/// <summary> /// Added to show <see cref="SpectrumLibraryInfoDlg"/> /// </summary> private void TestLibraryInfo() { var libspec = new BiblioSpecLiteSpec("ManageLibraryRunsTestScores", TestFilesDir.GetTestPath("ManageLibraryRunsTestScores.blib")); var newLib = BiblioSpecLiteLibrary.Load(libspec, new DefaultFileLoadMonitor(new SilentProgressMonitor())); AddLibrary(libspec, newLib); WaitForDocumentLoaded(); var libExplore = ShowDialog <ViewLibraryDlg>(SkylineWindow.ViewSpectralLibraries); var specLibInfoDlg = ShowDialog <SpectrumLibraryInfoDlg>(libExplore.ShowLibDetails); IList <SpectrumSourceFileDetails> datafiles = specLibInfoDlg.GetGridView(); Assert.AreEqual(datafiles.Count, 5); foreach (var file in datafiles) { Assert.AreEqual(0, file.BestSpectrum); Assert.AreEqual(0, file.MatchedSpectrum); Assert.AreEqual(file.CutoffScores.Count, 0); } OkDialog(specLibInfoDlg, specLibInfoDlg.OkDialog); var modDlg = ShowDialog <AddModificationsDlg>(() => libExplore.ChangeSelectedLibrary("ManageLibraryRunsTestScores")); OkDialog(modDlg, modDlg.OkDialog); WaitForConditionUI(() => libExplore.HasSelectedLibrary); specLibInfoDlg = ShowDialog <SpectrumLibraryInfoDlg>(libExplore.ShowLibDetails); datafiles = specLibInfoDlg.GetGridView(); Assert.AreEqual(datafiles.Count, 4); Assert.AreEqual(datafiles[0].CutoffScores.Count, 1); Assert.AreEqual(datafiles[0].MatchedSpectrum, 1); Assert.AreEqual(datafiles[0].BestSpectrum, 1); Assert.AreEqual(datafiles[1].CutoffScores.Count, 1); Assert.AreEqual(datafiles[1].MatchedSpectrum, 10); Assert.AreEqual(datafiles[1].BestSpectrum, 9); Assert.AreEqual(datafiles[1].CutoffScores.Count, 1); Assert.AreEqual(datafiles[2].MatchedSpectrum, 3); Assert.AreEqual(datafiles[2].BestSpectrum, 3); Assert.AreEqual(datafiles[3].MatchedSpectrum, 1); Assert.AreEqual(datafiles[3].BestSpectrum, 1); OkDialog(specLibInfoDlg, specLibInfoDlg.OkDialog); OkDialog(libExplore, libExplore.CancelDialog); }
public bool BuildLibrary(IProgressMonitor progress) { RetentionTimeRegression regr = null; var standardSpectra = new List <SpectrumMzInfo>(); if (IrtStandard != null && !ReferenceEquals(IrtStandard, IrtStandard.EMPTY)) { // Align Prosit iRTs with iRT standard var standardPeptidesToAdd = SkylineWindow.ReadStandardPeptides(IrtStandard); if (standardPeptidesToAdd != null && standardPeptidesToAdd.Count > 0) { // Get iRTs var standardIRTMap = _rtModel.Predict(_prositClient, _document.Settings, standardPeptidesToAdd.Select(p => (PrositRetentionTimeModel.PeptideDocNodeWrapper)p.NodePep).ToArray(), CancellationToken.None); var original = standardIRTMap.ToDictionary(p => p.Key.ModifiedTarget, p => p.Value); var target = IrtStandard.Peptides.ToDictionary(p => p.ModifiedTarget, p => p.Irt); var aligned = AlignedRetentionTimes.AlignLibraryRetentionTimes(target, original, 0.0, RegressionMethodRT.linear, CancellationToken.None); regr = aligned.Regression; // Get spectra var standardMS = _intensityModel.PredictBatches(_prositClient, progress, _document.Settings, standardPeptidesToAdd.Select(p => p.WithNCE(_nce)).ToArray(), CancellationToken.None); // Merge iRT and MS2 into SpecMzInfos standardSpectra = standardMS.Spectra.Select(m => m.SpecMzInfo).ToList(); for (var i = 0; i < standardSpectra.Count; ++i) { if (standardIRTMap.TryGetValue(standardMS.Spectra[i].PeptidePrecursorNCE.NodePep, out var iRT)) { standardSpectra[i].RetentionTime = iRT; } } } } // Predict fragment intensities PrositMS2Spectra ms = _intensityModel.PredictBatches(_prositClient, progress, _document.Settings, _peptides.Zip(_precursors, (pep, prec) => new PrositIntensityModel.PeptidePrecursorNCE(pep, prec, _nce)).ToArray(), CancellationToken.None); var specMzInfo = ms.Spectra.Select(m => m.SpecMzInfo).ToList(); // Predict iRTs for peptides var distinctPeps = _peptides.Select(p => (PrositRetentionTimeModel.PeptideDocNodeWrapper)p).Distinct( new SystemLinqExtensionMethods.FuncEqualityComparer <PrositRetentionTimeModel.PeptideDocNodeWrapper>( (p1, p2) => p1.Node.ModifiedSequence == p2.Node.ModifiedSequence)).ToArray(); var iRTMap = _rtModel.PredictBatches(_prositClient, progress, _document.Settings, distinctPeps, CancellationToken.None); for (var i = 0; i < specMzInfo.Count; ++i) { if (iRTMap.TryGetValue(ms.Spectra[i].PeptidePrecursorNCE.NodePep, out var iRT)) { specMzInfo[i].RetentionTime = regr?.Conversion?.GetY(iRT) ?? iRT; } } // Build library var librarySpectra = SpectrumMzInfo.RemoveDuplicateSpectra(standardSpectra.Concat(specMzInfo).ToList()); // Delete if already exists, no merging with Prosit var libraryExists = File.Exists(LibrarySpec.FilePath); if (libraryExists) { var replace = _replaceLibrary(); if (!replace) { return(false); } FileEx.SafeDelete(LibrarySpec.FilePath); } if (!librarySpectra.Any()) { return(true); } // Build the library using (var blibDb = BlibDb.CreateBlibDb(LibrarySpec.FilePath)) { var docLibrarySpec = new BiblioSpecLiteSpec(LibrarySpec.Name, LibrarySpec.FilePath); BiblioSpecLiteLibrary docLibraryNew = null; var docLibrarySpec2 = docLibrarySpec; docLibraryNew = blibDb.CreateLibraryFromSpectra(docLibrarySpec2, librarySpectra, LibrarySpec.Name, progress); if (docLibraryNew == null) { return(false); } } return(true); }
private bool BuildLibraryOrThrow(IProgressMonitor progress, ref IProgressStatus progressStatus) { progressStatus = progressStatus.ChangeSegments(0, 5); var standardSpectra = new List <SpectrumMzInfo>(); // First get predictions for iRT standards specified by the user which may or may not be in the document if (IrtStandard != null && !ReferenceEquals(IrtStandard, IrtStandard.EMPTY) && !ReferenceEquals(IrtStandard, IrtStandard.AUTO)) { var standardPeptidesToAdd = ReadStandardPeptides(IrtStandard); if (standardPeptidesToAdd != null && standardPeptidesToAdd.Count > 0) { // Get iRTs var standardIRTMap = _rtModel.Predict(_prositClient, _document.Settings, standardPeptidesToAdd.Select(p => (PrositRetentionTimeModel.PeptideDocNodeWrapper)p.NodePep).ToArray(), CancellationToken.None); // Get spectra var standardMS = _intensityModel.PredictBatches(_prositClient, progress, ref progressStatus, _document.Settings, standardPeptidesToAdd.Select(p => p.WithNCE(_nce)).ToArray(), CancellationToken.None); // Merge iRT and MS2 into SpecMzInfos standardSpectra = standardMS.Spectra.Select(m => m.SpecMzInfo).ToList(); for (var i = 0; i < standardSpectra.Count; ++i) { if (standardIRTMap.TryGetValue(standardMS.Spectra[i].PeptidePrecursorNCE.NodePep, out var iRT)) { standardSpectra[i].RetentionTime = iRT; } } } } progressStatus = progressStatus.NextSegment(); // Predict fragment intensities PrositMS2Spectra ms = _intensityModel.PredictBatches(_prositClient, progress, ref progressStatus, _document.Settings, _peptides.Zip(_precursors, (pep, prec) => new PrositIntensityModel.PeptidePrecursorNCE(pep, prec, IsotopeLabelType.light, _nce)).ToArray(), CancellationToken.None); progressStatus = progressStatus.NextSegment(); var specMzInfo = ms.Spectra.Select(m => m.SpecMzInfo).ToList(); // Predict iRTs for peptides var distinctModifiedSequences = new HashSet <string>(); var distinctPeps = new List <PrositRetentionTimeModel.PeptideDocNodeWrapper>(); foreach (var p in _peptides) { if (distinctModifiedSequences.Add(p.ModifiedSequence)) { distinctPeps.Add(new PrositRetentionTimeModel.PeptideDocNodeWrapper(p)); } } var iRTMap = _rtModel.PredictBatches(_prositClient, progress, ref progressStatus, _document.Settings, distinctPeps, CancellationToken.None); progressStatus = progressStatus.NextSegment(); for (var i = 0; i < specMzInfo.Count; ++i) { if (iRTMap.TryGetValue(ms.Spectra[i].PeptidePrecursorNCE.NodePep, out var iRT)) { specMzInfo[i].RetentionTime = iRT; } } // Build library var librarySpectra = SpectrumMzInfo.RemoveDuplicateSpectra(standardSpectra.Concat(specMzInfo).ToList()); // Delete if already exists, no merging with Prosit var libraryExists = File.Exists(LibrarySpec.FilePath); if (libraryExists) { var replace = _replaceLibrary(); if (!replace) { return(false); } FileEx.SafeDelete(LibrarySpec.FilePath); } if (!librarySpectra.Any()) { return(true); } progressStatus = progressStatus.NextSegment().ChangeMessage(Resources.SkylineWindow_SaveDocument_Saving___); // Build the library using (var blibDb = BlibDb.CreateBlibDb(LibrarySpec.FilePath)) { var docLibrarySpec = new BiblioSpecLiteSpec(LibrarySpec.Name, LibrarySpec.FilePath); BiblioSpecLiteLibrary docLibraryNew = null; var docLibrarySpec2 = docLibrarySpec; docLibraryNew = blibDb.CreateLibraryFromSpectra(docLibrarySpec2, librarySpectra, LibrarySpec.Name, progress, ref progressStatus); if (docLibraryNew == null) { return(false); } } return(true); }
public bool TryGetDocumentLibrary(out BiblioSpecLiteLibrary docLib) { docLib = null; for (int i = 0; i < _libraries.Count; i++) { if (_librarySpecs[i] != null && _librarySpecs[i].IsDocumentLibrary) { docLib = _libraries[i] as BiblioSpecLiteLibrary; return docLib != null; } } return false; }