public static SrmDocument ApplyPeak(SrmDocument doc, PeptideTreeNode nodePepTree, TransitionGroupDocNode nodeTranGroup, int resultsIndex, int? resultsFile, bool subsequent, ILongWaitBroker longWaitBroker) { nodeTranGroup = nodeTranGroup ?? PickTransitionGroup(doc, nodePepTree, resultsIndex); PeakMatchData referenceTarget; PeakMatchData[] referenceMatchData; DateTime? runTime; GetReferenceData(doc, nodePepTree.DocNode, nodeTranGroup, resultsIndex, resultsFile, out referenceTarget, out referenceMatchData, out runTime); var chromatograms = doc.Settings.MeasuredResults.Chromatograms; for (int i = 0; i < chromatograms.Count; i++) { var chromSet = chromatograms[i]; for (int j = 0; j < chromSet.MSDataFileInfos.Count; j++) { var fileInfo = chromSet.MSDataFileInfos[j]; if ((i == resultsIndex && (!resultsFile.HasValue || resultsFile.Value == j)) || (subsequent && runTime != null && fileInfo.RunStartTime < runTime)) { continue; } var bestMatch = GetPeakMatch(doc, chromSet, fileInfo, nodeTranGroup, referenceTarget, referenceMatchData); if (bestMatch != null) doc = bestMatch.ChangePeak(doc, nodePepTree, nodeTranGroup, chromSet.Name, fileInfo.FilePath); } longWaitBroker.SetProgressCheckCancel(i + 1, chromatograms.Count); } return doc; }
private void QueryPeptideProteins(ILongWaitBroker longWaitBroker) { List <HashSet <Protein> > peptideProteins = new List <HashSet <Protein> >(); if (BackgroundProteome != null) { using (var proteomeDb = BackgroundProteome.OpenProteomeDb()) { Digestion digestion = BackgroundProteome.GetDigestion(proteomeDb, SrmDocument.Settings.PeptideSettings); foreach (var peptideDocNode in _peptideDocNodes) { HashSet <Protein> proteins = new HashSet <Protein>(); if (digestion != null) { if (longWaitBroker.IsCanceled) { return; } foreach (Protein protein in digestion.GetProteinsWithSequence(peptideDocNode.Peptide.Sequence)) { if (protein.Sequence == PeptideGroupDocNode.PeptideGroup.Sequence) { _targetIsInBackgroundProteome = true; continue; } proteins.Add(protein); } } peptideProteins.Add(proteins); } } } _peptideProteins = peptideProteins; }
private IEnumerable <string> DownloadPackages(ILongWaitBroker waitBroker, IEnumerable <string> packagesToDownload) { ICollection <string> downloadPaths = new Collection <string>(); ICollection <string> failedDownloads = new Collection <string>(); using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(waitBroker, PackageUris.Count)) { foreach (var package in packagesToDownload) { Match file = Regex.Match(package, @"[^/]*$"); string downloadPath = Path.GetTempPath() + file; if (webClient.DownloadFileAsync(new Uri(package), downloadPath)) { downloadPaths.Add(downloadPath); } else { failedDownloads.Add(package); } } } if (failedDownloads.Count != 0) { throw new ToolExecutionException( TextUtil.LineSeparate( Resources.PythonInstaller_DownloadPackages_Failed_to_download_the_following_packages_, string.Empty, TextUtil.LineSeparate(failedDownloads), string.Empty, Resources.PythonInstaller_DownloadPython_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } return(downloadPaths); }
private void DownloadR(ILongWaitBroker longWaitBroker) { // the repository containing the downloadable R exes const string baseUri = "http://cran.r-project.org/bin/windows/base/"; // format the file name, e.g. R-2.15.2-win.exe string exe = @"R-" + _version + @"-win.exe"; // create the download path for the file DownloadPath = Path.GetTempPath() + exe; // create the webclient using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(longWaitBroker, 2)) { // First try downloading it as if it is the most recent release of R. The most // recent version is stored in a different location of the CRAN repo than older versions. // Otherwise, check and see if it is an older release var recentUri = new Uri(baseUri + exe); var olderUri = new Uri(baseUri + @"old/" + _version + @"/" + exe); if (!webClient.DownloadFileAsync(recentUri, DownloadPath) && !webClient.DownloadFileAsync(olderUri, DownloadPath)) { throw new ToolExecutionException( TextUtil.LineSeparate( Resources.RInstaller_DownloadR_Download_failed_, Resources .RInstaller_DownloadPackages_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } } }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { if (FailDownload) { throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Error_downloading_tool); } if (TestDownloadPath != null) { return(TestDownloadPath); } foreach (var item in ToolStoreItems ?? GetToolStoreItems()) { if (item.Identifier.Equals(packageIdentifier)) { string fileName = Path.GetFileName(item.FilePath); if (fileName == null) { throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Error_downloading_tool); } string path = Path.Combine(directory, fileName); File.Copy(item.FilePath, path, true); return(path); } } throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Cannot_find_a_file_with_that_identifier_); }
private void FindDataFiles(string directory, bool overwrite, ILongWaitBroker longWaitBroker) { // Don't search if every spectrum source file has an exact match and an alternate match if (directory == null || !Directory.Exists(directory) || (!overwrite && SpectrumSourceFiles.Values.All(s => s.HasMatches))) { return; } if (longWaitBroker != null) { longWaitBroker.Message = string.Format(Resources.ImportResultsControl_FindResultsFiles_Searching_for_matching_results_files_in__0__, directory); } try { foreach (string entry in Directory.EnumerateFileSystemEntries(directory)) { if (longWaitBroker != null && longWaitBroker.IsCanceled) { return; } if (entry != null && DataSourceUtil.IsDataSource(entry)) { TryMatch(entry, overwrite); } } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // No permissions on folder } }
/// <summary> /// Pastes tab delimited data into rows and columns starting from the current cell. /// If an error is encountered (e.g. type conversion), then a message is displayed, /// and the focus is left in the cell which had an error. /// Returns true if any changes were made to the document, false if there were no /// changes. /// </summary> private bool Paste(ILongWaitBroker longWaitBroker, TextReader reader) { bool anyChanges = false; var columnsByDisplayIndex = DataGridView.Columns.Cast <DataGridViewColumn>().Where(column => column.Visible).ToArray(); Array.Sort(columnsByDisplayIndex, (col1, col2) => col1.DisplayIndex.CompareTo(col2.DisplayIndex)); int iFirstCol; int iFirstRow; if (null == DataGridView.CurrentCell) { iFirstRow = 0; iFirstCol = 0; } else { iFirstCol = columnsByDisplayIndex.IndexOf(col => col.Index == DataGridView.CurrentCell.ColumnIndex); iFirstRow = DataGridView.CurrentCell.RowIndex; } for (int iRow = iFirstRow; iRow < DataGridView.Rows.Count; iRow++) { if (longWaitBroker.IsCanceled) { return(anyChanges); } longWaitBroker.Message = string.Format(Resources.DataGridViewPasteHandler_Paste_Pasting_row__0_, iRow + 1); string line = reader.ReadLine(); if (null == line) { return(anyChanges); } var row = DataGridView.Rows[iRow]; using (var values = SplitLine(line).GetEnumerator()) { for (int iCol = iFirstCol; iCol < columnsByDisplayIndex.Length; iCol++) { if (!values.MoveNext()) { break; } var column = columnsByDisplayIndex[iCol]; if (column.ReadOnly) { continue; } if (!TrySetValue(row.Cells[column.Index], values.Current)) { return(anyChanges); } anyChanges = true; } } } return(anyChanges); }
// Extract public void ExtractTutorial(ILongWaitBroker waitBroker) { using (ZipFile zip = ZipFile.Read(getTempPath())) { ExpectedSize = zip.Entries.Sum(entry => entry.UncompressedSize); zip.ExtractProgress += (s, e) => TutorialFile_ExtractProgress(s, e, waitBroker); var extractDir = getExtractPath(); var skyFileToOpen = Path.Combine(extractDir ?? string.Empty, SkyFileLocationInZip); foreach (var entry in zip.Entries.ToList()) { entry.FileName = entry.FileName.Substring(entry.FileName.IndexOf('/')); // Gets rid of everything up to and including first '/'. if (string.IsNullOrEmpty(entry.FileName)) { continue; } if (waitBroker.IsCanceled) { break; } try { entry.Extract(extractDir); ExtractedSize += entry.UncompressedSize; } catch (Exception) { if (!waitBroker.IsCanceled) { throw; } } } Program.MainWindow.BeginInvoke(new Action(() => { if (!string.IsNullOrEmpty(SkyFileLocationInZip) && !string.IsNullOrEmpty(ExtractPath)) { Program.MainWindow.OpenFile(skyFileToOpen); } else { Program.MainWindow.NewDocument(true); } if (string.IsNullOrEmpty(SkyFileLocationInZip)) { MessageDlg.Show(Program.MainWindow, string.Format(Resources.ActionTutorial_client_DownloadFileCompleted_File_saved_at___0_, extractDir)); } Process.Start(PdfFileLocation); // Opens Tutorial PDF in users default browser. })); } }
// Download public void DownloadTutorials(ILongWaitBroker waitBroker) { WaitBroker = waitBroker; WaitBroker.ProgressValue = Convert.ToInt32(Progress * 100); WebClient client = new WebClient { CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore), }; client.DownloadProgressChanged += client_DownloadProgressChanged; client.DownloadFile(new Uri(TutorialZipFileLocation), getTempPath()); }
private static void CopyOldTools(string outerToolsFolderPath, ILongWaitBroker broker) { //Copy tools to a different folder then Directory.Move if successful. string tempOuterToolsFolderPath = string.Concat(outerToolsFolderPath, @"_installing"); if (Directory.Exists(tempOuterToolsFolderPath)) { DirectoryEx.SafeDelete(tempOuterToolsFolderPath); // Not sure this is necessay, but just to be safe if (Directory.Exists(tempOuterToolsFolderPath)) { throw new Exception(Resources.Program_CopyOldTools_Error_copying_external_tools_from_previous_installation); } } // Must create the tools directory to avoid ending up here again next time Directory.CreateDirectory(tempOuterToolsFolderPath); ToolList toolList = Settings.Default.ToolList; int numTools = toolList.Count; const int endValue = 100; int progressValue = 0; // ReSharper disable once UselessBinaryOperation (in case we decide to start at progress>0 for display purposes) int increment = (endValue - progressValue) / (numTools + 1); foreach (var tool in toolList) { string toolDirPath = tool.ToolDirPath; if (!string.IsNullOrEmpty(toolDirPath) && Directory.Exists(toolDirPath)) { string foldername = Path.GetFileName(toolDirPath); string newDir = Path.Combine(outerToolsFolderPath, foldername); string tempNewDir = Path.Combine(tempOuterToolsFolderPath, foldername); if (!Directory.Exists(tempNewDir)) { DirectoryEx.DirectoryCopy(toolDirPath, tempNewDir, true); } tool.ToolDirPath = newDir; // Update the tool to point to its new directory. tool.ArgsCollectorDllPath = tool.ArgsCollectorDllPath.Replace(toolDirPath, newDir); } if (broker.IsCanceled) { // Don't leave around a corrupted directory DirectoryEx.SafeDelete(tempOuterToolsFolderPath); return; } progressValue += increment; broker.ProgressValue = progressValue; } Directory.Move(tempOuterToolsFolderPath, outerToolsFolderPath); Settings.Default.ToolList = ToolList.CopyTools(toolList); }
private void update_ProgressChanged(UpdateProgress e, ILongWaitBroker broker) { if (broker.IsCanceled) { AppDeployment.UpdateAsyncCancel(); } else { long updateBytes = Math.Max(_updateInfo.UpdateSizeBytes ?? 0, e.BytesTotal); broker.Message = GetProgressMessage(e.BytesCompleted, updateBytes); broker.ProgressValue = updateBytes == 0 ? 0 : (int)Math.Min(99, e.BytesCompleted * 100 / updateBytes); } }
private void QueryPeptideProteins(ILongWaitBroker longWaitBroker) { List <HashSet <Protein> > peptideProteins = new List <HashSet <Protein> >(); if (BackgroundProteome != null) { using (var proteomeDb = BackgroundProteome.OpenProteomeDb(longWaitBroker.CancellationToken)) { Digestion digestion = proteomeDb.GetDigestion(); if (digestion != null) { var peptidesOfInterest = _peptideDocNodes.Select(node => node.Item2.Peptide.Target.Sequence); var sequenceProteinsDict = digestion.GetProteinsWithSequences(peptidesOfInterest); if (longWaitBroker.IsCanceled) { return; } foreach (var tuple in _peptideDocNodes) { if (longWaitBroker.IsCanceled) { return; } var peptideGroup = (PeptideGroup)tuple.Item1.GetIdentity(0); var peptideDocNode = tuple.Item2; HashSet <Protein> proteins = new HashSet <Protein>(); var peptideGroupDocNode = PeptideGroupDocNodes.First(g => ReferenceEquals(g.PeptideGroup, peptideGroup)); List <Protein> proteinsForSequence; if (sequenceProteinsDict.TryGetValue(peptideDocNode.Peptide.Target.Sequence, out proteinsForSequence)) { if (peptideGroupDocNode != null) { foreach (var protein in proteinsForSequence) { if (protein.Sequence == peptideGroupDocNode.PeptideGroup.Sequence) { _peptidesInBackgroundProteome.Add(tuple.Item1); continue; } proteins.Add(protein); } } } peptideProteins.Add(proteins); } } } } _peptideProteins = peptideProteins; }
private static void FindInputFiles(string dir, ICollection <string> inputFiles, ILongWaitBroker broker, double start, double stop) { broker.Message = TextUtil.LineSeparate(Resources.BuildLibraryDlg_FindInputFiles_Finding_library_input_files_in, PathEx.ShortenPathForDisplay(dir)); string[] fileNames = Directory.GetFiles(dir); Array.Sort(fileNames); string[] dirs = Directory.GetDirectories(dir); Array.Sort(dirs); double startSub = start; double increment = (stop - start) / (dirs.Length + 1); const string extPep = BiblioSpecLiteBuilder.EXT_PEP_XML_ONE_DOT; const string extIdp = BiblioSpecLiteBuilder.EXT_IDP_XML; bool hasIdp = fileNames.Contains(f => PathEx.HasExtension(f, extIdp)); foreach (string fileName in fileNames) { if (IsValidInputFile(fileName)) { // If the directory has any .idpXML files, then do not add the // supporting .pepXML files. if (!hasIdp || !PathEx.HasExtension(fileName, extPep)) { inputFiles.Add(fileName); } } if (broker.IsCanceled) { return; } } startSub += increment; broker.ProgressValue = (int)startSub; foreach (string dirSub in dirs) { FindInputFiles(dirSub, inputFiles, broker, startSub, startSub + increment); if (broker.IsCanceled) { return; } startSub += increment; broker.ProgressValue = (int)startSub; } }
public IEnumerable <FindResult> FindAll(ILongWaitBroker longWaitBroker, SrmDocument document) { longWaitBroker.Message = Resources.FindPredicate_FindAll_Found_0_matches; var customMatches = new HashSet <Bookmark> [FindOptions.CustomFinders.Count]; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { var customFinder = FindOptions.CustomFinders[iFinder]; var bookmarkSet = new HashSet <Bookmark>(); longWaitBroker.Message = string.Format(Resources.FindPredicate_FindAll_Searching_for__0__, customFinder.DisplayName); foreach (var bookmark in customFinder.FindAll(document)) { if (longWaitBroker.IsCanceled) { yield break; } bookmarkSet.Add(bookmark); } customMatches[iFinder] = bookmarkSet; } var bookmarkEnumerator = new BookmarkEnumerator(document); int matchCount = 0; do { bookmarkEnumerator.MoveNext(); if (longWaitBroker.IsCanceled) { yield break; } FindMatch findMatch = null; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { if (customMatches[iFinder].Contains(bookmarkEnumerator.Current)) { findMatch = FindOptions.CustomFinders[iFinder].Match(bookmarkEnumerator); } } findMatch = findMatch ?? MatchInternal(bookmarkEnumerator); if (findMatch != null) { matchCount++; longWaitBroker.Message = matchCount == 1 ? Resources.FindPredicate_FindAll_Found_1_match : string.Format(Resources.FindPredicate_FindAll_Found__0__matches, matchCount); yield return(new FindResult(this, bookmarkEnumerator, findMatch)); } } while (!bookmarkEnumerator.AtStart); }
public IEnumerable<FindResult> FindAll(ILongWaitBroker longWaitBroker, SrmDocument document) { longWaitBroker.Message = Resources.FindPredicate_FindAll_Found_0_matches; var customMatches = new HashSet<Bookmark>[FindOptions.CustomFinders.Count]; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { var customFinder = FindOptions.CustomFinders[iFinder]; var bookmarkSet = new HashSet<Bookmark>(); longWaitBroker.Message = string.Format(Resources.FindPredicate_FindAll_Searching_for__0__, customFinder.DisplayName); foreach (var bookmark in customFinder.FindAll(document)) { if (longWaitBroker.IsCanceled) { yield break; } bookmarkSet.Add(bookmark); } customMatches[iFinder] = bookmarkSet; } var bookmarkEnumerator = new BookmarkEnumerator(document); int matchCount = 0; do { bookmarkEnumerator.MoveNext(); if (longWaitBroker.IsCanceled) { yield break; } FindMatch findMatch = null; for (int iFinder = 0; iFinder < FindOptions.CustomFinders.Count; iFinder++) { if (customMatches[iFinder].Contains(bookmarkEnumerator.Current)) { findMatch = FindOptions.CustomFinders[iFinder].Match(bookmarkEnumerator); } } findMatch = findMatch ?? MatchInternal(bookmarkEnumerator); if (findMatch != null) { matchCount++; longWaitBroker.Message = matchCount == 1 ? Resources.FindPredicate_FindAll_Found_1_match : string.Format(Resources.FindPredicate_FindAll_Found__0__matches, matchCount); yield return new FindResult(this, bookmarkEnumerator, findMatch); } } while (!bookmarkEnumerator.AtStart); }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { WebClient webClient = new WebClient(); UriBuilder uri = new UriBuilder(TOOL_STORE_URI) { Path = DOWNLOAD_TOOL_URL, Query = "lsid=" + packageIdentifier // Not L10N }; byte[] toolZip = webClient.DownloadData(uri.Uri.AbsoluteUri); // Not L10N string contentDisposition = webClient.ResponseHeaders.Get("Content-Disposition"); // Not L10N // contentDisposition is filename="ToolBasename.zip" Match match = Regex.Match(contentDisposition, "^filename=\"(.+)\"$", RegexOptions.IgnoreCase); // Not L10N string downloadedFile = directory + match.Groups[1].Value; File.WriteAllBytes(downloadedFile, toolZip); return(downloadedFile); }
private void QueryPeptideProteins(ILongWaitBroker longWaitBroker) { List <HashSet <Protein> > peptideProteins = new List <HashSet <Protein> >(); if (BackgroundProteome != null) { using (var proteomeDb = BackgroundProteome.OpenProteomeDb()) { Digestion digestion = BackgroundProteome.GetDigestion(proteomeDb, SrmDocument.Settings.PeptideSettings); if (digestion != null) { var peptidesOfInterest = _peptideDocNodes.Select(node => node.Peptide.Sequence); var sequenceProteinsDict = digestion.GetProteinsWithSequences(peptidesOfInterest, null); if (longWaitBroker.IsCanceled) { return; } foreach (var peptideDocNode in _peptideDocNodes) { HashSet <Protein> proteins = new HashSet <Protein>(); var peptideGroupDocNode = PeptideGroupDocNodes.First(g => g.Peptides.Contains(peptideDocNode)); List <Protein> proteinsForSequence; if (sequenceProteinsDict.TryGetValue(peptideDocNode.Peptide.Sequence, out proteinsForSequence)) { if (peptideGroupDocNode != null) { foreach (var protein in proteinsForSequence) { if (protein.Sequence == peptideGroupDocNode.PeptideGroup.Sequence) { _peptidesInBackgroundProteome.Add(peptideDocNode); continue; } proteins.Add(protein); } } } peptideProteins.Add(proteins); } } } } _peptideProteins = peptideProteins; }
/// <summary> /// The asynchronous download client links a webClient to a LongWaitBroker. It supports /// multiple asynchronous downloads, and updates the associated broker's progress value. /// </summary> /// <param name="waitBroker">The associated LongWaitBroker</param> /// <param name="files">The numbers of file this instance is expected to download. This /// is used to accurately update the broker's progress value</param> public MultiFileAsynchronousDownloadClient(ILongWaitBroker waitBroker, int files) { _longWaitBroker = waitBroker; _webClient = new WebClient(); FilesDownloaded = 0; _webClient.DownloadProgressChanged += (sender, args) => { _longWaitBroker.ProgressValue = (int)Math.Min(100, ((((double)FilesDownloaded) / files) * 100) + ((1.0 / files) * args.ProgressPercentage)); }; _webClient.DownloadFileCompleted += (sender, args) => { FilesDownloaded++; DownloadSucceeded = (args.Error == null); DownloadComplete = true; }; }
// Consider: the location of the following python links is assumed to be relatively stable, but could change. We // might want to package these scripts with Skyline itself to assure that they are available private void DownloadPip(ILongWaitBroker longWaitBroker) { // location of the setuptools install script const string setupToolsScript = "https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py"; SetupToolsPath = Path.GetTempPath() + @"ez_setup.py"; // location of the pip install script const string pipScript = "https://raw.github.com/pypa/pip/master/contrib/get-pip.py"; PipPath = Path.GetTempPath() + @"get-pip.py"; using (var webClient = TestPipDownloadClient ?? new MultiFileAsynchronousDownloadClient(longWaitBroker, 2)) { if (!webClient.DownloadFileAsync(new Uri(setupToolsScript), SetupToolsPath) || !webClient.DownloadFileAsync(new Uri(pipScript), PipPath)) { throw new ToolExecutionException(Resources.PythonInstaller_DownloadPip_Download_failed__Check_your_network_connection_or_contact_Skyline_developers_); } } }
private void DownloadPython(ILongWaitBroker waitBroker) { // the base Url for python releases const string baseUri = "http://python.org/ftp/python/"; // the installer file name, e.g. python-2.7.msi string fileName = @"python-" + _version + @".msi"; // the fully formed Uri, e.g. http://python.org/ftp/python/2.7/python-2.7.msi var downloadUri = new Uri(baseUri + _version + @"/" + fileName); using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(waitBroker, 1)) { if (!webClient.DownloadFileAsync(downloadUri, DownloadPath = Path.GetTempPath() + fileName)) { throw new ToolExecutionException(TextUtil.LineSeparate( Resources.PythonInstaller_DownloadPython_Download_failed_, Resources.PythonInstaller_DownloadPython_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } } }
private bool DoFillDown(ILongWaitBroker longWaitBroker, PropertyDescriptor[] propertyDescriptors, int firstRowIndex, int lastRowIndex) { bool anyChanges = false; var firstRowValues = propertyDescriptors.Select(pd => pd.GetValue(BindingListSource[firstRowIndex])).ToArray(); int totalRows = lastRowIndex - firstRowIndex + 1; for (int iRow = firstRowIndex + 1; iRow <= lastRowIndex; iRow++) { if (longWaitBroker.IsCanceled) { return(anyChanges); } longWaitBroker.ProgressValue = 100 * (iRow - firstRowIndex) / totalRows; longWaitBroker.Message = string.Format(Resources.DataboundGridControl_DoFillDown_Filling__0___1__rows, iRow - firstRowIndex, totalRows); var row = BindingListSource[iRow]; for (int icol = 0; icol < propertyDescriptors.Length; icol++) { var propertyDescriptor = propertyDescriptors[icol]; try { propertyDescriptor.SetValue(row, firstRowValues[icol]); anyChanges = true; } catch (Exception e) { MessageDlg.ShowWithException(this, TextUtil.LineSeparate(Resources.DataboundGridControl_DoFillDown_Error_setting_value_, e.Message), e); var column = DataGridView.Columns.OfType <DataGridViewColumn>() .FirstOrDefault(col => col.DataPropertyName == propertyDescriptor.Name); if (null != column) { DataGridView.CurrentCell = DataGridView.Rows[iRow].Cells[column.Index]; } return(anyChanges); } } } return(anyChanges); }
private bool ClearCells(ILongWaitBroker longWaitBroker) { if (DataGridView.SelectedRows.Count > 0) { return(false); } var columnIndexes = DataGridView.SelectedCells.Cast <DataGridViewCell>().Select(cell => cell.ColumnIndex).Distinct().ToArray(); if (columnIndexes.Any(columnIndex => DataGridView.Columns[columnIndex].ReadOnly)) { return(false); } bool anyChanges = false; var cellsByRow = DataGridView.SelectedCells.Cast <DataGridViewCell>().ToLookup(cell => cell.RowIndex).ToArray(); Array.Sort(cellsByRow, (g1, g2) => g1.Key.CompareTo(g2.Key)); for (int iGrouping = 0; iGrouping < cellsByRow.Length; iGrouping++) { if (longWaitBroker.IsCanceled) { return(anyChanges); } longWaitBroker.ProgressValue = 100 * iGrouping / cellsByRow.Length; longWaitBroker.Message = string.Format(Resources.DataGridViewPasteHandler_ClearCells_Cleared__0___1__rows, iGrouping, cellsByRow.Length); var rowGrouping = cellsByRow[iGrouping]; var cells = rowGrouping.ToArray(); Array.Sort(cells, (c1, c2) => c1.ColumnIndex.CompareTo(c2.ColumnIndex)); foreach (var cell in cells) { if (!TrySetValue(cell, string.Empty)) { return(anyChanges); } anyChanges = true; } } return(anyChanges); }
private void DownloadTools(ILongWaitBroker waitBroker, IEnumerable <ToolUpdateInfo> tools, out ICollection <ToolUpdateInfo> successfulDownloads, out ICollection <string> failedDownloads) { successfulDownloads = new Collection <ToolUpdateInfo>(); failedDownloads = new Collection <string>(); ToolDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "ToolDir")); // Not L10N foreach (var tool in tools) { var individualDir = Directory.CreateDirectory(Path.Combine(ToolDir.FullName, tool._packageName)); try { tool.FilePath = _updateHelper.GetToolZipFile(waitBroker, tool._packageIdentifer, individualDir.FullName); successfulDownloads.Add(tool); } catch (ToolExecutionException) { failedDownloads.Add(tool._packageName); } } }
/// <summary> /// Matches library peptides to the current document settings and adds them to the document. /// This needs to be one function so that we can use one LongWaitDlg. /// </summary> public void AddAllPeptidesToDocument(ILongWaitBroker broker, AuditLogEntryCreatorList entryCreators) { MatchAllPeptides(broker); if (broker.IsCanceled) { return; } if (MatchedPeptideCount == 0) { return; } if (broker.ShowDialog(wnd => EnsureDuplicateProteinFilter(wnd, entryCreators)) == DialogResult.Cancel) { return; } IdentityPath selectedPath; IdentityPath toPath = AddAllPeptidesSelectedPath; DocAllPeptides = AddPeptides(_document, broker, toPath, out selectedPath); AddAllPeptidesSelectedPath = selectedPath; }
public void UpdateSpectrumSourceFilesFromDirs(IEnumerable <string> dirPaths, bool overwrite, ILongWaitBroker longWaitBroker) { if (!overwrite && SpectrumSourceFiles.Values.All(s => s.HasMatches)) { return; } Array.ForEach(dirPaths.Distinct().ToArray(), dir => FindDataFiles(dir, overwrite, longWaitBroker)); }
private void DownloadPython(ILongWaitBroker waitBroker) { // the base Url for python releases const string baseUri = "http://python.org/ftp/python/"; // Not L10N // the installer file name, e.g. python-2.7.msi string fileName = "python-" + _version + ".msi"; // Not L10N // the fully formed Uri, e.g. http://python.org/ftp/python/2.7/python-2.7.msi var downloadUri = new Uri(baseUri + _version + "/" + fileName); // Not L10N using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(waitBroker, 1)) { if (!webClient.DownloadFileAsync(downloadUri, DownloadPath = Path.GetTempPath() + fileName)) throw new ToolExecutionException(TextUtil.LineSeparate( Resources.PythonInstaller_DownloadPython_Download_failed_, Resources.PythonInstaller_DownloadPython_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } }
private static void FindInputFiles(string dir, ICollection<string> inputFiles, ILongWaitBroker broker) { broker.ProgressValue = 0; FindInputFiles(dir, inputFiles, broker, 0, 100); }
private static void FindInputFiles(string dir, ICollection<string> inputFiles, ILongWaitBroker broker, double start, double stop) { broker.Message = TextUtil.LineSeparate(Resources.BuildLibraryDlg_FindInputFiles_Finding_library_input_files_in, PathEx.ShortenPathForDisplay(dir)); string[] fileNames = Directory.GetFiles(dir); Array.Sort(fileNames); string[] dirs = Directory.GetDirectories(dir); Array.Sort(dirs); double startSub = start; double increment = (stop - start) / (dirs.Length + 1); const string extPep = BiblioSpecLiteBuilder.EXT_PEP_XML_ONE_DOT; const string extIdp = BiblioSpecLiteBuilder.EXT_IDP_XML; bool hasIdp = fileNames.Contains(f => PathEx.HasExtension(f, extIdp)); foreach (string fileName in fileNames) { if (IsValidInputFile(fileName)) { // If the directory has any .idpXML files, then do not add the // supporting .pepXML files. if (!hasIdp || !PathEx.HasExtension(fileName, extPep)) inputFiles.Add(fileName); } if (broker.IsCanceled) return; } startSub += increment; broker.ProgressValue = (int) startSub; foreach (string dirSub in dirs) { FindInputFiles(dirSub, inputFiles, broker, startSub, startSub + increment); if (broker.IsCanceled) return; startSub += increment; broker.ProgressValue = (int)startSub; } }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { WebClient webClient = new WebClient(); UriBuilder uri = new UriBuilder(TOOL_STORE_URI) { Path = DOWNLOAD_TOOL_URL, Query = "lsid=" + packageIdentifier // Not L10N }; byte[] toolZip = webClient.DownloadData(uri.Uri.AbsoluteUri); // Not L10N string contentDisposition = webClient.ResponseHeaders.Get("Content-Disposition"); // Not L10N // contentDisposition is filename="ToolBasename.zip" Match match = Regex.Match(contentDisposition, "^filename=\"(.+)\"$", RegexOptions.IgnoreCase); // Not L10N string downloadedFile = directory + match.Groups[1].Value; File.WriteAllBytes(downloadedFile, toolZip); return downloadedFile; }
private SrmDocument ImportFiles(SrmDocument docOrig, ILongWaitBroker longWaitBroker, IList<string> filePaths, MeasuredResults.MergeAction resultsAction, bool mergePeptides, IdentityPath to, out IdentityPath firstAdded) { firstAdded = null; var docResult = docOrig; int filesRead = 0; // Add files in reverse order, so their nodes will end up in the right order. IdentityPath first = null; foreach (var filePath in filePaths) { if (longWaitBroker != null) { if (longWaitBroker.IsCanceled || longWaitBroker.IsDocumentChanged(docOrig)) return docOrig; longWaitBroker.ProgressValue = filesRead*100/filePaths.Count; longWaitBroker.Message = string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(filePath)); } using (var reader = new StreamReader(filePath)) { IdentityPath firstAddedForFile, nextAdd; docResult = docResult.ImportDocumentXml(reader, filePath, resultsAction, mergePeptides, FindSpectralLibrary, Settings.Default.StaticModList, Settings.Default.HeavyModList, to, out firstAddedForFile, out nextAdd, false); // Add the next document at the specified location to = nextAdd; // Store the first added node only for the first document if (first == null) first = firstAddedForFile; } filesRead++; } firstAdded = first; return docResult; }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { return _client.GetToolZipFile(waitBroker, packageIdentifier, directory); }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { var client = ToolStoreUtil.CreateClient(); return(client.GetToolZipFile(waitBroker, packageIdentifier, directory)); }
public void PerformWork(ILongWaitBroker broker) { _performWork(); }
private void TutorialFile_ExtractProgress(object sender, ExtractProgressEventArgs e, ILongWaitBroker waitBroker) { if (waitBroker != null) { if (waitBroker.IsCanceled) { e.Cancel = true; return; } int progressValue = (int)Math.Round((ExtractedSize + e.BytesTransferred) * 100.0 / ExpectedSize); if (progressValue != WaitBroker.ProgressValue) { waitBroker.ProgressValue = progressValue; waitBroker.Message = (string.Format(Resources.SrmDocumentSharing_SrmDocumentSharing_ExtractProgress_Extracting__0__, e.CurrentEntry.FileName)); } } }
// Extract public void ExtractTutorial(ILongWaitBroker waitBroker) { using (ZipFile zip = ZipFile.Read(getTempPath())) { ExpectedSize = zip.Entries.Sum(entry => entry.UncompressedSize); zip.ExtractProgress += (s,e) => TutorialFile_ExtractProgress(s,e, waitBroker); var extractDir = getExtractPath(); var skyFileToOpen = Path.Combine(extractDir ?? string.Empty, SkyFileLocationInZip); foreach (var entry in zip.Entries.ToList()) { entry.FileName = entry.FileName.Substring(entry.FileName.IndexOf('/')); // Gets rid of everything up to and including first '/'. if (string.IsNullOrEmpty(entry.FileName)) { continue; } if (waitBroker.IsCanceled) break; try { entry.Extract(extractDir); ExtractedSize += entry.UncompressedSize; } catch (Exception) { if (!waitBroker.IsCanceled) throw; } } Program.MainWindow.BeginInvoke(new Action(() => { if (!string.IsNullOrEmpty(SkyFileLocationInZip) && !string.IsNullOrEmpty(ExtractPath)) { Program.MainWindow.OpenFile(skyFileToOpen); } else { Program.MainWindow.NewDocument(true); } if (string.IsNullOrEmpty(SkyFileLocationInZip)) { MessageDlg.Show(Program.MainWindow, string.Format(Resources.ActionTutorial_client_DownloadFileCompleted_File_saved_at___0_, extractDir)); } Process.Start(PdfFileLocation); // Opens Tutorial PDF in users default browser. })); } }
public static SrmDocument ApplyPeak(SrmDocument doc, PeptideTreeNode nodePepTree, ref TransitionGroupDocNode nodeTranGroup, int resultsIndex, ChromFileInfoId resultsFile, bool subsequent, ReplicateValue groupBy, object groupByValue, ILongWaitBroker longWaitBroker) { nodeTranGroup = nodeTranGroup ?? PickTransitionGroup(doc, nodePepTree, resultsIndex); GetReferenceData(doc, nodePepTree.DocNode, nodeTranGroup, resultsIndex, resultsFile, out var referenceTarget, out var referenceMatchData, out var runTime); var annotationCalculator = new AnnotationCalculator(doc); var chromatograms = doc.Settings.MeasuredResults.Chromatograms; for (var i = 0; i < chromatograms.Count; i++) { var chromSet = chromatograms[i]; if (groupBy != null) { if (!Equals(groupByValue, groupBy.GetValue(annotationCalculator, chromSet))) { continue; } } for (var j = 0; j < chromSet.MSDataFileInfos.Count; j++) { var fileInfo = chromSet.MSDataFileInfos[j]; if ((i == resultsIndex && (resultsFile == null || ReferenceEquals(resultsFile, fileInfo.FileId))) || (subsequent && runTime != null && fileInfo.RunStartTime < runTime)) { continue; } var bestMatch = GetPeakMatch(doc, chromSet, fileInfo, nodeTranGroup, referenceTarget, referenceMatchData); if (bestMatch != null) { doc = bestMatch.ChangePeak(doc, nodePepTree, nodeTranGroup, chromSet.Name, fileInfo.FilePath); } } longWaitBroker.SetProgressCheckCancel(i + 1, chromatograms.Count); } return(doc); }
/// <summary> /// Adds all peptides which can be matched to a background proteome to the /// proteins in the background proteins, and returns a new document with those /// proteins and peptides added. /// </summary> /// <param name="document">The starting document</param> /// <param name="dictCopy">A dictionary of peptides to peptide matches. All added /// peptides are removed</param> /// <param name="broker">For reporting long wait status</param> /// <param name="toPath">Path to the location in the document to add new items</param> /// <param name="selectedPath">Path to item in the document that should be selected /// after this operation is complete</param> /// <returns>A new document with matching peptides and their proteins addded</returns> private SrmDocument AddProteomePeptides(SrmDocument document, Dictionary<PeptideSequenceModKey, PeptideMatch> dictCopy, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath) { // Build a list of new PeptideGroupDocNodes to add to the document. var dictPeptideGroupsNew = new Dictionary<string, PeptideGroupDocNode>(); // Get starting progress values int startPercent = (broker != null ? broker.ProgressValue : 0); int processedPercent = 0; int processedCount = 0; int totalMatches = dictCopy.Count; // Just to make sure this is set selectedPath = toPath; foreach (PeptideMatch pepMatch in dictCopy.Values) { // Show progress, if in a long wait if (broker != null) { if (broker.IsCanceled) { selectedPath = toPath; return document; } // All peptides with protein get processed in this loop. Peptides // without proteins get added later. if (pepMatch.Proteins != null) processedCount++; int processPercentNow = processedCount * (100 - startPercent) / totalMatches; if (processedPercent != processPercentNow) { processedPercent = processPercentNow; broker.ProgressValue = startPercent + processedPercent; } } // Peptide should be added to the document, // unless the NoDuplicates radio was selected and the peptide has more than 1 protein associated with it. if (pepMatch.Proteins == null || (FilterMultipleProteinMatches == BackgroundProteome.DuplicateProteinsFilter.NoDuplicates && pepMatch.Proteins.Count > 1)) continue; foreach (ProteinInfo protein in pepMatch.Proteins) { // Look for the protein in the document. string name = protein.ProteinMetadata.Name; var peptideGroupDocNode = FindPeptideGroupDocNode(document, name); bool foundInDoc = peptideGroupDocNode != null; bool foundInList = false; if (!foundInDoc) { // If the protein is not already in the document, // check to see if we have already created a PeptideGroupDocNode for it. if (dictPeptideGroupsNew.TryGetValue(name, out peptideGroupDocNode)) foundInList = true; // If not, create a new PeptideGroupDocNode. else { List<ProteinMetadata> alternativeProteins = new List<ProteinMetadata>(protein.Alternatives); peptideGroupDocNode = new PeptideGroupDocNode( new FastaSequence(name, protein.ProteinMetadata.Description, alternativeProteins, protein.Sequence), null, null, new PeptideDocNode[0]); } } // Create a new peptide that matches this protein. var fastaSequence = peptideGroupDocNode.PeptideGroup as FastaSequence; var peptideSequence = pepMatch.NodePep.Peptide.Sequence; // ReSharper disable PossibleNullReferenceException var begin = fastaSequence.Sequence.IndexOf(peptideSequence, StringComparison.Ordinal); // ReSharper restore PossibleNullReferenceException // Create a new PeptideDocNode using this peptide. var newPeptide = new Peptide(fastaSequence, peptideSequence, begin, begin + peptideSequence.Length, Settings.PeptideSettings.Enzyme.CountCleavagePoints(peptideSequence)); // Make sure we keep the same children. PeptideMatch match = pepMatch; var newNodePep = ((PeptideDocNode) new PeptideDocNode(newPeptide, pepMatch.NodePep.ExplicitMods, pepMatch.NodePep.ExplicitRetentionTime) .ChangeChildren(pepMatch.NodePep.Children.ToList().ConvertAll(nodeGroup => { // Create copies of the children in order to prevent transition groups with the same // global indices. var nodeTranGroup = (TransitionGroupDocNode) nodeGroup; if(match.Proteins != null && match.Proteins.Count() > 1) { nodeTranGroup = (TransitionGroupDocNode) nodeTranGroup.CopyId(); nodeTranGroup = (TransitionGroupDocNode) nodeTranGroup.ChangeChildren( nodeTranGroup.Children.ToList().ConvertAll(nodeTran => nodeTran.CopyId())); } return (DocNode) nodeTranGroup; })).ChangeAutoManageChildren(false)).ChangeSettings(document.Settings, SrmSettingsDiff.ALL); // If this PeptideDocNode is already a child of the PeptideGroupDocNode, // ignore it. if (peptideGroupDocNode.Children.Contains(nodePep => Equals(((PeptideDocNode) nodePep).Key, newNodePep.Key))) { Console.WriteLine(Resources.ViewLibraryPepMatching_AddProteomePeptides_Skipping__0__already_present, newNodePep.Peptide.Sequence); continue; } // Otherwise, add it to the list of children for the PeptideGroupNode. var newChildren = peptideGroupDocNode.Children.Cast<PeptideDocNode>().ToList(); newChildren.Add(newNodePep); newChildren.Sort(FastaSequence.ComparePeptides); // Store modified proteins by global index in a HashSet for second pass. var newPeptideGroupDocNode = peptideGroupDocNode.ChangeChildren(newChildren.Cast<DocNode>().ToArray()) .ChangeAutoManageChildren(false); // If the protein was already in the document, replace with the new PeptideGroupDocNode. if (foundInDoc) document = (SrmDocument)document.ReplaceChild(newPeptideGroupDocNode); // Otherwise, update the list of new PeptideGroupDocNodes to add. else { if (foundInList) dictPeptideGroupsNew.Remove(peptideGroupDocNode.Name); dictPeptideGroupsNew.Add(peptideGroupDocNode.Name, (PeptideGroupDocNode) newPeptideGroupDocNode); } // If we are only adding a single node, select it. if (PeptideMatches.Count == 1) selectedPath = new IdentityPath(new[] {peptideGroupDocNode.Id, newNodePep.Peptide}); // If the user only wants to add the first protein found, // we break the foreach loop after peptide has been added to its first protein.) if (FilterMultipleProteinMatches == BackgroundProteome.DuplicateProteinsFilter.FirstOccurence) break; } } if (dictPeptideGroupsNew.Count == 0) { return document; } // Sort the peptides. var nodePepGroupsSortedChildren = new List<PeptideGroupDocNode>(); foreach(PeptideGroupDocNode nodePepGroup in dictPeptideGroupsNew.Values) { var newChildren = nodePepGroup.Children.ToList(); // Have to cast all children to PeptideDocNodes in order to sort. var newChildrenNodePeps = newChildren.Cast<PeptideDocNode>().ToList(); newChildrenNodePeps.Sort(FastaSequence.ComparePeptides); nodePepGroupsSortedChildren.Add((PeptideGroupDocNode) nodePepGroup.ChangeChildren(newChildrenNodePeps.Cast<DocNode>().ToArray())); } // Sort the proteins. nodePepGroupsSortedChildren.Sort((node1, node2) => Comparer<string>.Default.Compare(node1.Name, node2.Name)); IdentityPath selPathTemp = selectedPath, nextAdd; document = document.AddPeptideGroups(nodePepGroupsSortedChildren, false, toPath, out selectedPath, out nextAdd); selectedPath = PeptideMatches.Count == 1 ? selPathTemp : selectedPath; return document; }
public BackgroundWorker(MinimizeResultsDlg dlg, ILongWaitBroker longWaitBroker) { _dlg = dlg; _longWaitBroker = longWaitBroker; }
private void DownloadTools(ILongWaitBroker waitBroker, IEnumerable<ToolUpdateInfo> tools, out ICollection<ToolUpdateInfo> successfulDownloads, out ICollection<string> failedDownloads) { successfulDownloads = new Collection<ToolUpdateInfo>(); failedDownloads = new Collection<string>(); ToolDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "ToolDir")); // Not L10N foreach (var tool in tools) { var individualDir = Directory.CreateDirectory(Path.Combine(ToolDir.FullName, tool._packageName)); try { tool.FilePath = _updateHelper.GetToolZipFile(waitBroker, tool._packageIdentifer, individualDir.FullName); successfulDownloads.Add(tool); } catch (ToolExecutionException) { failedDownloads.Add(tool._packageName); } } }
public static SrmDocument ApplyPeak(SrmDocument doc, PeptideTreeNode nodePepTree, ref TransitionGroupDocNode nodeTranGroup, int resultsIndex, int?resultsFile, bool subsequent, ILongWaitBroker longWaitBroker) { nodeTranGroup = nodeTranGroup ?? PickTransitionGroup(doc, nodePepTree, resultsIndex); PeakMatchData referenceTarget; PeakMatchData[] referenceMatchData; DateTime? runTime; GetReferenceData(doc, nodePepTree.DocNode, nodeTranGroup, resultsIndex, resultsFile, out referenceTarget, out referenceMatchData, out runTime); var chromatograms = doc.Settings.MeasuredResults.Chromatograms; for (int i = 0; i < chromatograms.Count; i++) { var chromSet = chromatograms[i]; for (int j = 0; j < chromSet.MSDataFileInfos.Count; j++) { var fileInfo = chromSet.MSDataFileInfos[j]; if ((i == resultsIndex && (!resultsFile.HasValue || resultsFile.Value == j)) || (subsequent && runTime != null && fileInfo.RunStartTime < runTime)) { continue; } var bestMatch = GetPeakMatch(doc, chromSet, fileInfo, nodeTranGroup, referenceTarget, referenceMatchData); if (bestMatch != null) { doc = bestMatch.ChangePeak(doc, nodePepTree, nodeTranGroup, chromSet.Name, fileInfo.FilePath); } } longWaitBroker.SetProgressCheckCancel(i + 1, chromatograms.Count); } return(doc); }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { var client = ToolStoreUtil.CreateClient(); return client.GetToolZipFile(waitBroker, packageIdentifier, directory); }
public string GetToolZipFile(ILongWaitBroker waitBroker, string packageIdentifier, string directory) { if (FailDownload) throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Error_downloading_tool); if (TestDownloadPath != null) return TestDownloadPath; foreach (var item in ToolStoreItems ?? GetToolStoreItems()) { if (item.Identifier.Equals(packageIdentifier)) { string fileName = Path.GetFileName(item.FilePath); if (fileName == null) throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Error_downloading_tool); string path = Path.Combine(directory, fileName); File.Copy(item.FilePath, path, true); return path; } } throw new ToolExecutionException(Resources.TestToolStoreClient_GetToolZipFile_Cannot_find_a_file_with_that_identifier_); }
private static SrmDocument AddPeptidesToLibraryGroup(SrmDocument document, ICollection<PeptideMatch> listMatches, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath) { // Get starting progress values int startPercent = (broker != null ? broker.ProgressValue : 0); int processedPercent = 0; int processedCount = 0; int totalMatches = listMatches.Count; var listPeptides = new List<PeptideDocNode>(); foreach (var match in listMatches) { // Show progress, if in a long wait if (broker != null) { if (broker.IsCanceled) { selectedPath = null; return document; } processedCount++; int processPercentNow = processedCount * (100 - startPercent) / totalMatches; if (processedPercent != processPercentNow) { processedPercent = processPercentNow; broker.ProgressValue = startPercent + processedPercent; } } listPeptides.Add(match.NodePep.ChangeSettings(document.Settings, SrmSettingsDiff.ALL)); } bool hasVariable = listPeptides.Contains(nodePep => nodePep.HasExplicitMods && nodePep.ExplicitMods.IsVariableStaticMods); // Use existing group by this name, if present. var nodePepGroupNew = FindPeptideGroupDocNode(document, Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides); if(nodePepGroupNew != null) { var newChildren = nodePepGroupNew.Children.ToList(); newChildren.AddRange(listPeptides.ConvertAll(nodePep => (DocNode) nodePep)); selectedPath = (listPeptides.Count == 1 ? new IdentityPath(nodePepGroupNew.Id, listPeptides[0].Id) : toPath); nodePepGroupNew = (PeptideGroupDocNode) nodePepGroupNew.ChangeChildren(newChildren); if (hasVariable) nodePepGroupNew = (PeptideGroupDocNode) nodePepGroupNew.ChangeAutoManageChildren(false); return (SrmDocument) document.ReplaceChild(nodePepGroupNew); } else { nodePepGroupNew = new PeptideGroupDocNode(new PeptideGroup(), Resources.ViewLibraryPepMatching_AddPeptidesToLibraryGroup_Library_Peptides, string.Empty, listPeptides.ToArray()); if (hasVariable) nodePepGroupNew = (PeptideGroupDocNode) nodePepGroupNew.ChangeAutoManageChildren(false); IdentityPath nextAdd; document = document.AddPeptideGroups(new[] { nodePepGroupNew }, true, toPath, out selectedPath, out nextAdd); selectedPath = new IdentityPath(selectedPath, nodePepGroupNew.Children[0].Id); return document; } }
private static void FindInputFiles(string dir, ICollection <string> inputFiles, ILongWaitBroker broker) { broker.ProgressValue = 0; FindInputFiles(dir, inputFiles, broker, 0, 100); }
/// <summary> /// Tries to match each library peptide to document settings. /// </summary> public void MatchAllPeptides(ILongWaitBroker broker) { _chargeSettingsMap = new SrmSettings[128]; // Build a dictionary mapping sequence to proteins because getting this information is slow. var dictSequenceProteins = new Dictionary<string, IList<ProteinInfo>>(); var dictNewNodePeps = new Dictionary<PeptideSequenceModKey, PeptideMatch>(); PeptideMatches = null; MatchedPeptideCount = 0; int peptides = 0; int totalPeptides = _libraryPepInfos.Length; foreach (ViewLibraryPepInfo pepInfo in _libraryPepInfos) { if (broker.IsCanceled) return; int charge = pepInfo.Key.Charge; // Find the matching peptide. var nodePepMatched = AssociateMatchingPeptide(pepInfo, charge).PeptideNode; if (nodePepMatched != null) { MatchedPeptideCount++; PeptideMatch peptideMatchInDict; // If peptide is already in the dictionary of peptides to add, merge the children. if (!dictNewNodePeps.TryGetValue(nodePepMatched.SequenceKey, out peptideMatchInDict)) { IList<ProteinInfo> matchedProteins = null; var sequence = nodePepMatched.Peptide.Sequence; // This is only set if the user has checked the associate peptide box. if (_backgroundProteome != null) { // We want to query the background proteome as little as possible, // so sequences are mapped to protein lists in a dictionary. if (!dictSequenceProteins.TryGetValue(sequence, out matchedProteins)) { using (var proteomeDb = _backgroundProteome.OpenProteomeDb()) { var digestion = _backgroundProteome.GetDigestion(proteomeDb, Settings.PeptideSettings); if (digestion != null) { matchedProteins = digestion.GetProteinsWithSequence(sequence).Select(protein=>new ProteinInfo(protein)).ToList(); dictSequenceProteins.Add(sequence, matchedProteins); } } } } dictNewNodePeps.Add(nodePepMatched.SequenceKey, new PeptideMatch(nodePepMatched, matchedProteins, MatchesFilter(sequence, charge))); } else { PeptideDocNode nodePepInDictionary = peptideMatchInDict.NodePep; if (!nodePepInDictionary.HasChildCharge(charge)) { List<DocNode> newChildren = nodePepInDictionary.Children.ToList(); newChildren.AddRange(nodePepMatched.Children); newChildren.Sort(Peptide.CompareGroups); var key = nodePepMatched.SequenceKey; dictNewNodePeps.Remove(key); dictNewNodePeps.Add(key, new PeptideMatch((PeptideDocNode)nodePepInDictionary.ChangeChildren(newChildren), peptideMatchInDict.Proteins, peptideMatchInDict.MatchesFilterSettings)); } } } peptides++; int progressValue = (int)((peptides + 0.0) / totalPeptides * PERCENT_PEPTIDE_MATCH); broker.ProgressValue = progressValue; } PeptideMatches = dictNewNodePeps; }
private void DownloadR(ILongWaitBroker longWaitBroker) { // the repository containing the downloadable R exes const string baseUri = "http://cran.r-project.org/bin/windows/base/"; // Not L10N // format the file name, e.g. R-2.15.2-win.exe string exe = "R-" + _version + "-win.exe"; // Not L10N // create the download path for the file DownloadPath = Path.GetTempPath() + exe; // create the webclient using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(longWaitBroker, 2)) { // First try downloading it as if it is the most recent release of R. The most // recent version is stored in a different location of the CRAN repo than older versions. // Otherwise, check and see if it is an older release var recentUri = new Uri(baseUri + exe); var olderUri = new Uri(baseUri + "old/" + _version + "/" + exe); // Not L10N if (!webClient.DownloadFileAsync(recentUri, DownloadPath) && !webClient.DownloadFileAsync(olderUri, DownloadPath)) throw new ToolExecutionException( TextUtil.LineSeparate( Resources.RInstaller_DownloadR_Download_failed_, Resources .RInstaller_DownloadPackages_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } }
public void PerformWork(ILongWaitBroker broker) { _broker = broker; _performWork(this); }
/// <summary> /// Adds a list of PeptideDocNodes found in the library to the current document. /// </summary> public SrmDocument AddPeptides(SrmDocument document, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath) { if (toPath != null && toPath.Depth == (int)SrmDocument.Level.MoleculeGroups && ReferenceEquals(toPath.GetIdentity((int)SrmDocument.Level.MoleculeGroups), SequenceTree.NODE_INSERT_ID)) { toPath = null; } SkippedPeptideCount = 0; var dictCopy = new Dictionary<PeptideSequenceModKey, PeptideMatch>(); // Make heavy mods explicit if (PeptideMatches.Values.Contains(match => match.NodePep.HasExplicitMods && match.NodePep.ExplicitMods.HeavyModifications != null)) { _matcher.ConvertAllHeavyModsExplicit(); } // Call ensure mods on all peptides to be added to the document. var listDefStatMods = new MappedList<string, StaticMod>(); listDefStatMods.AddRange(Properties.Settings.Default.StaticModList); listDefStatMods.AddRange(document.Settings.PeptideSettings.Modifications.StaticModifications); var listDefHeavyMods = new MappedList<string, StaticMod>(); listDefHeavyMods.AddRange(Properties.Settings.Default.HeavyModList); listDefHeavyMods.AddRange(document.Settings.PeptideSettings.Modifications.HeavyModifications); foreach (var key in PeptideMatches.Keys) { var match = PeptideMatches[key]; var nodePepDocSet = match.NodePep; if (_matcher.MatcherPepMods != null) nodePepDocSet = match.NodePep.EnsureMods(_matcher.MatcherPepMods, document.Settings.PeptideSettings.Modifications, listDefStatMods, listDefHeavyMods); if (!dictCopy.ContainsKey(nodePepDocSet.SequenceKey)) dictCopy.Add(nodePepDocSet.SequenceKey, new PeptideMatch(nodePepDocSet, match.Proteins, match.MatchesFilterSettings)); } if (!Properties.Settings.Default.LibraryPeptidesKeepFiltered) { // TODO: This removes entire peptides where only a single // precursor does not match. e.g. the library contains // a singly charged precursor match, but also doubly charged dictCopy = dictCopy.Where(match => match.Value.MatchesFilterSettings) .ToDictionary(match => match.Key, match => match.Value); } SrmDocument newDocument = UpdateExistingPeptides(document, dictCopy, toPath, out selectedPath); toPath = selectedPath; // If there is an associated background proteome, add peptides that can be // matched to the proteins from the background proteom. if (_backgroundProteome != null) { newDocument = AddProteomePeptides(newDocument, dictCopy, broker, toPath, out selectedPath); } toPath = selectedPath; // Add all remaining peptides as a peptide list. if (_backgroundProteome == null || Properties.Settings.Default.LibraryPeptidesAddUnmatched) { var listPeptidesToAdd = dictCopy.Values.ToList(); listPeptidesToAdd.RemoveAll(match => match.Proteins != null && match.Proteins.Count > 0); if (listPeptidesToAdd.Count > 0) { newDocument = AddPeptidesToLibraryGroup(newDocument, listPeptidesToAdd, broker, toPath, out selectedPath); } } return newDocument; }
// Consider: the location of the following python links is assumed to be relatively stable, but could change. We // might want to package these scripts with Skyline itself to assure that they are available private void DownloadPip(ILongWaitBroker longWaitBroker) { // location of the setuptools install script const string setupToolsScript = "https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py"; // Not L10N SetupToolsPath = Path.GetTempPath() + "ez_setup.py"; // Not L10N // location of the pip install script const string pipScript = "https://raw.github.com/pypa/pip/master/contrib/get-pip.py"; // Not L10N PipPath = Path.GetTempPath() + "get-pip.py"; // Not L10N using (var webClient = TestPipDownloadClient ?? new MultiFileAsynchronousDownloadClient(longWaitBroker, 2)) { if (!webClient.DownloadFileAsync(new Uri(setupToolsScript), SetupToolsPath) || !webClient.DownloadFileAsync(new Uri(pipScript), PipPath)) { throw new ToolExecutionException(Resources.PythonInstaller_DownloadPip_Download_failed__Check_your_network_connection_or_contact_Skyline_developers_); } } }
/// <summary> /// Matches library peptides to the current document settings and adds them to the document. /// This needs to be one function so that we can use one LongWaitDlg. /// </summary> public void AddAllPeptidesToDocument(ILongWaitBroker broker) { MatchAllPeptides(broker); if (broker.IsCanceled) return; if (MatchedPeptideCount == 0) return; if (broker.ShowDialog(EnsureDuplicateProteinFilter) == DialogResult.Cancel) return; IdentityPath selectedPath; IdentityPath toPath = AddAllPeptidesSelectedPath; DocAllPeptides = AddPeptides(_document, broker, toPath, out selectedPath); AddAllPeptidesSelectedPath = selectedPath; }
private IEnumerable<string> DownloadPackages(ILongWaitBroker waitBroker, IEnumerable<string> packagesToDownload) { ICollection<string> downloadPaths = new Collection<string>(); ICollection<string> failedDownloads = new Collection<string>(); using (var webClient = TestDownloadClient ?? new MultiFileAsynchronousDownloadClient(waitBroker, PackageUris.Count)) { foreach (var package in packagesToDownload) { Match file = Regex.Match(package, @"[^/]*$"); // Not L10N string downloadPath = Path.GetTempPath() + file; if (webClient.DownloadFileAsync(new Uri(package), downloadPath)) { downloadPaths.Add(downloadPath); } else { failedDownloads.Add(package); } } } if (failedDownloads.Count != 0) { throw new ToolExecutionException( TextUtil.LineSeparate( Resources.PythonInstaller_DownloadPackages_Failed_to_download_the_following_packages_, string.Empty, TextUtil.LineSeparate(failedDownloads), string.Empty, Resources.PythonInstaller_DownloadPython_Check_your_network_connection_or_contact_the_tool_provider_for_installation_support_)); } return downloadPaths; }
private void QueryPeptideProteins(ILongWaitBroker longWaitBroker) { List<HashSet<Protein>> peptideProteins = new List<HashSet<Protein>>(); if (BackgroundProteome != null) { using (var proteomeDb = BackgroundProteome.OpenProteomeDb()) { Digestion digestion = BackgroundProteome.GetDigestion(proteomeDb, SrmDocument.Settings.PeptideSettings); foreach (var peptideDocNode in _peptideDocNodes) { HashSet<Protein> proteins = new HashSet<Protein>(); if (digestion != null) { if (longWaitBroker.IsCanceled) { return; } foreach (Protein protein in digestion.GetProteinsWithSequence(peptideDocNode.Peptide.Sequence)) { if (protein.Sequence == PeptideGroupDocNode.PeptideGroup.Sequence) { _targetIsInBackgroundProteome = true; continue; } proteins.Add(protein); } } peptideProteins.Add(proteins); } } } _peptideProteins = peptideProteins; }
private void BeginUpdate(ILongWaitBroker broker) { AppDeployment.UpdateAsync(ev => update_ProgressChanged(ev, broker), update_Complete); }
private void OptimizeCache(string fileName, ILongWaitBroker progress) { // Optimize the results cache to get rid of any unnecessary // chromatogram data. var settings = Document.Settings; if (settings.HasResults) { var results = settings.MeasuredResults; if (results.IsLoaded) { var resultsNew = results.OptimizeCache(fileName, _chromatogramManager.StreamManager, progress); if (!ReferenceEquals(resultsNew, results)) { SrmDocument docNew, docCurrent; do { docCurrent = Document; docNew = docCurrent.ChangeMeasuredResults(resultsNew); } while (!SetDocument(docNew, docCurrent)); } } } else { string cachePath = ChromatogramCache.FinalPathForName(DocumentFilePath, null); FileEx.SafeDelete(cachePath, true); } }
private static void CopyOldTools(string outerToolsFolderPath, ILongWaitBroker broker) { //Copy tools to a different folder then Directory.Move if successful. string tempOuterToolsFolderPath = string.Concat(outerToolsFolderPath, "_installing"); // Not L10N if (Directory.Exists(tempOuterToolsFolderPath)) { DirectoryEx.SafeDelete(tempOuterToolsFolderPath); // Not sure this is necessay, but just to be safe if (Directory.Exists(tempOuterToolsFolderPath)) throw new Exception(Resources.Program_CopyOldTools_Error_copying_external_tools_from_previous_installation); } // Must create the tools directory to avoid ending up here again next time Directory.CreateDirectory(tempOuterToolsFolderPath); ToolList toolList = Settings.Default.ToolList; int numTools = toolList.Count; const int endValue = 100; int progressValue = 0; int increment = (endValue - progressValue)/(numTools +1); foreach (var tool in toolList) { string toolDirPath = tool.ToolDirPath; if (!string.IsNullOrEmpty(toolDirPath) && Directory.Exists(toolDirPath)) { string foldername = Path.GetFileName(toolDirPath); string newDir = Path.Combine(outerToolsFolderPath, foldername); string tempNewDir = Path.Combine(tempOuterToolsFolderPath, foldername); if (!Directory.Exists(tempNewDir)) DirectoryEx.DirectoryCopy(toolDirPath, tempNewDir, true); tool.ToolDirPath = newDir; // Update the tool to point to its new directory. tool.ArgsCollectorDllPath = tool.ArgsCollectorDllPath.Replace(toolDirPath, newDir); } if (broker.IsCanceled) { // Don't leave around a corrupted directory DirectoryEx.SafeDelete(tempOuterToolsFolderPath); return; } progressValue += increment; broker.ProgressValue = progressValue; } Directory.Move(tempOuterToolsFolderPath, outerToolsFolderPath); Settings.Default.ToolList = ToolList.CopyTools(toolList); }
/// <summary> /// The asynchronous download client links a webClient to a LongWaitBroker. It supports /// multiple asynchronous downloads, and updates the associated broker's progress value. /// </summary> /// <param name="waitBroker">The associated LongWaitBroker</param> /// <param name="files">The numbers of file this instance is expected to download. This /// is used to accurately update the broker's progress value</param> public MultiFileAsynchronousDownloadClient(ILongWaitBroker waitBroker, int files) { _longWaitBroker = waitBroker; _webClient = new WebClient(); FilesDownloaded = 0; _webClient.DownloadProgressChanged += (sender, args) => { _longWaitBroker.ProgressValue = (int) Math.Min(100, ((((double) FilesDownloaded)/files)*100) + ((1.0/files)*args.ProgressPercentage)); }; _webClient.DownloadFileCompleted += (sender, args) => { FilesDownloaded++; DownloadSucceeded = (args.Error == null); DownloadComplete = true; }; }
private void FindDataFiles(string directory, bool overwrite, ILongWaitBroker longWaitBroker) { // Don't search if every spectrum source file has an exact match and an alternate match if (directory == null || !Directory.Exists(directory) || (!overwrite && SpectrumSourceFiles.Values.All(s => s.HasMatches))) return; if (longWaitBroker != null) { longWaitBroker.Message = string.Format(Resources.ImportResultsControl_FindResultsFiles_Searching_for_matching_results_files_in__0__, directory); } try { foreach (string entry in Directory.EnumerateFileSystemEntries(directory)) { if (longWaitBroker != null && longWaitBroker.IsCanceled) return; if (entry != null && DataSourceUtil.IsDataSource(entry)) TryMatch(entry, overwrite); } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { // No permissions on folder } }