public void SettingsChangeTranGroups() { SrmDocument docFasta = CreateMixedDoc(); SrmSettings settings = docFasta.Settings; // Add heavy mod SrmDocument docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideModifications( m => m.ChangeModifications(IsotopeLabelType.heavy, new[] { new StaticMod("N-Terminal K", "K", ModTerminus.C, "H7", LabelAtoms.None, null, null) }))); CheckNTerminalKGroups(docFasta2); Assert.AreEqual(docFasta.PeptideCount, docFasta2.PeptideCount); // Add multiple charges with heavy mod var newCharges = Adduct.ProtonatedFromCharges(2, 3, 4); settings = docFasta2.Settings; SrmDocument docFasta3 = docFasta2.ChangeSettings(settings.ChangeTransitionFilter( f => f.ChangePeptidePrecursorCharges(newCharges))); CheckNTerminalKGroups(docFasta3); Assert.AreEqual(docFasta.PeptideCount, docFasta3.PeptideCount); // Use charge that will cause filtering on instrument maximum m/z docFasta2 = docFasta.ChangeSettings(settings.ChangeTransitionFilter( f => f.ChangePeptidePrecursorCharges(Adduct.ProtonatedFromCharges(1)))); Assert.IsTrue(docFasta.PeptideTransitionGroupCount < docFasta2.PeptideTransitionGroupCount); Assert.AreEqual(docFasta.PeptideCount, docFasta2.PeptideCount); }
public void SettingsChangeTrans() { SrmDocument docFasta = CreateMixedDoc(); SrmSettings settings = docFasta.Settings; SrmDocument docFastaNoP = docFasta.ChangeSettings(settings.ChangeTransitionFilter( f => f.ChangeMeasuredIons(new MeasuredIon[0]))); // Fixed start and end positions SrmDocument docFasta2 = CheckTranstions(docFastaNoP, "ion 1", "last ion", 1); CheckTranstions(docFasta2, "ion 2", "last ion - 1", 3); docFasta2 = CheckTranstions(docFastaNoP, "ion 3", "last ion - 2", 5); CheckTranstions(docFasta2, "ion 4", "last ion - 3", 7); // Check ion types including precursor var docPrec = docFasta2.ChangeSettings(docFasta2.Settings.ChangeTransitionFilter(f => f.ChangePeptideIonTypes(new[] { IonType.y, IonType.precursor }))); Assert.AreEqual(docFasta2.PeptideTransitionCount + docFasta2.PeptideTransitionGroupCount, docPrec.PeptideTransitionCount); docPrec = docFasta2.ChangeSettings(docFasta2.Settings.ChangeTransitionFilter(f => f.ChangePeptideIonTypes(new[] { IonType.precursor }))); Assert.AreEqual(docFasta2.PeptideTransitionGroupCount, docPrec.PeptideTransitionCount); AssertEx.Serializable(docPrec, AssertEx.DocumentCloned); // TODO: Finish this test }
public static SrmDocument RecalculateAlignments(SrmDocument document, IProgressMonitor progressMonitor) { var newSources = ListAvailableRetentionTimeSources(document.Settings); var newResultsSources = ListSourcesForResults(document.Settings.MeasuredResults, newSources); var allLibraryRetentionTimes = ReadAllRetentionTimes(document, newSources); var newFileAlignments = new List <FileRetentionTimeAlignments>(); IProgressStatus progressStatus = new ProgressStatus(@"Aligning retention times"); // CONSIDER: localize? Will users see this? foreach (var retentionTimeSource in newResultsSources.Values) { progressStatus = progressStatus.ChangePercentComplete(100 * newFileAlignments.Count / newResultsSources.Count); progressMonitor.UpdateProgress(progressStatus); try { var fileAlignments = CalculateFileRetentionTimeAlignments(retentionTimeSource.Name, allLibraryRetentionTimes, progressMonitor); newFileAlignments.Add(fileAlignments); } catch (OperationCanceledException) { progressMonitor.UpdateProgress(progressStatus.Cancel()); return(null); } } var newDocRt = new DocumentRetentionTimes(newSources.Values, newFileAlignments); var newDocument = document.ChangeSettings(document.Settings.ChangeDocumentRetentionTimes(newDocRt)); Debug.Assert(IsLoaded(newDocument)); progressMonitor.UpdateProgress(progressStatus.Complete()); return(newDocument); }
private SrmDocument ConnectLibrarySpecs(SrmDocument document, string documentPath) { string docLibFile = null; if (!string.IsNullOrEmpty(documentPath) && document.Settings.PeptideSettings.Libraries.HasDocumentLibrary) { docLibFile = BiblioSpecLiteSpec.GetLibraryFileName(documentPath); if (!File.Exists(docLibFile)) { Assert.Fail(Resources.CommandLine_ConnectLibrarySpecs_Error__Could_not_find_the_spectral_library__0__for_this_document_, docLibFile); } } var settings = document.Settings.ConnectLibrarySpecs((library, librarySpec) => { string name = library != null ? library.Name : librarySpec.Name; LibrarySpec spec; if (Settings.Default.SpectralLibraryList.TryGetValue(name, out spec)) { if (File.Exists(spec.FilePath)) { return(spec); } } string fileName = library != null ? library.FileNameHint : Path.GetFileName(librarySpec.FilePath); if (fileName != null) { // First look for the file name in the document directory string pathLibrary = PathEx.FindExistingRelativeFile(documentPath, fileName); if (pathLibrary != null) { return(CreateLibrarySpec(library, librarySpec, pathLibrary, true)); } // In the user's default library directory pathLibrary = Path.Combine(Settings.Default.LibraryDirectory, fileName); if (File.Exists(pathLibrary)) { return(CreateLibrarySpec(library, librarySpec, pathLibrary, false)); } } Assert.Fail(Resources.CommandLine_ConnectLibrarySpecs_Warning__Could_not_find_the_spectral_library__0_, name); return(CreateLibrarySpec(library, librarySpec, null, false)); }, docLibFile); if (ReferenceEquals(settings, document.Settings)) { return(document); } // If the libraries were moved to disconnected state, then avoid updating // the document tree for this change, or it will strip all the library // information off the document nodes. if (settings.PeptideSettings.Libraries.DisconnectedLibraries != null) { return(document.ChangeSettingsNoDiff(settings)); } return(document.ChangeSettings(settings)); }
private SrmDocument ChangeQuantificationSettings(SrmDocument srmDocument, QuantificationSettings quantificationSettings) { return(srmDocument.ChangeSettings( srmDocument.Settings.ChangePeptideSettings( srmDocument.Settings.PeptideSettings.ChangeAbsoluteQuantification( quantificationSettings)))); }
public void SettingsChangeMassCalcProps() { SrmDocument docFasta = CreateMixedDoc(); SrmSettings settings = docFasta.Settings; // Use average precursor masses SrmDocument docFasta2 = docFasta.ChangeSettings(settings.ChangeTransitionPrediction( p => p.ChangePrecursorMassType(MassType.Average))); // Average masses should be heavier that monoisotipic, and transitions should be unchanged CheckMasses(docFasta, docFasta2, (before, after) => Assert.IsTrue(before < after), Assert.AreEqual); // Use average fragment masses settings = docFasta2.Settings.ChangeTransitionInstrument(instrument => instrument.ChangeMaxMz(1501)); // Keep all the new heavy transitions SrmDocument docFasta3 = docFasta2.ChangeSettings(settings.ChangeTransitionPrediction( p => p.ChangeFragmentMassType(MassType.Average))); // Precursor masses should not have changed, and transitions should be heavier CheckMasses(docFasta2, docFasta3, Assert.AreEqual, (before, after) => Assert.IsTrue(before < after)); // Change both back to all monoisotopic settings = docFasta3.Settings; SrmDocument docFasta4 = docFasta3.ChangeSettings(settings.ChangeTransitionPrediction( p => p.ChangePrecursorMassType(MassType.Monoisotopic).ChangeFragmentMassType(MassType.Monoisotopic))); // This should return the masses to their original values CheckMasses(docFasta, docFasta4, Assert.AreEqual, Assert.AreEqual); // TODO: Static modifications }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var lib = GetOptimizationLibrary(docCurrent); if (lib != null && !lib.IsNone && !lib.IsUsable) { lib = LoadLibrary(container, lib); } if (lib == null || !ReferenceEquals(document.Id, container.Document.Id)) { // Loading was cancelled or document changed EndProcessing(document); return(false); } SrmDocument docNew; do { // Change the document to use the new library docCurrent = container.Document; if (!ReferenceEquals(GetOptimizationLibrary(docCurrent), GetOptimizationLibrary(container.Document))) { EndProcessing(document); return(false); } docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangeTransitionPrediction(predict => predict.ChangeOptimizationLibrary(lib))); }while (!CompleteProcessing(container, docNew, docCurrent)); return(true); }
public SrmDocument AddDocumentSpectralLibrary(SrmDocument doc, LibrarySpec libSpec) { return(doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib => { var libSpecs = new List <LibrarySpec>(); var libs = new List <Library>(); if (libSpec.IsDocumentLibrary) { libSpecs.Add(libSpec); libs.Add(DocLib); int skipCount = lib.HasDocumentLibrary ? 1 : 0; libSpecs.AddRange(lib.LibrarySpecs.Skip(skipCount)); libs.AddRange(lib.Libraries.Skip(skipCount)); lib = lib.ChangeDocumentLibrary(true); } else { for (int i = 0; i < lib.LibrarySpecs.Count; i++) { var spec = lib.LibrarySpecs[i]; if (spec.IsDocumentLibrary || spec.Name != libSpec.Name) { libSpecs.Add(spec); libs.Add(lib.Libraries[i]); } } libSpecs.Add(libSpec); libs.Add(DocLib); } return lib.ChangeLibraries(libSpecs, libs); }))); }
public static SrmDocument ToggleAuditLogging(SrmDocument doc, bool enable) { var newDoc = doc.ChangeSettings( doc.Settings.ChangeDataSettings(doc.Settings.DataSettings.ChangeAuditLogging(enable))); return(newDoc); }
public void MultiLabelTypeListTest() { int startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); // Add some FASTA IdentityPath pathRoot = IdentityPath.ROOT; SrmDocument docFasta = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, pathRoot, out _); const int initProt = 2, initPep = 26, initTran = 89; AssertEx.IsDocumentState(docFasta, ++startRev, initProt, initPep, initTran); // Add multiple heavy types var settings = docFasta.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(LABEL_TYPE13_C, HEAVY_MODS_13_C), new TypedModifications(LABEL_TYPE15_N, HEAVY_MODS_15_N) })); var docMulti = docFasta.ChangeSettings(settings); // CONSIDER: make explicit S-Lens, cone voltage, CE etc roundtrip? // docMulti.MoleculeTransitionGroups.FirstOrDefault().ChangeExplicitValues(ExplicitTransitionGroupValues.TEST) // Make sure transition lists export to various formats and roundtrip VerifyExportRoundTrip(new ThermoMassListExporter(docMulti), docFasta); // Add Oxidation (M) as a static modification to challenge new mass list importing flexibility VerifyExportRoundTrip(new AbiMassListExporter(AddOxidationM(docMulti)), AddOxidationM(docFasta)); VerifyExportRoundTrip(new AgilentMassListExporter(docMulti), docFasta); VerifyExportRoundTrip(new WatersMassListExporter(docMulti), docFasta); }
protected override void DoTest() { var document = new SrmDocument(SrmSettingsList.GetDefault()); var staticMods = document.Settings.PeptideSettings.Modifications.StaticModifications.ToList(); staticMods.Add(UniMod.GetModification("Phospho (ST)", true).ChangeVariable(true)); var heavyMods = new List <StaticMod> { UniMod.GetModification("Label:13C(6)15N(4) (C-term R)", false) }; document = document.ChangeSettings(document.Settings .ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods).ChangeHeavyModifications(heavyMods)) .ChangeTransitionFilter(filt => filt.ChangePrecursorCharges(new [] { 2, 3, 4, 5 }))); Assert.IsTrue(SkylineWindow.SetDocument(document, SkylineWindow.Document)); RunUI(() => SkylineWindow.Paste(TextUtil.LineSeparate(PEPTIDE_MODIFIED, PEPTIDE_UNMODIFIED))); document = WaitForDocumentChangeLoaded(document); RunUI(() => SkylineWindow.Paste(PEPTIDE_EXTRA)); var docPaste1 = WaitForDocumentChangeLoaded(document); AssertEx.IsDocumentState(docPaste1, null, 2, 6, 44, 129); TestErrorMessages(); TestUse(); }
private static SrmDocument ChangePeptideModifications(SrmDocument doc, IList <TypedModifications> typedHeavyMods) { var settingsNew = doc.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, typedHeavyMods)); return(doc.ChangeSettings(settingsNew)); }
public void MultiLabelExplicitSerialTest() { // Create a simple document and add two peptides SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); const string pepSequence1 = "QFVLSCVILR"; const string pepSequence2 = "DIEVYCDGAITTK"; var reader = new StringReader(string.Join("\n", new[] { ">peptides1", pepSequence1, pepSequence2 })); IdentityPath path; document = document.ImportFasta(reader, true, IdentityPath.ROOT, out path); Assert.AreEqual(2, document.PeptideCount); // Add some modifications in two new label types var modCarb = new StaticMod("Carbamidomethyl Cysteine", "C", null, "C2H3ON"); var modOther = new StaticMod("Another Cysteine", "C", null, "CO8N2"); var staticMods = new[] { modCarb, modOther }; var mod15N = new StaticMod("All 15N", null, null, null, LabelAtoms.N15, null, null); var modK13C = new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null); var modR13C = new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null); var modV13C = new StaticMod("Heavy V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null); var heavyMods = new[] { mod15N, modK13C, modR13C, modV13C }; var labelTypeAA = new IsotopeLabelType("heavy AA", IsotopeLabelType.FirstHeavy); var labelTypeAll = new IsotopeLabelType("heavy All", IsotopeLabelType.FirstHeavy + 1); var settings = document.Settings; settings = settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(labelTypeAA, new[] { modK13C, modR13C }), new TypedModifications(labelTypeAll, new[] { mod15N }) })); document = document.ChangeSettings(settings); Assert.AreEqual(6, document.PeptideTransitionGroupCount); // Add modifications to light and heavy AA in the first peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 0); var nodePepMod = (PeptideDocNode)document.FindNode(path); var explicitMod = new ExplicitMods(nodePepMod.Peptide, new[] { new ExplicitMod(pepSequence1.IndexOf('C'), modOther) }, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAA, new ExplicitMod[0]) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); // Add a modification to heavy All in the second peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 1); nodePepMod = (PeptideDocNode)document.FindNode(path); explicitMod = new ExplicitMods(nodePepMod.Peptide, null, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAll, new[] { new ExplicitMod(pepSequence2.IndexOf('V'), modV13C) }) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); AssertEx.Serializable(document, 3, AssertEx.DocumentCloned); }
private static double driftTimeMax = 13.799765403988133; // Known max drift time for this file - use to mimic resolving power logic for test purposes private static SrmDocument InitWatersImsMseDocument(TestFilesDir testFilesDir, IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType driftPeakWidthCalcType, bool withDriftTimeFilter, bool withDriftTimePredictor, out string docPath) { var skyFile = withDriftTimePredictor ? "single_with_driftinfo.sky" : "single_no_driftinfo.sky"; docPath = testFilesDir.GetTestPath(skyFile); var cmdline = new CommandLine(); Assert.IsTrue(cmdline.OpenSkyFile(docPath)); // Handles any path shifts in database files, like our .imdb file SrmDocument doc = cmdline.Document; // Cause library load and subsequent document update using (var docContainer = new ResultsTestDocumentContainer(null, docPath)) { docContainer.SetDocument(doc, null, true); docContainer.AssertComplete(); doc = docContainer.Document; double resolvingPower = 100; // Test was originally written with resolving power 100 double widthAtDtMax = 2 * driftTimeMax / resolvingPower; var driftTimeWindowWidthCalculator = new IonMobilityWindowWidthCalculator(driftPeakWidthCalcType, resolvingPower, 0, widthAtDtMax); if (withDriftTimeFilter && !withDriftTimePredictor) { // Use the bare drift times in the spectral library var librarySpec = new BiblioSpecLiteSpec("drift test", testFilesDir.GetTestPath("waters-mobility.filtered-scaled.blib")); doc = doc.ChangeSettings( doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })). ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesWindowWidthCalculator(driftTimeWindowWidthCalculator)). ChangePeptidePrediction(p => p.ChangeUseLibraryIonMobilityValues(true)) ); } else if (withDriftTimeFilter) { doc = doc.ChangeSettings( doc.Settings.ChangePeptideSettings(ps => ps.ChangePrediction( ps.Prediction.ChangeDriftTimePredictor(ps.Prediction.IonMobilityPredictor.ChangeDriftTimeWindowWidthCalculator(driftTimeWindowWidthCalculator))))); } } return(doc); }
private SrmDocument EnsureAnnotation(SrmDocument document, string annotationName, bool addAnnotation, IEnumerable <string> annotationNames) { var containsQAnnotation = annotationNames.Contains(annotationName); if (!containsQAnnotation && addAnnotation) { var annotationTargets = AnnotationDef.AnnotationTargetSet.OfValues(AnnotationDef.AnnotationTarget.precursor_result); var newAnnotationDef = new AnnotationDef(annotationName, annotationTargets, AnnotationDef.AnnotationType.number, new string[0]); AnnotationDef existingAnnotationDef; // CONSIDER: Throw error instead of overwriting? if (!Settings.Default.AnnotationDefList.TryGetValue(annotationName, out existingAnnotationDef) && !Equals(existingAnnotationDef, newAnnotationDef)) { Settings.Default.AnnotationDefList.SetValue(newAnnotationDef); } else { // Use the existing annotation newAnnotationDef = existingAnnotationDef; } document = document.ChangeSettings(Document.Settings.ChangeAnnotationDefs(defs => { var defsNew = defs.ToList(); defsNew.Add(newAnnotationDef); return(defsNew); })); } else if (containsQAnnotation && !AddAnnotation) { document = document.ChangeSettings(Document.Settings.ChangeAnnotationDefs(defs => { var defsNew = defs.ToList(); defsNew.RemoveAll(def => Equals(def.Name, annotationName)); return(defsNew); })); var annotationNamesToKeep = document.Settings.DataSettings.AnnotationDefs.Select(def => def.Name).ToList(); document = (SrmDocument)document.StripAnnotationValues(annotationNamesToKeep); } return(document); }
public void FullScanPrecursorTransitionsTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"Test\FullScanPrecursor.zip"); string docPath = testFilesDir.GetTestPath("FullScanPrecursor.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 4, 5, 52); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { var mitoLibSpec = new BiblioSpecLiteSpec("mito2", testFilesDir.GetTestPath("mito2.blib")); doc = docContainer.ChangeLibSpecs(new[] { mitoLibSpec }); Assert.IsTrue(doc.IsLoaded); // Switch to only precursor ions var docPrecOnly = doc.ChangeSettings(doc.Settings.ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor }))); // All precursors should have 3 precursor transitions (M, M+1 and M+2) AssertEx.IsDocumentState(docPrecOnly, 3, 1, 4, 5, 15); Assert.IsFalse(docPrecOnly.PeptideTransitions.Any(nodeTran => nodeTran.Transition.IonType != IonType.precursor)); // Use low resolution MS1 filtering var docLowMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, null) .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, 0.5, null))); // All precursors should have one precursor transition AssertEx.IsDocumentState(docLowMs1, 4, 1, 4, 5, 5); // Add y-ions to low resolution filtering var docLowMs1Y = docLowMs1.ChangeSettings(docLowMs1.Settings.ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y }))); AssertEx.IsDocumentState(docLowMs1Y, 5, 1, 4, 5, 33); // Turn off MS1 filtering var docNoMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null))); // One of the precursors should have no transitions, since its spectrum has no precursor match AssertEx.IsDocumentState(docNoMs1, 4, 1, 4, 5, 4); // Turn off MS/MS library matching var docNoLibMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.none))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docNoLibMatch, 5, 1, 4, 5, 5); // Use library plus filter matching var docLibPlusMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.all_plus))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docLibPlusMatch, 5, 1, 4, 5, 5); // Release the library stream, and dispose of the directory docContainer.ChangeLibSpecs(new LibrarySpec[0]); } testFilesDir.Dispose(); }
private SrmDocument AddOxidationM(SrmDocument doc) { return(doc.ChangeSettings( doc.Settings.ChangePeptideModifications(mod => { var staticMods = mod.StaticModifications.ToList(); staticMods.Add(UniMod.GetModification("Oxidation (M)", true).ChangeVariable(false)); return mod.ChangeStaticModifications(staticMods); }))); }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var loadMonitor = new LoadMonitor(this, container, container.Document); IPeakScoringModel scoringModel = new MProphetPeakScoringModel( Path.GetFileNameWithoutExtension(container.DocumentFilePath), null as LinearModelParams, MProphetPeakScoringModel.GetDefaultCalculators(docCurrent), true); var targetDecoyGenerator = new TargetDecoyGenerator(docCurrent, scoringModel, this, loadMonitor); // Get scores for target and decoy groups. List <IList <float[]> > targetTransitionGroups, decoyTransitionGroups; targetDecoyGenerator.GetTransitionGroups(out targetTransitionGroups, out decoyTransitionGroups); if (!decoyTransitionGroups.Any()) { throw new InvalidDataException(); } // Set intial weights based on previous model (with NaN's reset to 0) var initialWeights = new double[scoringModel.PeakFeatureCalculators.Count]; // But then set to NaN the weights that have unknown values for this dataset for (var i = 0; i < initialWeights.Length; ++i) { if (!targetDecoyGenerator.EligibleScores[i]) { initialWeights[i] = double.NaN; } } var initialParams = new LinearModelParams(initialWeights); // Train the model. scoringModel = scoringModel.Train(targetTransitionGroups, decoyTransitionGroups, targetDecoyGenerator, initialParams, null, null, scoringModel.UsesSecondBest, true, loadMonitor); SrmDocument docNew; do { docCurrent = container.Document; docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangePeptideIntegration(i => i.ChangeAutoTrain(false).ChangePeakScoringModel((PeakScoringModelSpec)scoringModel))); // Reintegrate peaks var resultsHandler = new MProphetResultsHandler(docNew, (PeakScoringModelSpec)scoringModel, _cachedFeatureScores); resultsHandler.ScoreFeatures(loadMonitor); if (resultsHandler.IsMissingScores()) { throw new InvalidDataException(Resources.ImportPeptideSearchManager_LoadBackground_The_current_peak_scoring_model_is_incompatible_with_one_or_more_peptides_in_the_document_); } docNew = resultsHandler.ChangePeaks(loadMonitor); }while (!CompleteProcessing(container, docNew, docCurrent)); return(true); }
private void TestMinIonCount() { const string protein = ">sp|P62258|1433E_HUMAN 14-3-3 protein epsilon OS=H**o sapiens GN=YWHAE PE=1 SV=1\r\n" + "MDDREDLVYQAKLAEQAERYDEMVESMKKVAGMDVELTVEERNLLSVAYKNVIGARRASW\r\n" + "RIISSIEQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHLIPAANTGESKVF\r\n" + "YYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVF\r\n" + "YYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDSTLIMQLLRDNLTLWTSDMQGDGE\r\n" + "EQNKEALQDVEDENQ*"; SrmDocument doc = null; RunUI(() => { doc = SkylineWindow.DocumentUI; Assert.IsTrue(SkylineWindow.LoadFile(GetTestPath("MinIonCount.sky"))); doc = WaitForDocumentChangeLoaded(doc); SkylineWindow.Paste(protein); }); doc = WaitForDocumentChange(doc); var minIonCount = 6; Assert.AreEqual(minIonCount, doc.Settings.TransitionSettings.Libraries.MinIonCount); Assert.AreEqual(11, doc.PeptideCount); foreach (var nodePepGroup in doc.MoleculeGroups) { foreach (var nodePep in nodePepGroup.Peptides) { Assert.AreNotEqual(0, nodePep.TransitionGroupCount); foreach (var nodeTranGroup in nodePep.TransitionGroups) { Assert.IsTrue(nodeTranGroup.TransitionCount >= minIonCount); } } } minIonCount = 5; RunUI(() => Assert.IsTrue(SkylineWindow.SetDocument( doc.ChangeSettings(doc.Settings.ChangeTransitionLibraries(libraries => libraries.ChangeMinIonCount(minIonCount))), doc))); doc = WaitForDocumentChange(doc); Assert.AreEqual(minIonCount, doc.Settings.TransitionSettings.Libraries.MinIonCount); Assert.AreEqual(12, doc.PeptideCount); foreach (var nodePepGroup in doc.MoleculeGroups) { foreach (var nodePep in nodePepGroup.Peptides) { Assert.AreNotEqual(0, nodePep.TransitionGroupCount); foreach (var nodeTranGroup in nodePep.TransitionGroups) { Assert.IsTrue(nodeTranGroup.TransitionCount >= minIonCount); } } } RunUI(() => SkylineWindow.SaveDocument()); }
/// <summary> /// Ensure that the document peptide settings contain all of the necessary heavy label types (i.e. "heavy1", "heavy2", ...) /// to accomodate the specified number of possible permutations. /// </summary> public SrmDocument EnsureLabelTypes(IProgressMonitor progressMonitor, SrmDocument document, int maxPermutationCount, List <IsotopeLabelType> partialLabelTypes) { if (partialLabelTypes.Count == 0) { partialLabelTypes.Add(IsotopeLabelType.light); } var labelTypesByName = document.Settings.PeptideSettings.Modifications.GetHeavyModificationTypes() .ToDictionary(label => label.Name); int maxSortValue = 0; if (labelTypesByName.Any()) { maxSortValue = labelTypesByName.Values.Max(label => label.SortOrder); } var labelTypesToAdd = new List <IsotopeLabelType>(); for (int i = partialLabelTypes.Count; i < maxPermutationCount - 1; i++) { if (progressMonitor.IsCanceled) { throw new OperationCanceledException(); } var name = FullyHeavyLabelType.Name + i; IsotopeLabelType labelType; if (!labelTypesByName.TryGetValue(name, out labelType)) { labelType = new IsotopeLabelType(name, ++maxSortValue); labelTypesToAdd.Add(labelType); } partialLabelTypes.Add(labelType); } if (!labelTypesByName.ContainsKey(FullyHeavyLabelType.Name)) { labelTypesToAdd.Add(FullyHeavyLabelType); } if (labelTypesToAdd.Any()) { var settings = document.Settings; var heavyModifications = settings.PeptideSettings.Modifications.HeavyModifications.ToList(); heavyModifications.AddRange(labelTypesToAdd.Select(labelType => new TypedModifications(labelType, ImmutableList.Empty <StaticMod>()))); var peptideModifications = settings.PeptideSettings.Modifications; peptideModifications = new PeptideModifications(peptideModifications.StaticModifications, peptideModifications.MaxVariableMods, peptideModifications.MaxNeutralLosses, heavyModifications, peptideModifications.InternalStandardTypes); settings = settings.ChangePeptideSettings(settings.PeptideSettings.ChangeModifications(peptideModifications)); document = document.ChangeSettings(settings); } return(document); }
public void SettingsChangeNotDoc() { SrmDocument docFasta = CreateMixedDoc(); SrmSettings settings = docFasta.Settings; // Change declustering potential, collision energy, and retention time var regressions = new DeclusterPotentialList(); regressions.AddDefaults(); var dpRegress = regressions["SCIEX"]; var collisions = new CollisionEnergyList(); collisions.AddDefaults(); var ceRegress = collisions["SCIEX"]; var calc = Settings.Default.RTScoreCalculatorList.GetDefaults().First(); var rtRegress = new RetentionTimeRegression("Test", calc, 3.5, 10.4, 12.8, new MeasuredRetentionTime[0]); SrmSettings settings2 = settings.ChangePeptidePrediction(p => p.ChangeRetentionTime(rtRegress)). ChangeTransitionPrediction(p => p.ChangeCollisionEnergy(ceRegress).ChangeDeclusteringPotential(dpRegress)); SrmDocument docFasta2 = docFasta.ChangeSettings(settings2); AssertEx.IsDocumentState(docFasta2, docFasta.RevisionIndex + 1, 3, 111, 352); Assert.AreSame(docFasta.Children, docFasta2.Children); Assert.AreNotEqual(docFasta.Settings, docFasta2.Settings); // Change auto-select toggles SrmSettings settings3 = settings.ChangePeptideFilter(f => f.ChangeAutoSelect(false)). ChangeTransitionFilter(f => f.ChangeAutoSelect(false)); SrmDocument docFasta3 = docFasta.ChangeSettings(settings3); AssertEx.IsDocumentState(docFasta3, docFasta.RevisionIndex + 1, 3, 111, 352); Assert.AreSame(docFasta.Children, docFasta3.Children); Assert.AreNotEqual(docFasta.Settings, docFasta3.Settings); }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var calc = GetIrtCalculator(docCurrent); if (calc != null && !calc.IsUsable) { calc = LoadCalculator(container, calc); } if (calc == null || !ReferenceEquals(document.Id, container.Document.Id)) { // Loading was cancelled or document changed EndProcessing(document); return(false); } var rtRegression = docCurrent.Settings.PeptideSettings.Prediction.RetentionTime; var rtRegressionNew = !ReferenceEquals(calc, rtRegression.Calculator) ? rtRegression.ChangeCalculator(calc) : rtRegression; if (rtRegressionNew.IsAutoCalcRequired(docCurrent, null)) { rtRegressionNew = AutoCalcRegressions(container, rtRegressionNew); } if (rtRegressionNew == null || !ReferenceEquals(document.Id, container.Document.Id) || // No change in the regression, including reference equal standard peptides (Equals(rtRegression, rtRegressionNew) && rtRegression.SamePeptides(rtRegressionNew))) { // Loading was cancelled or document changed EndProcessing(document); return(false); } SrmDocument docNew; do { // Change the document to use the new calculator and regression information. docCurrent = container.Document; if (!ReferenceEquals(rtRegression, docCurrent.Settings.PeptideSettings.Prediction.RetentionTime)) { EndProcessing(document); return(false); } docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangePeptidePrediction(predict => predict.ChangeRetentionTime(rtRegressionNew))); }while (!CompleteProcessing(container, docNew, docCurrent)); return(true); }
private static void ValidateRelativeRT(RelativeRT relativeRT, SrmDocument doc, string docPath, List <ChromatogramSet> listChromatograms) { FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); SrmSettings settings = doc.Settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications( mods.HeavyModifications.Select(m => m.ChangeRelativeRT(relativeRT)).ToArray())); var docMods = doc.ChangeSettings(settings); var docResults = docMods.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainer = new ResultsTestDocumentContainer(docMods, docPath); Assert.IsTrue(docContainer.SetDocument(docResults, docMods, true)); docContainer.AssertComplete(); docContainer.Release(); }
private static SrmDocument CreateLibraryDocument(SrmSettings settings, string textFasta, bool peptideList, TestDocumentContainer docContainer, BackgroundLoader libraryManager, out int startRev) { startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); Assert.IsTrue(docContainer.SetDocument(document, null)); // Register after first set document libraryManager.Register(docContainer); // Add libraries SrmDocument docLibraries = document.ChangeSettings(settings); ++startRev; // Add some FASTA IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = docLibraries.ImportFasta(new StringReader(textFasta), peptideList, path, out path); ++startRev; // Until libraries are loaded, only the sequences should appear if (!peptideList) { AssertEx.IsDocumentState(docFasta, startRev, textFasta.Count(c => c == '>'), 0, 0); } // Run the library load Assert.IsTrue(docContainer.SetDocument(docFasta, document, true)); ++startRev; // After library load completes peptides and transitions should have expected library info SrmDocument docLoaded = docContainer.Document; // Check expected library inforamation foreach (var nodePeptide in docLoaded.Peptides) { Assert.IsNull(nodePeptide.Rank); } foreach (var nodeTran in docLoaded.PeptideTransitions) { Assert.IsTrue(nodeTran.HasLibInfo); Assert.IsTrue(nodeTran.LibInfo.Rank <= 3); } return(docLoaded); }
public static SrmDocument AddRetentionTimePredictor(SrmDocument doc, LibrarySpec libSpec) { var calc = new RCalcIrt( Helpers.GetUniqueName(libSpec.Name, Settings.Default.RTScoreCalculatorList.Select(lib => lib.Name).ToArray()), libSpec.FilePath); var predictor = new RetentionTimeRegression( Helpers.GetUniqueName(libSpec.Name, Settings.Default.RetentionTimeList.Select(rt => rt.Name).ToArray()), calc, null, null, DEFAULT_RT_WINDOW, new List <MeasuredRetentionTime>()); Settings.Default.RTScoreCalculatorList.Add(calc); Settings.Default.RetentionTimeList.Add(predictor); return(doc.ChangeSettings( doc.Settings.ChangePeptideSettings( doc.Settings.PeptideSettings.ChangePrediction( doc.Settings.PeptideSettings.Prediction.ChangeRetentionTime(predictor))))); }
public static SrmDocument PrepareImportFasta(SrmDocument document) { // First preserve the state of existing document nodes in the tree // Todo: There are better ways to do this than this brute force method; revisit later. if (document.PeptideGroupCount > 0) { document = ChangeAutoManageChildren(document, PickLevel.all, false); } var pick = document.Settings.PeptideSettings.Libraries.Pick; if (pick != PeptidePick.library && pick != PeptidePick.both) { document = document.ChangeSettings(document.Settings.ChangePeptideLibraries(lib => lib.ChangePick(PeptidePick.library))); } return(document); }
public SrmDocument AddDocumentSpectralLibrary(SrmDocument doc, LibrarySpec libSpec) { return(doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib => { int skipCount = lib.HasDocumentLibrary ? 1 : 0; var libSpecs = new List <LibrarySpec> { libSpec }; libSpecs.AddRange(lib.LibrarySpecs.Skip(skipCount)); var libs = new List <Library> { DocLib }; libs.AddRange(lib.Libraries.Skip(skipCount)); return lib.ChangeDocumentLibrary(true).ChangeLibraries(libSpecs, libs); }))); }
private static SrmDocument CheckTranstions(SrmDocument document, string startName, string endName, int ionDiff) { SrmSettings settings = document.Settings; SrmDocument docNew = document.ChangeSettings(settings.ChangeTransitionFilter( f => f.ChangeFragmentRangeFirstName(startName).ChangeFragmentRangeLastName(endName)). ChangeTransitionInstrument(i => i.ChangeMaxMz(5000))); // length-n ions foreach (PeptideDocNode nodePeptide in docNew.Peptides) { Assert.AreEqual(Math.Max(0, nodePeptide.Peptide.Sequence.Length - ionDiff), nodePeptide.TransitionCount); } return(docNew); }
public void VerifySerialization(ListData listData) { var xmlSerializer = new XmlSerializer(typeof(ListData)); var stream = new MemoryStream(); xmlSerializer.Serialize(stream, listData); stream.Seek(0, SeekOrigin.Begin); var roundTrip = xmlSerializer.Deserialize(stream); Assert.AreEqual(listData, roundTrip); var document = new SrmDocument(SrmSettingsList.GetDefault()); document = document.ChangeSettings( document.Settings.ChangeDataSettings( document.Settings.DataSettings.ChangeListDefs(new[] { listData }))); AssertEx.Serializable(document); }
private static SrmDocument InitWiffDocument(TestFilesDir testFilesDir) { const LabelAtoms labelAtoms = LabelAtoms.C13 | LabelAtoms.N15; List <StaticMod> heavyMods = new List <StaticMod> { new StaticMod("Heavy K", "K", ModTerminus.C, null, labelAtoms, null, null), new StaticMod("Heavy R", "R", ModTerminus.C, null, labelAtoms, null, null), }; SrmSettings settings = SrmSettingsList.GetDefault(); settings = settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications(heavyMods)); SrmDocument doc = new SrmDocument(settings); IdentityPath selectPath; string path = testFilesDir.GetTestPath("051309_transition list.csv"); // Product m/z out of range var docError = doc; List <MeasuredRetentionTime> irtPeptides; List <SpectrumMzInfo> librarySpectra; List <TransitionImportErrorInfo> errorList; var inputs = new MassListInputs(path) { FormatProvider = CultureInfo.InvariantCulture, Separator = TextUtil.SEPARATOR_CSV }; docError.ImportMassList(inputs, null, out selectPath, out irtPeptides, out librarySpectra, out errorList); Assert.AreEqual(errorList.Count, 1); AssertEx.AreComparableStrings(TextUtil.SpaceSeparate(Resources.MassListRowReader_CalcTransitionExplanations_The_product_m_z__0__is_out_of_range_for_the_instrument_settings__in_the_peptide_sequence__1_, Resources.MassListRowReader_CalcPrecursorExplanations_Check_the_Instrument_tab_in_the_Transition_Settings), errorList[0].ErrorMessage, 2); Assert.AreEqual(errorList[0].Column, 1); Assert.AreEqual(errorList[0].Row, 19); doc = doc.ChangeSettings(settings.ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); inputs = new MassListInputs(path) { FormatProvider = CultureInfo.InvariantCulture, Separator = TextUtil.SEPARATOR_CSV }; doc = doc.ImportMassList(inputs, null, out selectPath); AssertEx.IsDocumentState(doc, 2, 9, 9, 18, 54); return(doc); }
protected override void DoTest() { var document = new SrmDocument(SrmSettingsList.GetDefault()); var staticMods = document.Settings.PeptideSettings.Modifications.StaticModifications.ToList(); staticMods.Add(UniMod.GetModification("Phospho (ST)", true).ChangeVariable(true)); var heavyMods = new List<StaticMod> {UniMod.GetModification("Label:13C(6)15N(4) (C-term R)", false)}; document = document.ChangeSettings(document.Settings .ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods).ChangeHeavyModifications(heavyMods)) .ChangeTransitionFilter(filt => filt.ChangePrecursorCharges(new [] {2, 3, 4, 5}))); Assert.IsTrue(SkylineWindow.SetDocument(document, SkylineWindow.Document)); RunUI(() => SkylineWindow.Paste(TextUtil.LineSeparate(PEPTIDE_MODIFIED, PEPTIDE_UNMODIFIED))); document = WaitForDocumentChangeLoaded(document); RunUI(() => SkylineWindow.Paste(PEPTIDE_EXTRA)); var docPaste1 = WaitForDocumentChangeLoaded(document); AssertEx.IsDocumentState(docPaste1, null, 2, 6, 44, 129); TestErrorMessages(); TestUse(); }
private SrmDocument ConnectOptimizationDatabase(SrmDocument document, string documentPath) { var settings = document.Settings.ConnectOptimizationDatabase(lib => FindOptimizationDatabase(documentPath, lib)); if (settings == null) return null; if (ReferenceEquals(settings, document.Settings)) return document; return document.ChangeSettings(settings); }
private bool ImportSearchInternal(CommandArgs commandArgs, ref SrmDocument doc) { var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(String.Empty)); var import = new ImportPeptideSearch { SearchFilenames = commandArgs.SearchResultsFiles.ToArray(), CutoffScore = commandArgs.CutoffScore.GetValueOrDefault() }; // Build library var builder = import.GetLibBuilder(doc, commandArgs.Saving ? commandArgs.SaveFile : commandArgs.SkylineFile, commandArgs.IncludeAmbiguousMatches); ImportPeptideSearch.ClosePeptideSearchLibraryStreams(doc); _out.WriteLine(Resources.CommandLine_ImportSearch_Creating_spectral_library_from_files_); foreach (var file in commandArgs.SearchResultsFiles) _out.WriteLine(Path.GetFileName(file)); if (!builder.BuildLibrary(progressMonitor)) return false; if (!string.IsNullOrEmpty(builder.AmbiguousMatchesMessage)) _out.WriteLine(builder.AmbiguousMatchesMessage); var docLibSpec = builder.LibrarySpec.ChangeDocumentLibrary(true); _out.WriteLine(Resources.CommandLine_ImportSearch_Loading_library); var libraryManager = new LibraryManager(); if (!import.LoadPeptideSearchLibrary(libraryManager, docLibSpec, progressMonitor)) return false; doc = import.AddDocumentSpectralLibrary(doc, docLibSpec); if (doc == null) return false; if (!import.VerifyRetentionTimes(import.GetFoundResultsFiles().Select(f => f.Path))) { _out.WriteLine(TextUtil.LineSeparate( Resources.ImportPeptideSearchDlg_NextPage_The_document_specific_spectral_library_does_not_have_valid_retention_times_, Resources.ImportPeptideSearchDlg_NextPage_Please_check_your_peptide_search_pipeline_or_contact_Skyline_support_to_ensure_retention_times_appear_in_your_spectral_libraries_)); return false; } // Look for results files to import import.InitializeSpectrumSourceFiles(doc); import.UpdateSpectrumSourceFilesFromDirs(import.GetDirsToSearch(Path.GetDirectoryName(commandArgs.SkylineFile)), false, null); var missingResultsFiles = import.GetMissingResultsFiles().ToArray(); if (missingResultsFiles.Any()) { foreach (var file in missingResultsFiles) { if (doc.Settings.HasResults && doc.Settings.MeasuredResults.FindMatchingMSDataFile(new MsDataFilePath(file)) != null) continue; _out.WriteLine(Resources.CommandLine_ImportSearch_Warning__Unable_to_locate_results_file___0__, Path.GetFileName(file)); } } // Add all modifications, if requested if (commandArgs.AcceptAllModifications) { import.InitializeModifications(doc); var foundMods = import.GetMatchedMods().Count(); var newModifications = new PeptideModifications(import.MatcherPepMods.StaticModifications, new[] {new TypedModifications(IsotopeLabelType.heavy, import.MatcherHeavyMods)}); var newSettings = import.AddModifications(doc, newModifications); if (!ReferenceEquals(doc.Settings, newSettings)) { if (foundMods != 1) _out.WriteLine(Resources.CommandLine_ImportSearch_Adding__0__modifications_, foundMods); else _out.WriteLine(Resources.CommandLine_ImportSearch_Adding_1_modification_); doc = doc.ChangeSettings(newSettings); doc.Settings.UpdateDefaultModifications(false); } } // Import FASTA if (commandArgs.ImportingFasta) { _out.WriteLine(Resources.CommandLine_ImportFasta_Importing_FASTA_file__0____, Path.GetFileName(commandArgs.FastaPath)); doc = ImportPeptideSearch.PrepareImportFasta(doc); int emptyProteins; try { IdentityPath firstAdded, nextAdd; doc = ImportPeptideSearch.ImportFasta(doc, commandArgs.FastaPath, progressMonitor, null, out firstAdded, out nextAdd, out emptyProteins); } catch (Exception x) { _out.WriteLine(Resources.CommandLine_Run_Error__Failed_importing_the_file__0____1_, commandArgs.FastaPath, x.Message); _doc = doc; return true; // So that document will be saved with the new library } if (emptyProteins > 0 && !commandArgs.KeepEmptyProteins) { doc = ImportPeptideSearch.RemoveEmptyProteins(doc); } } // Import results _doc = doc; ImportFoundResultsFiles(commandArgs, import); return true; }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var calc = GetIrtCalculator(docCurrent); if (calc != null && !calc.IsUsable) calc = LoadCalculator(container, calc); if (calc == null || !ReferenceEquals(document.Id, container.Document.Id)) { // Loading was cancelled or document changed EndProcessing(document); return false; } var rtRegression = docCurrent.Settings.PeptideSettings.Prediction.RetentionTime; var rtRegressionNew = !ReferenceEquals(calc, rtRegression.Calculator) ? rtRegression.ChangeCalculator(calc) : rtRegression; if (rtRegressionNew.IsAutoCalcRequired(docCurrent, null)) rtRegressionNew = AutoCalcRegressions(container, rtRegressionNew); if (rtRegressionNew == null || !ReferenceEquals(document.Id, container.Document.Id) || // No change in the regression, including reference equal standard peptides (Equals(rtRegression, rtRegressionNew) && rtRegression.SamePeptides(rtRegressionNew))) { // Loading was cancelled or document changed EndProcessing(document); return false; } SrmDocument docNew; do { // Change the document to use the new calculator and regression information. docCurrent = container.Document; if (!ReferenceEquals(rtRegression, docCurrent.Settings.PeptideSettings.Prediction.RetentionTime)) return false; docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangePeptidePrediction(predict => predict.ChangeRetentionTime(rtRegressionNew))); } while (!CompleteProcessing(container, docNew, docCurrent)); return true; }
private SrmDocument ConnectLibrarySpecs(SrmDocument document, string documentPath) { string docLibFile = null; if (!string.IsNullOrEmpty(documentPath) && document.Settings.PeptideSettings.Libraries.HasDocumentLibrary) { docLibFile = BiblioSpecLiteSpec.GetLibraryFileName(documentPath); if (!File.Exists(docLibFile)) { _out.WriteLine(Resources.CommandLine_ConnectLibrarySpecs_Error__Could_not_find_the_spectral_library__0__for_this_document_, docLibFile); return null; } } var settings = document.Settings.ConnectLibrarySpecs(library => { LibrarySpec spec; if (Settings.Default.SpectralLibraryList.TryGetValue(library.Name, out spec)) { if (File.Exists(spec.FilePath)) return spec; } string fileName = library.FileNameHint; if (fileName != null) { // First look for the file name in the document directory string pathLibrary = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName); if (File.Exists(pathLibrary)) return library.CreateSpec(pathLibrary).ChangeDocumentLocal(true); // In the user's default library directory pathLibrary = Path.Combine(Settings.Default.LibraryDirectory, fileName); if (File.Exists(pathLibrary)) return library.CreateSpec(pathLibrary); } _out.WriteLine(Resources.CommandLine_ConnectLibrarySpecs_Warning__Could_not_find_the_spectral_library__0_, library.Name); return library.CreateSpec(null); }, docLibFile); if (ReferenceEquals(settings, document.Settings)) return document; // If the libraries were moved to disconnected state, then avoid updating // the document tree for this change, or it will strip all the library // information off the document nodes. if (settings.PeptideSettings.Libraries.DisconnectedLibraries != null) return document.ChangeSettingsNoDiff(settings); return document.ChangeSettings(settings); }
public void VariableModSerializeTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath path = IdentityPath.ROOT; var settings = document.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listStaticMods = new List<StaticMod>(modsDefault.StaticModifications) { VAR_MET_OXIDIZED, VAR_MET_AMONIA_ADD, VAR_ASP_WATER_ADD }; var docVarMods = document.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); var docVmYeast = docVarMods.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); Assert.AreEqual(315, GetVariableModCount(docVmYeast)); AssertEx.Serializable(docVmYeast, 3, AssertEx.DocumentCloned); }
private static void ValidateLibraryDocs(SrmDocument docTarget, SrmDocument docActual, LibraryManager libraryManager) { var docContainer = new TestDocumentContainer(); libraryManager.Register(docContainer); try { AssertEx.IsDocumentState(docActual, 0, docTarget.PeptideGroupCount, docTarget.PeptideCount, docTarget.PeptideTransitionGroupCount, docTarget.PeptideTransitionCount); docActual = docActual.ChangeSettings(docActual.Settings.ConnectLibrarySpecs(FindLibrarySpec)); Assert.IsTrue(docContainer.SetDocument(docActual, null, true)); SrmDocument docLoaded = docContainer.Document; AssertEx.DocumentCloned(docTarget, docLoaded); // Assert.IsTrue(ArrayUtil.ReferencesEqual(docActual.Transitions.ToArray(), docLoaded.Transitions.ToArray())); // Assert.IsTrue(ArrayUtil.ReferencesEqual(docActual.TransitionGroups.ToArray(), docLoaded.TransitionGroups.ToArray())); // Assert.IsTrue(ArrayUtil.ReferencesEqual(docActual.Peptides.ToArray(), docLoaded.Peptides.ToArray())); Assert.IsTrue(ArrayUtil.ReferencesEqual(docActual.Children, docLoaded.Children)); } finally { libraryManager.Unregister(docContainer); } }
protected override void DoTest() { // Set up initial document quickly, without involving UI SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); var staticMods = new List<StaticMod>(document.Settings.PeptideSettings.Modifications.StaticModifications); staticMods.AddRange(new[] { new StaticMod("Phospho", "S,T,Y", null, true, "PO3H", LabelAtoms.None, RelativeRT.Matching, null, null, new[] {new FragmentLoss("PO4H3")}), new StaticMod("K(GlyGly)", "K", null, true, "N2H6C4O2", LabelAtoms.None, RelativeRT.Matching, null, null, null), }); document = document.ChangeSettings(document.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods).ChangeMaxNeutralLosses(2))); Assert.IsTrue(SkylineWindow.SetDocument(document, SkylineWindow.Document)); RunUI(() => SkylineWindow.Paste(TRANSITIONLIST_CSV_MODLOSS_CLIPBOARD_TEXT)); var docPaste1 = WaitForDocumentChange(document); AssertEx.IsDocumentState(docPaste1, null, 3, 4, 12); // revision # is hard to predict with background loaders running Assert.AreEqual(4, GetVariableModCount(docPaste1)); Assert.AreEqual(6, GetLossCount(docPaste1, 1)); string insertListText = I18n(TRANSITIONS_MODLOSS_CLIPBOARD_TEXT); SetClipboardTextUI(insertListText); RunDlg<PasteDlg>(SkylineWindow.ShowPasteTransitionListDlg, insertTransDlg => { insertTransDlg.IsMolecule = false; // Make sure it's ready to accept peptides rather than small molecules insertTransDlg.PasteTransitions(); insertTransDlg.OkDialog(); }); WaitForProteinMetadataBackgroundLoaderCompletedUI(); // Nothing should have changed RunUI(() => Assert.AreSame(docPaste1, SkylineWindow.DocumentUI)); // Revert to the original empty document RunUI(SkylineWindow.Undo); Assert.AreSame(document, SkylineWindow.Document); RunDlg<PasteDlg>(SkylineWindow.ShowPasteTransitionListDlg, insertTransDlg => { insertTransDlg.PasteTransitions(); insertTransDlg.OkDialog(); }); var docInsert1 = WaitForDocumentChange(document); AssertEx.IsDocumentState(docInsert1, null, 3, 4, 12); // revision # is hard to predict with background loaders running Assert.AreEqual(4, GetVariableModCount(docInsert1)); Assert.AreEqual(6, GetLossCount(docInsert1, 1)); string insertPart1 = I18n(TRANSITIONS_PREC_PART1_CLIPBOARD_TEXT); string insertPart2 = I18n(TRANSITIONS_PREC_PART2_CLIPBOARD_TEXT); string insertSep = I18n(TRANSITIONS_PREC_SEP_CLIPBOARD_TEXT); RunDlg<PasteDlg>(SkylineWindow.ShowPasteTransitionListDlg, insertTransDlg => { // Check error and grid cell selection for a bad product m/z VerifyTransitionListError(insertTransDlg, insertListText, 757.420279, 888.8888, 8, 2); // Non-numeric product m/z VerifyTransitionListError(insertTransDlg, insertListText, 908.447222, "x", Resources.PasteDlg_AddTransitionList_The_product_m_z_must_be_a_number_, 1, 2); // Check error and grid cell selection for a bad precursor m/z VerifyTransitionListError(insertTransDlg, insertListText, 648.352161, 777.7777, 6, 1); // Non-numeric precursor m/z VerifyTransitionListError(insertTransDlg, insertListText, 762.033412, "x", Resources.PasteDlg_AddTransitionList_The_precursor_m_z_must_be_a_number_, 0, 1); // Empty peptide VerifyTransitionListError(insertTransDlg, insertListText, "TISQSSSLKSSSNSNK", "", Resources.PasteDlg_ListPeptideSequences_The_peptide_sequence_cannot_be_blank, 9, 0); // Bad peptide VerifyTransitionListError(insertTransDlg, insertListText, "TISQSSSLKSSSNSNK", "BBBbBBBR", Resources.PasteDlg_ListPeptideSequences_This_peptide_sequence_contains_invalid_characters, 9, 0); // No mods explain all transitions VerifyTransitionListError(insertTransDlg, insertPart1 + insertPart2, null, null, Resources.PeptideGroupBuilder_AppendTransition_Failed_to_explain_all_transitions_for_0__m_z__1__with_a_single_set_of_modifications, 3, 0, 2); // Finally a working set of transitions SetClipboardText(insertPart1 + insertSep + insertPart2); insertTransDlg.PasteTransitions(); insertTransDlg.OkDialog(); }); var docInsert2 = WaitForDocumentChange(docInsert1); AssertEx.IsDocumentState(docInsert2, null, 4, 7, 21); // revision # is hard to predict with background loaders running Assert.AreEqual(7, GetVariableModCount(docInsert2)); Assert.AreEqual(11, GetLossCount(docInsert2, 1)); }
public void VariableModImportListTest() { // TODO: Deal with multiple variable modifications that produce the same // precursor mass but different product ion masses SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); var staticMods = new List<StaticMod>(document.Settings.PeptideSettings.Modifications.StaticModifications); staticMods.AddRange(new[] { new StaticMod("Met Sulfoxide", "M", null, true, "O", LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("SOCH4") }), new StaticMod("Met Sulfone", "M", null, true, "O2", LabelAtoms.None, RelativeRT.Matching, null, null, null), new StaticMod("Phospho", "S,T,Y", null, true, "PO3H", LabelAtoms.None, RelativeRT.Matching, null, null, new[] {new FragmentLoss("PO4H3")}), new StaticMod("K(GlyGly)", "K", null, true, "N2H6C4O2", LabelAtoms.None, RelativeRT.Matching, null, null, null), }); document = document.ChangeSettings(document.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods))); IdentityPath pathTo; List<MeasuredRetentionTime> irtPeptides; List<SpectrumMzInfo> librarySpectra; List<TransitionImportErrorInfo> errorList; var inputsPhospho = new MassListInputs(TEXT_PHOSPHO_TRANSITION_LIST, CultureInfo.InvariantCulture, TextUtil.SEPARATOR_CSV); document.ImportMassList(inputsPhospho, null, out pathTo, out irtPeptides, out librarySpectra, out errorList); Assert.AreEqual(27, errorList.Count); AssertEx.AreComparableStrings(TextUtil.SpaceSeparate(Resources.MassListRowReader_CalcTransitionExplanations_The_product_m_z__0__is_out_of_range_for_the_instrument_settings__in_the_peptide_sequence__1_, Resources.MassListRowReader_CalcPrecursorExplanations_Check_the_Instrument_tab_in_the_Transition_Settings), errorList[0].ErrorMessage, 2); Assert.AreEqual(1, errorList[0].Column); Assert.AreEqual(40, errorList[0].Row); var docHighMax = document.ChangeSettings(document.Settings.ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); var docList = docHighMax.ImportMassList(inputsPhospho, null, out pathTo); AssertEx.Serializable(docList); AssertEx.IsDocumentState(docList, 3, 68, 134, 157, 481); foreach (var nodeTran in docList.PeptideTransitions) { var it = nodeTran.Transition.IonType; Assert.IsTrue(it == IonType.y || it == IonType.b || it == IonType.precursor, "Found unexpected non b, y or precursor ion type."); } var inputsMultiLoss = new MassListInputs(TEXT_PHOSPHO_MULTI_LOSS, CultureInfo.InvariantCulture, TextUtil.SEPARATOR_CSV); docHighMax.ImportMassList(inputsMultiLoss, null, out pathTo, out irtPeptides, out librarySpectra, out errorList); Assert.AreEqual(5, errorList.Count); AssertEx.AreComparableStrings(Resources.MassListRowReader_CalcTransitionExplanations_Product_m_z_value__0__in_peptide__1__has_no_matching_product_ion, errorList[0].ErrorMessage, 2); Assert.AreEqual(1, errorList[0].Column); Assert.AreEqual(2, errorList[0].Row); var docMultiLos = docHighMax.ChangeSettings(docHighMax.Settings.ChangePeptideModifications(mods => mods.ChangeMaxNeutralLosses(2))); docList = docMultiLos.ImportMassList(inputsMultiLoss, null, out pathTo); AssertEx.IsDocumentState(docList, 4, 4, 4, 12); }
/// <summary> /// Changes collision energy and declustering potential settings to their /// default values for an instrument type. /// </summary> /// <param name="document">Document to change</param> /// <param name="ceNameDefault">Default name for CE</param> /// <param name="dpNameDefault">Default name for DP</param> private static SrmDocument ChangeInstrumentTypeSettings(SrmDocument document, string ceNameDefault, string dpNameDefault) { var ceList = Settings.Default.CollisionEnergyList; CollisionEnergyRegression ce; if (!ceList.TryGetValue(ceNameDefault, out ce)) { foreach (var ceDefault in ceList.GetDefaults()) { if (ceDefault.Name.StartsWith(ceNameDefault)) ce = ceDefault; } } var dpList = Settings.Default.DeclusterPotentialList; DeclusteringPotentialRegression dp = null; if (dpNameDefault != null && !dpList.TryGetValue(dpNameDefault, out dp)) { foreach (var dpDefault in dpList.GetDefaults()) { if (dpDefault.Name.StartsWith(dpNameDefault)) dp = dpDefault; } } return document.ChangeSettings(document.Settings.ChangeTransitionPrediction( predict => { if (ce != null) predict = predict.ChangeCollisionEnergy(ce); if (dp != null) predict = predict.ChangeDeclusteringPotential(dp); return predict; })); }
private SrmDocument EnsureAnnotation(SrmDocument document, string annotationName, bool addAnnotation, IEnumerable<string> annotationNames) { var containsQAnnotation = annotationNames.Contains(annotationName); if (!containsQAnnotation && addAnnotation) { var annotationTargets = AnnotationDef.AnnotationTargetSet.OfValues(AnnotationDef.AnnotationTarget.precursor_result); var newAnnotationDef = new AnnotationDef(annotationName, annotationTargets, AnnotationDef.AnnotationType.number, new string[0]); AnnotationDef existingAnnotationDef; // CONSIDER: Throw error instead of overwriting? if (!Settings.Default.AnnotationDefList.TryGetValue(annotationName, out existingAnnotationDef) && !Equals(existingAnnotationDef, newAnnotationDef)) { Settings.Default.AnnotationDefList.SetValue(newAnnotationDef); } else { // Use the existing annotation newAnnotationDef = existingAnnotationDef; } document = document.ChangeSettings(Document.Settings.ChangeAnnotationDefs(defs => { var defsNew = defs.ToList(); defsNew.Add(newAnnotationDef); return defsNew; })); } else if (containsQAnnotation && !AddAnnotation) { document = document.ChangeSettings(Document.Settings.ChangeAnnotationDefs(defs => { var defsNew = defs.ToList(); defsNew.RemoveAll(def => Equals(def.Name, annotationName)); return defsNew; })); var annotationNamesToKeep = document.Settings.DataSettings.AnnotationDefs.Select(def => def.Name).ToList(); document = (SrmDocument) document.StripAnnotationValues(annotationNamesToKeep); } return document; }
public void TestPaste() { ClearDefaultModifications(); _yeastDoc = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMaxMz(1600))); _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new MeasuredIon[0]))); IdentityPath path; _yeastDocReadOnly = _yeastDoc = _yeastDoc.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST_LIB), false, IdentityPath.ROOT, out path); _study7DocReadOnly = _study7Doc = CreateStudy7Doc(); IdentityPath pathRoot = IdentityPath.ROOT; // Test pasting into document with same implicit modifications does not create any extra explicit modifications. var study7EmptyDoc = (SrmDocument) _study7Doc.ChangeChildren(new DocNode[0]); var study7PasteDoc = CopyPaste(_study7Doc, null, study7EmptyDoc, pathRoot); var arrayPeptides = _study7Doc.Peptides.ToArray(); var arrayPastePeptides = study7PasteDoc.Peptides.ToArray(); Assert.AreEqual(arrayPeptides.Length, arrayPastePeptides.Length); AssertEx.DocsEqual(_study7Doc, study7PasteDoc); // DocsEqual gives a more verbose failure message using XML output // Test implicit mods in source document become explicit mods in target document. ResetDocuments(); _yeastDoc = (SrmDocument) _yeastDoc.ChangeChildren(new DocNode[0]); var settings = _yeastDoc.Settings; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(new StaticMod[0]))); _yeastDoc = CopyPaste(_study7Doc, null, _yeastDoc, pathRoot); var pepMods = _yeastDoc.Settings.PeptideSettings.Modifications; Assert.IsTrue(pepMods.StaticModifications != null); Assert.IsTrue(pepMods.HasHeavyModifications); Assert.IsFalse(pepMods.StaticModifications.Contains(mod => !mod.IsExplicit)); Assert.IsFalse(pepMods.HeavyModifications.Contains(mod => !mod.IsExplicit)); // Test explicit mods are dropped if the target document has matching implicit modifications. study7PasteDoc = CopyPaste(_yeastDoc, null, study7EmptyDoc, pathRoot); Assert.AreEqual(_study7Doc, study7PasteDoc); // Add new label type to source document. ResetDocuments(); const string labelTypeName13C = "heavy 13C"; var labelType13C = new IsotopeLabelType(labelTypeName13C, IsotopeLabelType.light.SortOrder + 1); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] {new TypedModifications(labelType13C, HEAVY_MODS_13_C)}); Assert.IsTrue(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => Equals(nodeGroup.TransitionGroup.LabelType, labelType13C))); // Test pasting into the same document with new label type. _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); // Check all transition have correct label type references. Assert.IsFalse(_yeastDoc.PeptideTransitionGroups.Contains(nodeGroup => { IsotopeLabelType labelType = nodeGroup.TransitionGroup.LabelType; return !ReferenceEquals(labelType, _yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelType.Name).LabelType); })); // Check new document still serializes correctly. AssertEx.Serializable(_yeastDoc, AssertEx.DocumentCloned); // Test pasting into new document drops label types from source document that are not found in the target document. _yeastDoc = CopyPaste(_yeastDoc, null, new SrmDocument(SrmSettingsList.GetDefault()), pathRoot); Assert.IsNull(_yeastDoc.Settings.PeptideSettings.Modifications.GetModificationsByName(labelTypeName13C)); // If only specific children are selected, test that only these children get copied. ResetDocuments(); var arrayTrans = _study7Doc.PeptideTransitions.ToArray(); IList<DocNode> selNodes = new List<DocNode>(); for (int i = 0; i < arrayTrans.Length; i += 2) { selNodes.Add(arrayTrans[i]); } _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); Assert.AreEqual(arrayTrans.Length + selNodes.Count, _study7Doc.PeptideTransitionCount); // Test after pasting to a peptide list, all children have been updated to point to the correct parent. ResetDocuments(); _study7Doc = CopyPaste(_yeastDoc, new[] { _yeastDoc.Peptides.ToArray()[0] }, _study7Doc, _study7Doc.GetPathTo((int) SrmDocument.Level.MoleculeGroups, 0)); Assert.AreEqual(_yeastDoc.Peptides.ToArray()[0].Peptide, _study7Doc.Peptides.ToArray()[0].Peptide); Assert.AreEqual(_study7Doc.Peptides.ToArray()[0].Peptide, _study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup.Peptide); Assert.AreEqual(_study7Doc.PeptideTransitionGroups.ToArray()[0].TransitionGroup, _study7Doc.PeptideTransitions.ToArray()[0].Transition.Group); // If only specific transition are selected for a peptide, but all transition groups are included, test AutoManageChildren is true. ResetDocuments(); selNodes = new List<DocNode>(); foreach (TransitionGroupDocNode transGroup in _study7Doc.PeptideTransitionGroups) { selNodes.Add(transGroup.Children[0]); } // TODO: Fix this and make it pass // var emptyDoc = (SrmDocument)_study7Doc.ChangeChildren(new List<DocNode>()); // _study7Doc = CopyPaste(_study7Doc, selNodes, emptyDoc, pathRoot); _study7Doc = (SrmDocument)_study7Doc.ChangeChildren(new List<DocNode>()); _study7Doc = CopyPaste(_study7Doc, selNodes, _study7Doc, pathRoot); foreach (PeptideDocNode peptide in _study7Doc.Peptides) Assert.IsTrue(peptide.AutoManageChildren); // Test pasting in modifications with the same name as but different definition from existing modifications not allowed. ResetDocuments(); _yeastDoc = ChangePeptideModifications(_yeastDoc, new[] { new TypedModifications(IsotopeLabelType.heavy, HEAVY_C_K_DIFDEF) }); SetDefaultModifications(_study7Doc); AssertEx.ThrowsException<Exception>(() => _yeastDoc.Settings.UpdateDefaultModifications(false)); // Test variable modifications kept if target document has matching variable modifications turned on. ResetDocuments(); settings = _yeastDoc.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listVariableMods = new List<StaticMod>(modsDefault.StaticModifications) { VAR_MET_OXIDIZED }; _yeastDoc = _yeastDoc.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listVariableMods.ToArray()))); // Make sure there is an implicitly modified peptide in the yeast document Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.Peptide.Sequence.Contains("C"))); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); _yeastDoc = CopyPaste(_yeastDoc, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods && !nodePep.HasVariableMods)); // Otherwise the variable modifications become only explicit modifications. var yeastDocVar = _yeastDoc; _yeastDoc = _yeastDoc.ChangeSettings(_yeastDoc.Settings.ChangePeptideModifications(mods => modsDefault)); _yeastDoc = CopyPaste(yeastDocVar, null, _yeastDoc, pathRoot); Assert.IsFalse(_yeastDoc.Settings.PeptideSettings.Modifications.HasVariableModifications); Assert.IsTrue(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasExplicitMods)); Assert.IsFalse(_yeastDoc.Peptides.Contains(nodePep => nodePep.HasVariableMods)); }
private static SrmDocument ChangePeptideModifications(SrmDocument doc, IList<TypedModifications> typedHeavyMods) { var settingsNew = doc.Settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, typedHeavyMods)); return doc.ChangeSettings(settingsNew); }
private static SrmDocument CreateLibraryDocument(SrmSettings settings, string textFasta, bool peptideList, TestDocumentContainer docContainer, BackgroundLoader libraryManager, out int startRev) { startRev = 0; SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); Assert.IsTrue(docContainer.SetDocument(document, null)); // Register after first set document libraryManager.Register(docContainer); // Add libraries SrmDocument docLibraries = document.ChangeSettings(settings); ++startRev; // Add some FASTA IdentityPath path = IdentityPath.ROOT; SrmDocument docFasta = docLibraries.ImportFasta(new StringReader(textFasta), peptideList, path, out path); ++startRev; // Until libraries are loaded, only the sequences should appear if (!peptideList) AssertEx.IsDocumentState(docFasta, startRev, textFasta.Count(c => c == '>'), 0, 0); // Run the library load Assert.IsTrue(docContainer.SetDocument(docFasta, document, true)); ++startRev; // After library load completes peptides and transitions should have expected library info SrmDocument docLoaded = docContainer.Document; // Check expected library inforamation foreach (var nodePeptide in docLoaded.Peptides) Assert.IsNull(nodePeptide.Rank); foreach (var nodeTran in docLoaded.PeptideTransitions) { Assert.IsTrue(nodeTran.HasLibInfo); Assert.IsTrue(nodeTran.LibInfo.Rank <= 3); } return docLoaded; }
public SrmDocument ConvertToSmallMolecules(SrmDocument document, ConvertToSmallMoleculesMode mode = ConvertToSmallMoleculesMode.formulas, bool invertCharges = false, bool ignoreDecoys=false) { if (mode == ConvertToSmallMoleculesMode.none) return document; var newdoc = new SrmDocument(document.Settings); var note = new Annotations(TestingConvertedFromProteomic, null, 1); // Mark this as a testing node so we don't sort it newdoc = (SrmDocument)newdoc.ChangeIgnoreChangingChildren(true); // Retain copied results foreach (var peptideGroupDocNode in document.MoleculeGroups) { if (!peptideGroupDocNode.IsProteomic) { newdoc = (SrmDocument)newdoc.Add(peptideGroupDocNode); // Already a small molecule } else { var newPeptideGroup = new PeptideGroup(); var newPeptideGroupDocNode = new PeptideGroupDocNode(newPeptideGroup, peptideGroupDocNode.Annotations.Merge(note), peptideGroupDocNode.Name, peptideGroupDocNode.Description, new PeptideDocNode[0], peptideGroupDocNode.AutoManageChildren); foreach (var mol in peptideGroupDocNode.Molecules) { var peptideSequence = mol.Peptide.Sequence; // Create a PeptideDocNode with the presumably baseline charge and label var precursorCharge = (mol.TransitionGroups.Any() ? mol.TransitionGroups.First().TransitionGroup.PrecursorCharge : 0) * (invertCharges ? -1 : 1); var isotopeLabelType = mol.TransitionGroups.Any() ? mol.TransitionGroups.First().TransitionGroup.LabelType : IsotopeLabelType.light; var moleculeCustomIon = ConvertToSmallMolecule(mode, document, mol, precursorCharge, isotopeLabelType); var precursorCustomIon = moleculeCustomIon; var newPeptide = new Peptide(moleculeCustomIon); var newPeptideDocNode = new PeptideDocNode(newPeptide, newdoc.Settings, null, null, null, null, mol.ExplicitRetentionTime, note, mol.Results, new TransitionGroupDocNode[0], mol.AutoManageChildren); foreach (var transitionGroupDocNode in mol.TransitionGroups) { if (transitionGroupDocNode.IsDecoy) { if (ignoreDecoys) continue; throw new Exception("There is no translation from decoy to small molecules"); // Not L10N } if (transitionGroupDocNode.TransitionGroup.PrecursorCharge != Math.Abs(precursorCharge) || !Equals(isotopeLabelType, transitionGroupDocNode.TransitionGroup.LabelType)) { // Different charges or labels mean different ion formulas precursorCharge = transitionGroupDocNode.TransitionGroup.PrecursorCharge * (invertCharges ? -1 : 1); isotopeLabelType = transitionGroupDocNode.TransitionGroup.LabelType; precursorCustomIon = ConvertToSmallMolecule(mode, document, mol, precursorCharge, isotopeLabelType); } var newTransitionGroup = new TransitionGroup(newPeptide, precursorCustomIon, precursorCharge, isotopeLabelType); // Remove any library info, since for the moment at least small molecules don't support this and it won't roundtrip var resultsNew = RemoveTransitionGroupChromInfoLibraryInfo(transitionGroupDocNode); var newTransitionGroupDocNode = new TransitionGroupDocNode(newTransitionGroup, transitionGroupDocNode.Annotations.Merge(note), document.Settings, null, null, transitionGroupDocNode.ExplicitValues, resultsNew, null, transitionGroupDocNode.AutoManageChildren); var mzShift = invertCharges ? 2.0 * BioMassCalc.MassProton : 0; // We removed hydrogen rather than added Assume.IsTrue((Math.Abs(newTransitionGroupDocNode.PrecursorMz + mzShift - transitionGroupDocNode.PrecursorMz) - Math.Abs(transitionGroupDocNode.TransitionGroup.PrecursorCharge * BioMassCalc.MassElectron)) <= 1E-5); foreach (var transition in transitionGroupDocNode.Transitions) { double mass = 0; var transitionCharge = transition.Transition.Charge * (invertCharges ? -1 : 1); var ionType = IonType.custom; CustomIon transitionCustomIon; double mzShiftTransition = 0; if (transition.Transition.IonType == IonType.precursor) { ionType = IonType.precursor; transitionCustomIon = new DocNodeCustomIon(precursorCustomIon.Formula, string.IsNullOrEmpty(precursorCustomIon.Formula) ? precursorCustomIon.MonoisotopicMass : (double?) null, string.IsNullOrEmpty(precursorCustomIon.Formula) ? precursorCustomIon.AverageMass : (double?) null, SmallMoleculeNameFromPeptide(peptideSequence, transitionCharge)); mzShiftTransition = invertCharges ? 2.0 * BioMassCalc.MassProton : 0; // We removed hydrogen rather than added } else if (transition.Transition.IonType == IonType.custom) { transitionCustomIon = transition.Transition.CustomIon; mass = transitionCustomIon.MonoisotopicMass; } else { // TODO - try to get fragment formula? mass = BioMassCalc.CalculateIonMassFromMz(transition.Mz, transition.Transition.Charge); transitionCustomIon = new DocNodeCustomIon(mass, mass,// We can't really get at mono vs average mass from m/z, but for test purposes this is fine transition.Transition.FragmentIonName); } if (mode == ConvertToSmallMoleculesMode.masses_and_names) { // Discard the formula if we're testing the use of mass-with-names (for matching in ratio calcs) target specification transitionCustomIon = new DocNodeCustomIon(transitionCustomIon.MonoisotopicMass, transitionCustomIon.AverageMass, transition.Transition.FragmentIonName); } else if (mode == ConvertToSmallMoleculesMode.masses_only) { // Discard the formula and name if we're testing the use of mass-only target specification transitionCustomIon = new DocNodeCustomIon(transitionCustomIon.MonoisotopicMass, transitionCustomIon.AverageMass); } var newTransition = new Transition(newTransitionGroup, ionType, null, transition.Transition.MassIndex, transition.Transition.Charge * (invertCharges ? -1 : 1), null, transitionCustomIon); if (ionType == IonType.precursor) { mass = document.Settings.GetFragmentMass(transitionGroupDocNode.TransitionGroup.LabelType, null, newTransition, newTransitionGroupDocNode.IsotopeDist); } var newTransitionDocNode = new TransitionDocNode(newTransition, transition.Annotations.Merge(note), null, mass, transition.IsotopeDistInfo, null, transition.Results); Assume.IsTrue((Math.Abs(newTransitionDocNode.Mz + mzShiftTransition - transition.Mz) - Math.Abs(transitionGroupDocNode.TransitionGroup.PrecursorCharge * BioMassCalc.MassElectron)) <= 1E-5, String.Format("unexpected mz difference {0}-{1}={2}", newTransitionDocNode.Mz , transition.Mz, newTransitionDocNode.Mz - transition.Mz)); // Not L10N newTransitionGroupDocNode = (TransitionGroupDocNode)newTransitionGroupDocNode.Add(newTransitionDocNode); } if (newPeptideDocNode != null) newPeptideDocNode = (PeptideDocNode)newPeptideDocNode.Add(newTransitionGroupDocNode); } newPeptideGroupDocNode = (PeptideGroupDocNode)newPeptideGroupDocNode.Add(newPeptideDocNode); } newdoc = (SrmDocument)newdoc.Add(newPeptideGroupDocNode); } } // No retention time prediction for small molecules (yet?) newdoc = newdoc.ChangeSettings(newdoc.Settings.ChangePeptideSettings(newdoc.Settings.PeptideSettings.ChangePrediction( newdoc.Settings.PeptideSettings.Prediction.ChangeRetentionTime(null)))); return newdoc; }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var ionMobilityLibrary = GetIonMobilityLibrary(docCurrent); if (ionMobilityLibrary != null && !ionMobilityLibrary.IsUsable) ionMobilityLibrary = LoadIonMobilityLibrary(container, ionMobilityLibrary); if (ionMobilityLibrary == null || !ReferenceEquals(document.Id, container.Document.Id)) { // Loading was cancelled or document changed EndProcessing(document); return false; } var dtPredictor = docCurrent.Settings.PeptideSettings.Prediction.DriftTimePredictor; var dtPredictorNew = !ReferenceEquals(ionMobilityLibrary, dtPredictor.IonMobilityLibrary) ? dtPredictor.ChangeLibrary(ionMobilityLibrary) : dtPredictor; if (dtPredictorNew == null || !ReferenceEquals(document.Id, container.Document.Id) || (Equals(dtPredictor, dtPredictorNew))) { // Loading was cancelled or document changed EndProcessing(document); return false; } SrmDocument docNew; do { // Change the document to use the new predictor. docCurrent = container.Document; if (!ReferenceEquals(dtPredictor, docCurrent.Settings.PeptideSettings.Prediction.DriftTimePredictor)) return false; docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangePeptidePrediction(predictor => predictor.ChangeDriftTimePredictor(dtPredictorNew))); } while (!CompleteProcessing(container, docNew, docCurrent)); return true; }
private static SrmDocument ChangeBackgroundProteome(SrmDocument document, BackgroundProteome backgroundProteome) { return document.ChangeSettings( document.Settings.ChangePeptideSettings(setP => setP.ChangeBackgroundProteome(backgroundProteome))); }
public void VariableModBasicTest() { SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault0_6()); // Make sure default document produces no variable modifications IdentityPath path = IdentityPath.ROOT; var docYeast = document.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); Assert.AreEqual(0, GetVariableModCount(docYeast)); // Add a single variable modification var settings = document.Settings; var modsDefault = settings.PeptideSettings.Modifications; var listStaticMods = new List<StaticMod>(modsDefault.StaticModifications) {VAR_MET_OXIDIZED}; var docMetOxidized = document.ChangeSettings(settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); // Make sure variable modifications are added as expected to imported FASTA path = IdentityPath.ROOT; var docMoYeast = docMetOxidized.ImportFasta(new StringReader(ExampleText.TEXT_FASTA_YEAST), false, path, out path); Assert.AreEqual(21, GetVariableModCount(docMoYeast)); AssertEx.IsDocumentState(docMoYeast, 2, 2, 119, 374); // Exclude unmodified peptides var docNoMoExclude = docMoYeast.ChangeSettings(docMoYeast.Settings.ChangePeptideFilter(f => f.ChangeExclusions(new[] { new PeptideExcludeRegex("Non-Oxidized Meth", "M\\[", true, true) }))); Assert.AreEqual(GetVariableModCount(docMoYeast), GetVariableModCount(docNoMoExclude)); Assert.AreEqual(docNoMoExclude.PeptideCount, GetVariableModCount(docNoMoExclude)); AssertEx.IsDocumentState(docNoMoExclude, 3, 2, 21, 63); // Exclude multiply modified peptides var docMultMoExclude = docNoMoExclude.ChangeSettings(docNoMoExclude.Settings.ChangePeptideFilter(f => f.ChangeExclusions(new List<PeptideExcludeRegex>(f.Exclusions) { new PeptideExcludeRegex("Multi-Oxidized Meth", "M\\[.*M\\[", false, true) }))); Assert.AreEqual(docMultMoExclude.PeptideCount, GetVariableModCount(docMultMoExclude)); AssertEx.IsDocumentState(docMultMoExclude, 4, 2, 18, 56); // And that removing the variable modification removes the variably modifide peptides var docYeast2 = docMoYeast.ChangeSettings(docMoYeast.Settings.ChangePeptideModifications(mods => modsDefault)); Assert.AreEqual(0, GetVariableModCount(docYeast2)); Assert.AreEqual(docYeast, docYeast2); Assert.AreNotSame(docYeast, docYeast2); // Even when automanage children is turned off var docNoAuto = (SrmDocument)docMoYeast.ChangeChildren((from node in docYeast2.MoleculeGroups select node.ChangeAutoManageChildren(false)).ToArray()); var docYeastNoAuto = docNoAuto.ChangeSettings(docYeast.Settings); Assert.AreEqual(0, GetVariableModCount(docYeastNoAuto)); // Shouldn't come back, if the mods are restored var docMoNoAuto = docYeastNoAuto.ChangeSettings(docMetOxidized.Settings); Assert.AreEqual(0, GetVariableModCount(docMoNoAuto)); Assert.AreSame(docYeastNoAuto.Children, docMoNoAuto.Children); // Make sure loss modification result in smaller m/z values var listModsLoss = new List<StaticMod>(modsDefault.StaticModifications) { VAR_ASP_WATER_LOSS }; var docAspLoss = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listModsLoss.ToArray()))); Assert.AreEqual(145, GetVariableModCount(docAspLoss)); VerifyModificationOrder(docAspLoss, false); // Add multiple variable modifications listStaticMods.Add(VAR_ASP_WATER_ADD); var docVarMulti = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); Assert.AreEqual(220, GetVariableModCount(docVarMulti)); int maxModifiableMulti = GetMaxModifiableCount(docVarMulti); Assert.IsTrue(maxModifiableMulti > GetMaxModifiedCount(docVarMulti)); VerifyModificationOrder(docVarMulti, true); // Repeat with a single variable modification on multiple amino acids // and verify that this creates the same number of variably modified peptides var listModsMultiAA = new List<StaticMod>(modsDefault.StaticModifications) { VAR_MET_ASP_OXIDIZED }; var docVarMultiAA = docYeast2.ChangeSettings(docYeast2.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listModsMultiAA.ToArray()))); Assert.AreEqual(220, GetVariableModCount(docVarMultiAA)); VerifyModificationOrder(docVarMultiAA, true); // And also multiple modifications on the same amino acid residue listStaticMods.Add(VAR_MET_AMONIA_ADD); var docVarAaMulti = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(listStaticMods.ToArray()))); Assert.AreEqual(315, GetVariableModCount(docVarAaMulti)); int maxModifiableAaMulti = GetMaxModifiableCount(docVarAaMulti); Assert.AreEqual(maxModifiableMulti, maxModifiableAaMulti, "Unexptected change in the maximum number of modifiable amino acids"); Assert.IsTrue(maxModifiableAaMulti > GetMaxModifiedCount(docVarAaMulti)); VerifyModificationOrder(docVarAaMulti, true); // Reduce the maximum number of variable modifications allowed var docVar2AaMulti = docVarAaMulti.ChangeSettings(docVarAaMulti.Settings.ChangePeptideModifications(mods => mods.ChangeMaxVariableMods(2))); Assert.AreEqual(242, GetVariableModCount(docVar2AaMulti)); Assert.AreEqual(2, GetMaxModifiedCount(docVar2AaMulti)); VerifyModificationOrder(docVar2AaMulti, true); var docVar1AaMulti = docVar2AaMulti.ChangeSettings(docVar2AaMulti.Settings.ChangePeptideModifications(mods => mods.ChangeMaxVariableMods(1))); Assert.AreEqual(128, GetVariableModCount(docVar1AaMulti)); Assert.AreEqual(1, GetMaxModifiedCount(docVar1AaMulti)); VerifyModificationOrder(docVar1AaMulti, true); var docVarAaMultiReset = docVar1AaMulti.ChangeSettings(docVarAaMulti.Settings); Assert.AreEqual(315, GetVariableModCount(docVarAaMultiReset)); // Repeat with auto-manage turned off to make sure it also removes // variable modifications which are made invalide by changing the limit var docMultiNoAuto = (SrmDocument)docVarAaMulti.ChangeChildren((from node in docVarAaMulti.MoleculeGroups select node.ChangeAutoManageChildren(false)).ToArray()); var docMulti2NoAuto = docMultiNoAuto.ChangeSettings(docVar2AaMulti.Settings); Assert.IsTrue(ArrayUtil.ReferencesEqual(docVar2AaMulti.Molecules.ToArray(), docMulti2NoAuto.Molecules.ToArray())); var docMulti1NoAuto = docMulti2NoAuto.ChangeSettings(docVar1AaMulti.Settings); Assert.IsTrue(ArrayUtil.ReferencesEqual(docVar1AaMulti.Molecules.ToArray(), docMulti1NoAuto.Molecules.ToArray())); var docMultiNoAutoReset = docMulti1NoAuto.ChangeSettings(docVarAaMulti.Settings); Assert.AreSame(docMulti1NoAuto.Children, docMultiNoAutoReset.Children); // Add heavy modifications to an earlier document to verify // that heavy precursors all get greater precursor m/z values than // their light versions var docVarHeavy = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications( mods => mods.ChangeHeavyModifications(HEAVY_MODS))); foreach (var nodePep in docVarHeavy.Peptides) { if (nodePep.Peptide.NextAA == '-') continue; Assert.AreEqual(2, nodePep.Children.Count); Assert.AreEqual(GetPrecursorMz(nodePep, 0), GetPrecursorMz(nodePep, 1)-3, 0.02); } // Repeat with a modification specifying multiple amino acids // and make sure the resulting m/z values are the same var docVarHeavyMulti = docVarMulti.ChangeSettings(docVarMulti.Settings.ChangePeptideModifications( mods => mods.ChangeHeavyModifications(HEAVY_MODS_MULTI))); var varHeavyGroups = docVarHeavy.PeptideTransitionGroups.ToArray(); var varHeavyMultiPeptides = docVarHeavyMulti.PeptideTransitionGroups.ToArray(); Assert.AreEqual(varHeavyGroups.Length, varHeavyMultiPeptides.Length); for (int i = 0; i < varHeavyGroups.Length; i++) Assert.AreEqual(varHeavyGroups[i].PrecursorMz, varHeavyMultiPeptides[i].PrecursorMz); }
private static SrmDocument CheckTranstions(SrmDocument document, string startName, string endName, int ionDiff) { SrmSettings settings = document.Settings; SrmDocument docNew = document.ChangeSettings(settings.ChangeTransitionFilter( f => f.ChangeFragmentRangeFirstName(startName). ChangeFragmentRangeLastName(endName)). ChangeTransitionInstrument(i => i.ChangeMaxMz(5000))); // length-n ions foreach (PeptideDocNode nodePeptide in docNew.Peptides) { Assert.AreEqual(Math.Max(0, nodePeptide.Peptide.Sequence.Length - ionDiff), nodePeptide.TransitionCount); } return docNew; }
private static SrmDocument InitWiffDocument(TestFilesDir testFilesDir) { const LabelAtoms labelAtoms = LabelAtoms.C13 | LabelAtoms.N15; List<StaticMod> heavyMods = new List<StaticMod> { new StaticMod("Heavy K", "K", ModTerminus.C, null, labelAtoms, null, null), new StaticMod("Heavy R", "R", ModTerminus.C, null, labelAtoms, null, null), }; SrmSettings settings = SrmSettingsList.GetDefault(); settings = settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications(heavyMods)); SrmDocument doc = new SrmDocument(settings); IdentityPath selectPath; string path = testFilesDir.GetTestPath("051309_transition list.csv"); // Product m/z out of range var docError = doc; List<MeasuredRetentionTime> irtPeptides; List<SpectrumMzInfo> librarySpectra; List<TransitionImportErrorInfo> errorList; var inputs = new MassListInputs(path) { FormatProvider = CultureInfo.InvariantCulture, Separator = TextUtil.SEPARATOR_CSV }; docError.ImportMassList(inputs, null, out selectPath, out irtPeptides, out librarySpectra, out errorList); Assert.AreEqual(errorList.Count, 1); AssertEx.AreComparableStrings(TextUtil.SpaceSeparate(Resources.MassListRowReader_CalcTransitionExplanations_The_product_m_z__0__is_out_of_range_for_the_instrument_settings__in_the_peptide_sequence__1_, Resources.MassListRowReader_CalcPrecursorExplanations_Check_the_Instrument_tab_in_the_Transition_Settings), errorList[0].ErrorMessage, 2); Assert.AreEqual(errorList[0].Column, 1); Assert.AreEqual(errorList[0].Row, 19); doc = doc.ChangeSettings(settings.ChangeTransitionInstrument(inst => inst.ChangeMaxMz(1800))); inputs = new MassListInputs(path) { FormatProvider = CultureInfo.InvariantCulture, Separator = TextUtil.SEPARATOR_CSV }; doc = doc.ImportMassList(inputs, null, out selectPath); AssertEx.IsDocumentState(doc, 2, 9, 9, 18, 54); return doc; }
protected override bool LoadBackground(IDocumentContainer container, SrmDocument document, SrmDocument docCurrent) { var lib = GetOptimizationLibrary(docCurrent); if (lib != null && !lib.IsNone && !lib.IsUsable) lib = LoadLibrary(container, lib); if (lib == null || !ReferenceEquals(document.Id, container.Document.Id)) { // Loading was cancelled or document changed EndProcessing(document); return false; } SrmDocument docNew; do { // Change the document to use the new library docCurrent = container.Document; if (!ReferenceEquals(GetOptimizationLibrary(docCurrent), GetOptimizationLibrary(container.Document))) return false; docNew = docCurrent.ChangeSettings(docCurrent.Settings.ChangeTransitionPrediction(predict => predict.ChangeOptimizationLibrary(lib))); } while (!CompleteProcessing(container, docNew, docCurrent)); return true; }
public static OptimizationDb ConvertFromOldFormat(string path, IProgressMonitor loadMonitor, ProgressStatus status, SrmDocument document) { // Try to open assuming old format (Id, PeptideModSeq, Charge, Mz, Value, Type) var precursors = new Dictionary<string, HashSet<int>>(); // PeptideModSeq -> charges var optimizations = new List<Tuple<DbOptimization, double>>(); // DbOptimization, product m/z int maxCharge = 1; using (SQLiteConnection connection = new SQLiteConnection("Data Source = " + path)) // Not L10N using (SQLiteCommand command = new SQLiteCommand(connection)) { connection.Open(); command.CommandText = "SELECT PeptideModSeq, Charge, Mz, Value, Type FROM OptimizationLibrary"; // Not L10N using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var type = (OptimizationType)reader["Type"]; // Not L10N var modifiedSequence = reader["PeptideModSeq"].ToString(); // Not L10N var charge = (int)reader["Charge"]; // Not L10N var productMz = (double)reader["Mz"]; // Not L10N var value = (double)reader["Value"]; // Not L10N optimizations.Add(new Tuple<DbOptimization, double>(new DbOptimization(type, modifiedSequence, charge, string.Empty, -1, value), productMz)); if (!precursors.ContainsKey(modifiedSequence)) { precursors[modifiedSequence] = new HashSet<int>(); } precursors[modifiedSequence].Add(charge); if (charge > maxCharge) { maxCharge = charge; } } } } var peptideList = (from precursor in precursors from charge in precursor.Value select string.Format("{0}{1}", precursor.Key, Transition.GetChargeIndicator(charge)) // Not L10N ).ToList(); var newDoc = new SrmDocument(document != null ? document.Settings : SrmSettingsList.GetDefault()); newDoc = newDoc.ChangeSettings(newDoc.Settings .ChangePeptideLibraries(libs => libs.ChangePick(PeptidePick.filter)) .ChangeTransitionFilter(filter => filter.ChangeFragmentRangeFirstName("ion 1") // Not L10N .ChangeFragmentRangeLastName("last ion") // Not L10N .ChangeProductCharges(Enumerable.Range(1, maxCharge).ToList()) .ChangeIonTypes(new []{ IonType.y, IonType.b })) .ChangeTransitionLibraries(libs => libs.ChangePick(TransitionLibraryPick.none)) ); var matcher = new ModificationMatcher { FormatProvider = NumberFormatInfo.InvariantInfo }; matcher.CreateMatches(newDoc.Settings, peptideList, Settings.Default.StaticModList, Settings.Default.HeavyModList); FastaImporter importer = new FastaImporter(newDoc, matcher); string text = string.Format(">>{0}\r\n{1}", newDoc.GetPeptideGroupId(true), TextUtil.LineSeparate(peptideList)); // Not L10N PeptideGroupDocNode imported = importer.Import(new StringReader(text), null, Helpers.CountLinesInString(text)).First(); int optimizationsUpdated = 0; foreach (PeptideDocNode nodePep in imported.Children) { string sequence = newDoc.Settings.GetSourceTextId(nodePep); foreach (var nodeGroup in nodePep.TransitionGroups) { int charge = nodeGroup.PrecursorCharge; foreach (var nodeTran in nodeGroup.Transitions) { double productMz = nodeTran.Mz; foreach (var optimization in optimizations.Where(opt => string.IsNullOrEmpty(opt.Item1.FragmentIon) && opt.Item1.ProductCharge == -1 && opt.Item1.PeptideModSeq == sequence && opt.Item1.Charge == charge && Math.Abs(opt.Item2 - productMz) < 0.00001)) { optimization.Item1.FragmentIon = nodeTran.FragmentIonName; optimization.Item1.ProductCharge = nodeTran.Transition.Charge; ++optimizationsUpdated; } } } } if (optimizations.Count > optimizationsUpdated) { throw new OptimizationsOpeningException(string.Format(Resources.OptimizationDb_ConvertFromOldFormat_Failed_to_convert__0__optimizations_to_new_format_, optimizations.Count - optimizationsUpdated)); } using (var fs = new FileSaver(path)) { OptimizationDb db = CreateOptimizationDb(fs.SafeName); db.UpdateOptimizations(optimizations.Select(opt => opt.Item1).ToArray(), new DbOptimization[0]); fs.Commit(); if (loadMonitor != null) loadMonitor.UpdateProgress(status.ChangePercentComplete(100)); return GetOptimizationDb(fs.RealName, null, null); } }
private SrmDocument ConnectLibrarySpecs(IWin32Window parent, SrmDocument document, string documentPath) { string docLibFile = null; if (!string.IsNullOrEmpty(documentPath) && document.Settings.PeptideSettings.Libraries.HasDocumentLibrary) { docLibFile = BiblioSpecLiteSpec.GetLibraryFileName(documentPath); if (!File.Exists(docLibFile)) { MessageDlg.Show(this, string.Format(Resources.SkylineWindow_ConnectLibrarySpecs_Could_not_find_the_spectral_library__0__for_this_document__Without_the_library__no_spectrum_ID_information_will_be_available_, docLibFile)); } } var settings = document.Settings.ConnectLibrarySpecs(library => { LibrarySpec spec; if (Settings.Default.SpectralLibraryList.TryGetValue(library.Name, out spec)) { if (File.Exists(spec.FilePath)) return spec; } if (documentPath == null) return null; string fileName = library.FileNameHint; if (fileName != null) { // First look for the file name in the document directory string pathLibrary = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName); if (File.Exists(pathLibrary)) return library.CreateSpec(pathLibrary).ChangeDocumentLocal(true); // In the user's default library directory pathLibrary = Path.Combine(Settings.Default.LibraryDirectory ?? string.Empty, fileName); if (File.Exists(pathLibrary)) return library.CreateSpec(pathLibrary); } using (var dlg = new MissingFileDlg { ItemName = library.Name, ItemType = Resources.SkylineWindow_ConnectLibrarySpecs_Spectral_Library, Filter = library.SpecFilter, FileHint = fileName, FileDlgInitialPath = Path.GetDirectoryName(documentPath), Title = Resources.SkylineWindow_ConnectLibrarySpecs_Find_Spectral_Library }) { if (dlg.ShowDialog(parent) == DialogResult.OK) { Settings.Default.LibraryDirectory = Path.GetDirectoryName(dlg.FilePath); return library.CreateSpec(dlg.FilePath); } } return null; }, docLibFile); if (settings == null) return null; // User cancelled if (ReferenceEquals(settings, document.Settings)) return document; // If the libraries were moved to disconnected state, then avoid updating // the document tree for this change, or it will strip all the library // information off the document nodes. if (settings.PeptideSettings.Libraries.DisconnectedLibraries != null) return document.ChangeSettingsNoDiff(settings); return document.ChangeSettings(settings); }
private SrmDocument AddPeptides(SrmDocument document, bool validating, ref IdentityPath selectedPath) { if (tabControl1.SelectedTab != tabPagePeptideList) return document; var matcher = new ModificationMatcher(); var listPeptideSequences = ListPeptideSequences(); if (listPeptideSequences == null) return null; try { matcher.CreateMatches(document.Settings, listPeptideSequences, Settings.Default.StaticModList, Settings.Default.HeavyModList); } catch (FormatException e) { MessageDlg.ShowException(this, e); ShowPeptideError(new PasteError { Column = colPeptideSequence.Index, Message = Resources.PasteDlg_AddPeptides_Unable_to_interpret_peptide_modifications }); return null; } var strNameMatches = matcher.FoundMatches; if (!validating && !string.IsNullOrEmpty(strNameMatches)) { string message = TextUtil.LineSeparate(Resources.PasteDlg_AddPeptides_Would_you_like_to_use_the_Unimod_definitions_for_the_following_modifications, string.Empty, strNameMatches); if (MultiButtonMsgDlg.Show(this, message, Resources.PasteDlg_AddPeptides_OK) == DialogResult.Cancel) return null; } var backgroundProteome = GetBackgroundProteome(document); // Insert last to first so that proteins get inserted on top of each other // in the order they are added. Peptide insertion into peptide lists needs // to be carefully tracked to insert them in the order they are listed in // the grid. int lastGroupGlobalIndex = 0, lastPeptideIndex = -1; for (int i = gridViewPeptides.Rows.Count - 1; i >= 0; i--) { PeptideGroupDocNode peptideGroupDocNode; var row = gridViewPeptides.Rows[i]; var pepModSequence = Convert.ToString(row.Cells[colPeptideSequence.Index].Value); pepModSequence = FastaSequence.NormalizeNTerminalMod(pepModSequence); var proteinName = Convert.ToString(row.Cells[colPeptideProtein.Index].Value); if (string.IsNullOrEmpty(pepModSequence) && string.IsNullOrEmpty(proteinName)) continue; if (string.IsNullOrEmpty(proteinName)) { peptideGroupDocNode = GetSelectedPeptideGroupDocNode(document, selectedPath); if (!IsPeptideListDocNode(peptideGroupDocNode)) { peptideGroupDocNode = null; } } else { peptideGroupDocNode = FindPeptideGroupDocNode(document, proteinName); } if (peptideGroupDocNode == null) { if (string.IsNullOrEmpty(proteinName)) { peptideGroupDocNode = new PeptideGroupDocNode(new PeptideGroup(), document.GetPeptideGroupId(true), null, new PeptideDocNode[0]); } else { ProteinMetadata metadata = null; PeptideGroup peptideGroup = backgroundProteome.IsNone ? new PeptideGroup() : (backgroundProteome.GetFastaSequence(proteinName, out metadata) ?? new PeptideGroup()); if (metadata != null) peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, metadata, new PeptideDocNode[0]); else peptideGroupDocNode = new PeptideGroupDocNode(peptideGroup, proteinName, peptideGroup.Description, new PeptideDocNode[0]); } // Add to the end, if no insert node var to = selectedPath; if (to == null || to.Depth < (int)SrmDocument.Level.MoleculeGroups) document = (SrmDocument)document.Add(peptideGroupDocNode); else { Identity toId = selectedPath.GetIdentity((int) SrmDocument.Level.MoleculeGroups); document = (SrmDocument) document.Insert(toId, peptideGroupDocNode); } selectedPath = new IdentityPath(peptideGroupDocNode.Id); } var peptides = new List<PeptideDocNode>(); foreach (PeptideDocNode peptideDocNode in peptideGroupDocNode.Children) { peptides.Add(peptideDocNode); } var fastaSequence = peptideGroupDocNode.PeptideGroup as FastaSequence; PeptideDocNode nodePepNew; if (fastaSequence != null) { // Attempt to create node for error checking. nodePepNew = fastaSequence.CreateFullPeptideDocNode(document.Settings, FastaSequence.StripModifications(pepModSequence)); if (nodePepNew == null) { ShowPeptideError(new PasteError { Column = colPeptideSequence.Index, Line = i, Message = Resources.PasteDlg_AddPeptides_This_peptide_sequence_was_not_found_in_the_protein_sequence }); return null; } } // Create node using ModificationMatcher. nodePepNew = matcher.GetModifiedNode(pepModSequence, fastaSequence).ChangeSettings(document.Settings, SrmSettingsDiff.ALL); // Avoid adding an existing peptide a second time. if (!peptides.Contains(nodePep => Equals(nodePep.Key, nodePepNew.Key))) { if (nodePepNew.Peptide.FastaSequence != null) { peptides.Add(nodePepNew); peptides.Sort(FastaSequence.ComparePeptides); } else { int groupGlobalIndex = peptideGroupDocNode.PeptideGroup.GlobalIndex; if (groupGlobalIndex == lastGroupGlobalIndex && lastPeptideIndex != -1) { peptides.Insert(lastPeptideIndex, nodePepNew); } else { lastPeptideIndex = peptides.Count; peptides.Add(nodePepNew); } lastGroupGlobalIndex = groupGlobalIndex; } var newPeptideGroupDocNode = new PeptideGroupDocNode(peptideGroupDocNode.PeptideGroup, peptideGroupDocNode.Annotations, peptideGroupDocNode.Name, peptideGroupDocNode.Description, peptides.ToArray(), false); document = (SrmDocument)document.ReplaceChild(newPeptideGroupDocNode); } } if (!validating && listPeptideSequences.Count > 0) { var pepModsNew = matcher.GetDocModifications(document); document = document.ChangeSettings(document.Settings.ChangePeptideModifications(mods => pepModsNew)); document.Settings.UpdateDefaultModifications(false); } return document; }
private SrmDocument ConnectBackgroundProteome(SrmDocument document, string documentPath) { var settings = document.Settings.ConnectBackgroundProteome(backgroundProteomeSpec => FindBackgroundProteome(documentPath, backgroundProteomeSpec)); if (settings == null) return null; if (ReferenceEquals(settings, document.Settings)) return document; return document.ChangeSettings(settings); }
private SrmDocument ConnectIonMobilityDatabase(SrmDocument document, string documentPath) { var settings = document.Settings.ConnectIonMobilityLibrary(imdb => FindIonMobilityDatabase(documentPath, imdb)); if (settings == null) return null; if (ReferenceEquals(settings, document.Settings)) return document; return document.ChangeSettings(settings); }
public static SrmDocument RecalculateAlignments(SrmDocument document, IProgressMonitor progressMonitor) { var newSources = ListAvailableRetentionTimeSources(document.Settings); var newResultsSources = ListSourcesForResults(document.Settings.MeasuredResults, newSources); var allLibraryRetentionTimes = ReadAllRetentionTimes(document, newSources); var newFileAlignments = new List<FileRetentionTimeAlignments>(); var progressStatus = new ProgressStatus("Aligning retention times"); // Not L10N? Will users see this? foreach (var retentionTimeSource in newResultsSources.Values) { progressStatus = progressStatus.ChangePercentComplete(100*newFileAlignments.Count/newResultsSources.Count); progressMonitor.UpdateProgress(progressStatus); try { var fileAlignments = CalculateFileRetentionTimeAlignments(retentionTimeSource.Name, allLibraryRetentionTimes, progressMonitor); newFileAlignments.Add(fileAlignments); } catch (OperationCanceledException) { progressMonitor.UpdateProgress(progressStatus.Cancel()); return null; } } var newDocRt = new DocumentRetentionTimes(newSources.Values, newFileAlignments); var newDocument = document.ChangeSettings(document.Settings.ChangeDocumentRetentionTimes(newDocRt)); Debug.Assert(IsLoaded(newDocument)); progressMonitor.UpdateProgress(progressStatus.Complete()); return newDocument; }
private SrmDocument ConnectIrtDatabase(SrmDocument document, string documentPath) { var settings = document.Settings.ConnectIrtDatabase(calc => FindIrtDatabase(documentPath, calc)); if (settings == null) return null; if (ReferenceEquals(settings, document.Settings)) return document; return document.ChangeSettings(settings); }
private SrmDocument ChangeQuantificationSettings(SrmDocument srmDocument, QuantificationSettings quantificationSettings) { return srmDocument.ChangeSettings( srmDocument.Settings.ChangePeptideSettings( srmDocument.Settings.PeptideSettings.ChangeAbsoluteQuantification( quantificationSettings))); }
public void MultiLabelExplicitSerialTest() { // Create a simple document and add two peptides SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault()); const string pepSequence1 = "QFVLSCVILR"; const string pepSequence2 = "DIEVYCDGAITTK"; var reader = new StringReader(string.Join("\n", new[] {">peptides1", pepSequence1, pepSequence2})); IdentityPath path; document = document.ImportFasta(reader, true, IdentityPath.ROOT, out path); Assert.AreEqual(2, document.PeptideCount); // Add some modifications in two new label types var modCarb = new StaticMod("Carbamidomethyl Cysteine", "C", null, "C2H3ON"); var modOther = new StaticMod("Another Cysteine", "C", null, "CO8N2"); var staticMods = new[] {modCarb, modOther}; var mod15N = new StaticMod("All 15N", null, null, null, LabelAtoms.N15, null, null); var modK13C = new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null); var modR13C = new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null); var modV13C = new StaticMod("Heavy V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null); var heavyMods = new[] { mod15N, modK13C, modR13C, modV13C }; var labelTypeAA = new IsotopeLabelType("heavy AA", IsotopeLabelType.FirstHeavy); var labelTypeAll = new IsotopeLabelType("heavy All", IsotopeLabelType.FirstHeavy + 1); var settings = document.Settings; settings = settings.ChangePeptideModifications(mods => new PeptideModifications(mods.StaticModifications, new[] { new TypedModifications(labelTypeAA, new[] {modK13C, modR13C}), new TypedModifications(labelTypeAll, new[] {mod15N}) })); document = document.ChangeSettings(settings); Assert.AreEqual(6, document.PeptideTransitionGroupCount); // Add modifications to light and heavy AA in the first peptide path = document.GetPathTo((int) SrmDocument.Level.Molecules, 0); var nodePepMod = (PeptideDocNode) document.FindNode(path); var explicitMod = new ExplicitMods(nodePepMod.Peptide, new[] {new ExplicitMod(pepSequence1.IndexOf('C'), modOther)}, new[] {new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAA, new ExplicitMod[0])}); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); // Add a modification to heavy All in the second peptide path = document.GetPathTo((int)SrmDocument.Level.Molecules, 1); nodePepMod = (PeptideDocNode)document.FindNode(path); explicitMod = new ExplicitMods(nodePepMod.Peptide, null, new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAll, new[] {new ExplicitMod(pepSequence2.IndexOf('V'), modV13C)}) }); document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods); Assert.AreEqual(5, document.PeptideTransitionGroupCount); AssertEx.Serializable(document, 3, AssertEx.DocumentCloned); }