public void TestCustomMoleculeToTSV() { var moleculeAccessionNumbers = new MoleculeAccessionNumbers(new Dictionary <string, string> { { MoleculeAccessionNumbers.TagCAS, "MyCAS" }, { MoleculeAccessionNumbers.TagHMDB, "MyHMDB" }, { MoleculeAccessionNumbers.TagInChI, "MyInChI" }, { MoleculeAccessionNumbers.TagSMILES, "MySmiles" }, { MoleculeAccessionNumbers.TagKEGG, "MyKegg" } }); var smallMoleculeLibraryAttributes = SmallMoleculeLibraryAttributes.Create("MyMolecule", "H2O", "MyInChiKey", moleculeAccessionNumbers.GetNonInChiKeys()); for (var loop = 0; loop < 2; loop++) { var customMolecule = CustomMolecule.FromSmallMoleculeLibraryAttributes(smallMoleculeLibraryAttributes); var target = new Target(customMolecule); var serializableString = target.ToSerializableString(); var roundTrip = Target.FromSerializableString(serializableString); Assert.AreEqual(target, roundTrip); Assert.AreEqual(customMolecule, roundTrip.Molecule); Assert.AreEqual(customMolecule.AccessionNumbers, roundTrip.Molecule.AccessionNumbers); smallMoleculeLibraryAttributes = // Masses instead of formula SmallMoleculeLibraryAttributes.Create("MyMolecule", null, new TypedMass(123.4, MassType.Monoisotopic), new TypedMass(123.45, MassType.Average), "MyInChiKey", moleculeAccessionNumbers.GetNonInChiKeys()); } }
private static SmallMoleculeLibraryAttributes Normalize( ValueCache valueCache, SmallMoleculeLibraryAttributes smallMoleculeLibraryAttributes) { if (smallMoleculeLibraryAttributes == null) { return(SmallMoleculeLibraryAttributes.EMPTY); } if (null == smallMoleculeLibraryAttributes.MoleculeName || null == smallMoleculeLibraryAttributes.ChemicalFormula || null == smallMoleculeLibraryAttributes.InChiKey || null == smallMoleculeLibraryAttributes.OtherKeys) { smallMoleculeLibraryAttributes = SmallMoleculeLibraryAttributes.Create( smallMoleculeLibraryAttributes.MoleculeName ?? string.Empty, smallMoleculeLibraryAttributes.ChemicalFormula ?? string.Empty, smallMoleculeLibraryAttributes.InChiKey ?? string.Empty, smallMoleculeLibraryAttributes.OtherKeys ?? string.Empty); } if (valueCache != null) { if (!valueCache.TryGetCachedValue(ref smallMoleculeLibraryAttributes)) { smallMoleculeLibraryAttributes = valueCache.CacheValue(SmallMoleculeLibraryAttributes.Create( valueCache.CacheValue(smallMoleculeLibraryAttributes.MoleculeName), valueCache.CacheValue(smallMoleculeLibraryAttributes.ChemicalFormula), valueCache.CacheValue(smallMoleculeLibraryAttributes.InChiKey), valueCache.CacheValue(smallMoleculeLibraryAttributes.OtherKeys) )); } } return(smallMoleculeLibraryAttributes); }
internal MoleculeLibraryKey(ValueCache valueCache, LibraryKeyProto libraryKeyProto) : this( valueCache, SmallMoleculeLibraryAttributes.Create( valueCache.CacheValue(libraryKeyProto.MoleculeName), valueCache.CacheValue(libraryKeyProto.ChemicalFormula), libraryKeyProto.InChiKey, libraryKeyProto.OtherKeys), Adduct.FromString(libraryKeyProto.Adduct, Adduct.ADDUCT_TYPE.non_proteomic, null)) { }
public void TestCustomMoleculeToTSV() { var moleculeAccessionNumbers = new MoleculeAccessionNumbers(new Dictionary <string, string> { { MoleculeAccessionNumbers.TagCAS, "MyCAS" }, { MoleculeAccessionNumbers.TagHMDB, "MyHMDB" }, { MoleculeAccessionNumbers.TagInChI, "MyInChI" }, { MoleculeAccessionNumbers.TagSMILES, "MySmiles" } }); var smallMoleculeLibraryAttributes = SmallMoleculeLibraryAttributes.Create("MyMolecule", "H2O", "MyInChiKey", moleculeAccessionNumbers.GetNonInChiKeys()); var customMolecule = new CustomMolecule(smallMoleculeLibraryAttributes); var target = new Target(customMolecule); var serializableString = target.ToSerializableString(); var roundTrip = Target.FromSerializableString(serializableString); Assert.AreEqual(target, roundTrip); Assert.AreEqual(customMolecule, roundTrip.Molecule); Assert.AreEqual(customMolecule.AccessionNumbers, roundTrip.Molecule.AccessionNumbers); }
protected const string massFormatRegex = @"(?:[a-z][a-z]+)\s+\[([+-]?\d*\.\d+)(?![-+0-9\.])\/([+-]?\d*\.\d+)(?![-+0-9\.])\]"; // Not L10N public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes() { return(SmallMoleculeLibraryAttributes.Create(Name, Formula, AccessionNumbers.GetInChiKey(), AccessionNumbers.GetNonInChiKeys())); }
public void TestLibIonMobilityInfo() { const string caffeineFormula = "C8H10N4O2"; const string caffeineInChiKey = "RYYVLZVUVIJVGH-UHFFFAOYSA-N"; const string caffeineHMDB = "HMDB01847"; const double HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC = -.01; var dbIon1 = new DbIonMobilityPeptide(new Target("JKLMN"), Adduct.SINGLY_PROTONATED, 1.2, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) { Id = 12345 }; for (var loop = 0; loop < 2; loop++) { var dbIon2 = new DbIonMobilityPeptide(dbIon1); DbIonMobilityPeptide dbIon3 = null; Assert.AreEqual(dbIon1.GetHashCode(), dbIon2.GetHashCode()); Assert.IsFalse(dbIon1.Equals(null)); Assert.IsTrue(dbIon1.Equals(dbIon2 as object)); // ReSharper disable once ExpressionIsAlwaysNull Assert.IsFalse(dbIon1.Equals(dbIon3 as object)); Assert.IsTrue(dbIon1.Equals(dbIon1)); Assert.IsTrue(dbIon1.Equals(dbIon1 as object)); Assert.IsTrue(dbIon1.Equals(dbIon2)); dbIon1.CollisionalCrossSection = 1.3; Assert.AreNotEqual(dbIon1.CollisionalCrossSection, dbIon2.CollisionalCrossSection); if (loop == 1) { dbIon1.ModifiedTarget = new Target("foo"); Assert.AreNotEqual(dbIon1.Target, dbIon2.Target); Assert.AreNotEqual(dbIon1.ModifiedTarget, dbIon2.ModifiedTarget); } else { Assert.AreEqual(dbIon1.ModifiedTarget, dbIon2.ModifiedTarget); Assert.AreEqual(dbIon1.ModifiedTarget.Molecule, dbIon2.ModifiedTarget.Molecule); } dbIon1 = new DbIonMobilityPeptide( SmallMoleculeLibraryAttributes.Create("caffeine", caffeineFormula, caffeineInChiKey, caffeineHMDB), Adduct.FromStringAssumeProtonated("M+Na"), 1.2, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) { Id = 12345 }; } var dictCCS1 = new Dictionary <LibKey, IonMobilityAndCCS[]>(); var ccs1 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 1, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 2, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Collisional cross sections var ccs2 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 3, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 4, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Collisional cross sections const string seq1 = "JKLM"; const string seq2 = "KLMN"; dictCCS1.Add(new LibKey(seq1, 1), ccs1.ToArray()); dictCCS1.Add(new LibKey(seq2, 1), ccs2.ToArray()); var lib = new List <LibraryIonMobilityInfo> { new LibraryIonMobilityInfo("test", dictCCS1) }; var peptideTimes = CollisionalCrossSectionGridViewDriver.ConvertDriftTimesToCollisionalCrossSections(null, lib, 1, null); var validatingIonMobilityPeptides = peptideTimes as ValidatingIonMobilityPeptide[] ?? peptideTimes.ToArray(); Assert.AreEqual(2, validatingIonMobilityPeptides.Length); Assert.AreEqual(1.5, validatingIonMobilityPeptides[0].CollisionalCrossSection); Assert.AreEqual(3.5, validatingIonMobilityPeptides[1].CollisionalCrossSection); Assert.AreEqual(HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC, validatingIonMobilityPeptides[1].HighEnergyDriftTimeOffsetMsec); // Test serialization of molecule with '$' in it, which we use as a tab replacement against XML parser variability var molser = new CustomMolecule(SmallMoleculeLibraryAttributes.Create("caffeine$", caffeineFormula, caffeineInChiKey, caffeineHMDB)); var text = molser.ToSerializableString(); Assert.AreEqual(molser, CustomMolecule.FromSerializableString(text)); var dictCCS2 = new Dictionary <LibKey, IonMobilityAndCCS[]>(); var ccs3 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(4, eIonMobilityUnits.drift_time_msec), null, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Drift times const string seq3 = "KLMNJ"; dictCCS2.Add(new LibKey(seq3, Adduct.SINGLY_PROTONATED), ccs3.ToArray()); lib.Add(new LibraryIonMobilityInfo("test2", dictCCS2)); List <LibraryIonMobilityInfo> lib1 = lib; AssertEx.ThrowsException <Exception>(() => CollisionalCrossSectionGridViewDriver.ConvertDriftTimesToCollisionalCrossSections(null, lib1, 2, null), String.Format( Resources.CollisionalCrossSectionGridViewDriver_ProcessIonMobilityValues_Cannot_import_measured_ion_mobility_for_sequence__0___no_collisional_cross_section_conversion_parameters_were_provided_for_charge_state__1__, seq3, 1)); var regressions = new Dictionary <int, RegressionLine> { { 1, new RegressionLine(2, 1) } }; lib = new List <LibraryIonMobilityInfo> { new LibraryIonMobilityInfo("test", dictCCS2) }; peptideTimes = CollisionalCrossSectionGridViewDriver.ConvertDriftTimesToCollisionalCrossSections(null, lib, 1, regressions); validatingIonMobilityPeptides = peptideTimes as ValidatingIonMobilityPeptide[] ?? peptideTimes.ToArray(); Assert.AreEqual(1, validatingIonMobilityPeptides.Length); Assert.AreEqual(1.75, validatingIonMobilityPeptides[0].CollisionalCrossSection); }
private void MainTest() { // Clean-up before running the test RunUI(() => SkylineWindow.ModifyDocument("Set default settings", doc => doc.ChangeSettings(SrmSettingsList.GetDefault()))); // Check using libkey with small molecules var adduct = Adduct.FromStringAssumeProtonated("M+3Na"); var z = adduct.AdductCharge; const string caffeineFormula = "C8H10N4O2"; const string caffeineInChiKey = "RYYVLZVUVIJVGH-UHFFFAOYSA-N"; const string caffeineHMDB = "HMDB01847"; const string caffeineInChi = "InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3"; const string caffeineCAS = "58-08-2"; const string caffeineSMILES = "Cn1cnc2n(C)c(=O)n(C)c(=O)c12"; const string caffeineKEGG = "C07481"; var mId = new MoleculeAccessionNumbers(string.Join("\t", MoleculeAccessionNumbers.TagHMDB + ":" + caffeineHMDB, MoleculeAccessionNumbers.TagInChI + ":" + caffeineInChi, MoleculeAccessionNumbers.TagCAS + ":" + caffeineCAS, MoleculeAccessionNumbers.TagInChiKey + ":" + caffeineInChiKey, MoleculeAccessionNumbers.TagSMILES + ":" + caffeineSMILES, MoleculeAccessionNumbers.TagKEGG + ":" + caffeineKEGG)); Assert.AreEqual(caffeineInChiKey, mId.GetInChiKey()); Assert.AreEqual(caffeineCAS, mId.GetCAS()); Assert.AreEqual(caffeineSMILES, mId.GetSMILES()); Assert.AreEqual(caffeineKEGG, mId.GetKEGG()); var moleculeName = "caffeine"; var smallMolAttributes = SmallMoleculeLibraryAttributes.Create(moleculeName, caffeineFormula, caffeineInChiKey, string.Join("\t", MoleculeAccessionNumbers.TagHMDB + ":" + caffeineHMDB, MoleculeAccessionNumbers.TagInChI + ":" + caffeineInChi, MoleculeAccessionNumbers.TagCAS + ":" + caffeineCAS, MoleculeAccessionNumbers.TagSMILES + ":" + caffeineSMILES, MoleculeAccessionNumbers.TagKEGG + ":" + caffeineKEGG)); LibKey key; for (var loop = 0; loop++ < 2;) { key = new LibKey(smallMolAttributes, adduct); Assert.IsFalse(key.IsPrecursorKey); Assert.IsFalse(key.IsProteomicKey); Assert.IsTrue(key.IsSmallMoleculeKey); Assert.IsFalse(key.IsModified); Assert.AreEqual(0, key.ModificationCount); Assert.AreEqual(z, key.Charge); Assert.AreEqual(adduct, key.Adduct); Assert.AreEqual(caffeineInChiKey, key.Target.ToString()); var viewLibPepInfo = new ViewLibraryPepInfo(key); Assert.AreEqual(key, viewLibPepInfo.Key); var smallMolInfo = viewLibPepInfo.GetSmallMoleculeLibraryAttributes(); Assert.AreEqual(moleculeName, smallMolInfo.MoleculeName); Assert.AreEqual(caffeineInChiKey, smallMolInfo.InChiKey); Assert.AreEqual(caffeineFormula, smallMolInfo.ChemicalFormula); Assert.IsTrue(smallMolInfo.OtherKeys.Contains(caffeineCAS)); Assert.IsTrue(smallMolInfo.OtherKeys.Contains(caffeineInChi)); Assert.IsTrue(smallMolInfo.OtherKeys.Contains(caffeineHMDB)); Assert.IsTrue(smallMolInfo.OtherKeys.Contains(caffeineSMILES)); Assert.IsTrue(smallMolInfo.OtherKeys.Contains(caffeineKEGG)); adduct = Adduct.FromString("M+3Si", Adduct.ADDUCT_TYPE.non_proteomic, z = -17); // Not realistic, but let's see if it's handled consistently } // Check general libkey operation var seq = "YTQSNSVC[+57.0]YAK"; key = new LibKey(seq, Adduct.DOUBLY_PROTONATED); Assert.IsFalse(key.IsPrecursorKey); Assert.IsTrue(key.IsProteomicKey); Assert.IsFalse(key.IsSmallMoleculeKey); Assert.IsTrue(key.IsModified); Assert.AreEqual(2, key.Charge); Assert.AreEqual(1, key.ModificationCount); Assert.AreEqual(Adduct.DOUBLY_PROTONATED, key.Adduct); Assert.AreEqual(seq, key.Target.ToString()); // Test error conditions BuildLibraryError("missing_charge.pep.XML", TestFilesDir.FullPath); BuildLibraryError("non_int_charge.pep.XML", null); BuildLibraryError("zero_charge.pep.XML", null); BuildLibraryError("truncated.pep.XML", null); BuildLibraryError("no_such_file.pep.XML", null, "Failed to open"); BuildLibraryError("missing_mzxml.pep.XML", null, "Could not find spectrum file"); // Check for proper handling of labeled addducts in small molecule files // (formerly this would throw on a null object, fixed with the use of ExplicitMods.EMPTY) BuildLibraryValid("heavy_adduct.ssl", true, false, false, 1); // Make sure explorer handles this adduct type var viewLibUI = ShowDialog <ViewLibraryDlg>(SkylineWindow.ViewSpectralLibraries); RunUI(() => AssertEx.IsTrue(viewLibUI.GraphItem.IonLabels.Any())); RunUI(viewLibUI.CancelDialog); // Barbara added code to ProteoWizard to rebuild a missing or invalid mzXML index // BuildLibraryError("bad_mzxml.pep.XML", "<index> not found"); BuildLibraryValid(TestFilesDir.GetTestPath("library_errors"), new[] { "bad_mzxml.pep.XML" }, false, false, false, 1); string libraryBaseName = _libraryName; // Test mascot parser _libraryName = libraryBaseName + "mascot"; string libraryMascot = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid(TestFilesDir.GetTestPath("mascot"), new[] { "F027319.dat" }, true, false, false, 121, 4); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryMascot))); // Test successful builds _libraryName = libraryBaseName + "a"; string libraryA = _libraryName + BiblioSpecLiteSpec.EXT; string libraryARedundant = _libraryName + BiblioSpecLiteSpec.EXT_REDUNDANT; BuildLibraryValid("CPTAC_Set4_725_091509.pep.XML", true, false, false, 1); BuildLibraryValid("CPTAC_Set4_610_080509.pep.XML", true, false, true, 2); _libraryName = libraryBaseName + "b"; string libraryB = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid("CPTAC_Set4_624_072409.pep.XML", false, false, false, 6); _libraryName = libraryBaseName + "c"; string libraryC = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid(TestFilesDir.FullPath, new[] { libraryA, libraryB }, false, false, false, 8); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryA))); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryARedundant))); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryB))); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryC))); // Test peptide filter const string filterList = "ACARPIISVYSEK\n" + // TODO: Having the modified sequence as the first line causes an error with European number formats "ADRDESSPYAAM[+{0:F01}]IAAQDVAQR\n" + "ADAIQAGASQFETSAAK"; PastePeptideList(string.Format(filterList, 16.0), true, 0, 3, true); _libraryName = libraryBaseName + "filter"; string libraryFilter = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid(TestFilesDir.GetTestPath("maxquant"), new[] { "test.msms.txt" }, false, true, false, 2); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryFilter))); RunUI(SkylineWindow.Undo); RunUI(SkylineWindow.Undo); // Test AddPathsDlg (file not found) EnsurePeptideSettings(); var buildLibraryDlg = ShowDialog <BuildLibraryDlg>(PeptideSettingsUI.ShowBuildLibraryDlg); string[] invalidPaths = { Path.Combine(TestFilesDir.GetTestPath("maxquant"), "test.msms.xml"), Path.Combine(TestFilesDir.GetTestPath("library_valid"), "CPTAC_Set4_624_072409.pep.XML") }; TestAddPaths(buildLibraryDlg, invalidPaths, true); // Test AddPathsDlg (file invalid type) string[] invalidTypes = { Path.Combine(TestFilesDir.GetTestPath("maxquant"), "test.msms.txt"), Path.Combine(TestFilesDir.GetTestPath("maxquant"), "mqpar.xml") }; TestAddPaths(buildLibraryDlg, invalidTypes, true); // Test AddPathsDlg (valid files) string[] goodPaths = { Path.Combine(TestFilesDir.GetTestPath("maxquant"), "test.msms.txt"), Path.Combine(TestFilesDir.GetTestPath("library_valid"), "CPTAC_Set4_624_072409.pep.XML") }; TestAddPaths(buildLibraryDlg, goodPaths, false); OkDialog(buildLibraryDlg, buildLibraryDlg.CancelDialog); const string heavyRPeptide = "TPAQFDADELR"; const string oxidizedMPeptide = "LVGNMHGDETVSR"; const string peptideList = heavyRPeptide + "\n" + oxidizedMPeptide + "\n" + "ALSIGFETCR\n" + "GNMHGDETVSR\n" + "VGNMHGDETVSR"; PastePeptideList(peptideList, true, 0, 1); // Set modifications on peptides to verify they connect with library spectra. const LabelAtoms labelAtoms = LabelAtoms.C13 | LabelAtoms.N15; const string heavyR = "Heavy R"; Settings.Default.HeavyModList.Add(new StaticMod(heavyR, "R", ModTerminus.C, null, labelAtoms, null, null)); const string oMeth = "Oxidized Methionine"; Settings.Default.StaticModList.Add(new StaticMod(oMeth, "M", null, "O")); var sequenceTree = SkylineWindow.SequenceTree; var docCurrent = SkylineWindow.Document; // Select the heavyR peptide PeptideTreeNode nodePepTree = null; IdentityPath pathPep = docCurrent.GetPathTo((int)SrmDocument.Level.Molecules, 0); RunUI(() => { sequenceTree.SelectedPath = pathPep; nodePepTree = sequenceTree.SelectedNode as PeptideTreeNode; }); Assert.IsNotNull(nodePepTree); Assert.AreEqual(heavyRPeptide, nodePepTree.DocNode.Peptide.Sequence); // Set the Heavy R modification explicitly var editPepModsDlg = ShowDialog <EditPepModsDlg>(SkylineWindow.ModifyPeptide); RunUI(() => { editPepModsDlg.SetModification(heavyRPeptide.Length - 1, IsotopeLabelType.heavy, heavyR); editPepModsDlg.OkDialog(); }); WaitForCondition(() => (SkylineWindow.Document.Molecules.First().TransitionGroupCount == 2)); // The peptide should now match the spectrum in the library, and have // both heavy and light precursors, with ranked transitions PeptideDocNode nodePep = null; RunUI(() => nodePep = nodePepTree.DocNode); Assert.IsNotNull(nodePep); Debug.Assert(nodePep != null); Assert.AreEqual(2, nodePep.Children.Count, "Missing precursor for heavy R peptide."); docCurrent = SkylineWindow.Document; foreach (TransitionGroupDocNode nodeGroup in nodePep.Children) { AssertLibInfo(docCurrent, nodeGroup); } // Which means all transition groups should now have spectrum info foreach (var nodeGroup in docCurrent.PeptideTransitionGroups) { AssertLibInfo(docCurrent, nodeGroup); } // New document var docNew = new SrmDocument(SrmSettingsList.GetDefault()); var docNewCopy = docNew; RunUI(() => SkylineWindow.SwitchDocument(docNewCopy, null)); const string idpList3 = "FHYKTDQGIK\n" + "WCAIGHQER\n" + "WCTISTHEANK"; int idpCount3 = idpList3.Split('\n').Length; const string idpList = "ADVTLGGGAK\n" + "AGFAGDDAPR\n" + "ALEFAKK\n" + "CCTESLVNR\n" + "DSYVGDEAQSK\n" + "YICDNQDTISSK\n" + // charge 3 peptides all have 2 also idpList3; int idpCount = idpList.Split('\n').Length; _libraryName = libraryBaseName + "_idp"; string libraryIdp = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid(TestFilesDir.GetTestPath("idp_xml"), new[] { "orbi-small-eg.idpXML" }, false, false, false, idpCount + idpCount3); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryIdp))); // Add peptides expected to have charge 2 spectra in the library PastePeptideList(idpList, true, 0, 0); // Undo the paste RunUI(SkylineWindow.Undo); // Try filtering for only charge 3 spectra var transitionSettingsUI = ShowDialog <TransitionSettingsUI>( SkylineWindow.ShowTransitionSettingsUI); RunUI(() => { transitionSettingsUI.PrecursorCharges = "3"; transitionSettingsUI.OkDialog(); }); PastePeptideList(idpList, false, idpCount - idpCount3 + 1 /* missing cleavage*/, 0); // New document var docNewCopy2 = docNew; RunUI(() => SkylineWindow.SwitchDocument(docNewCopy2, null)); _libraryName = libraryBaseName + "_cpas1"; string libraryCpas1 = _libraryName + BiblioSpecLiteSpec.EXT; BuildLibraryValid(TestFilesDir.GetTestPath("cpas"), null, false, false, false, 3); Assert.IsTrue(File.Exists(TestFilesDir.GetTestPath(libraryCpas1))); // These are very poor searches, so repeat with no filter Settings.Default.LibraryResultCutOff = 0; _libraryName = libraryBaseName + "_cpas2"; BuildLibraryValid(TestFilesDir.GetTestPath("cpas"), null, false, false, false, 100, 100); // And, since the spectra are really poor, allow lots of // possibilities for fragment ions. var transitionSettingsCpas = ShowDialog <TransitionSettingsUI>( SkylineWindow.ShowTransitionSettingsUI); RunUI(() => { transitionSettingsCpas.PrecursorCharges = transitionSettingsCpas.ProductCharges = "1,2,3"; transitionSettingsCpas.FragmentTypes = "y,b"; transitionSettingsCpas.InstrumentMaxMz = 2000; transitionSettingsCpas.OkDialog(); }); EnsurePeptideSettings(); RunUI(() => { // Turn off carbamidomethyl cys, since not in these searches PeptideSettingsUI.PickedStaticMods = new string[0]; PeptideSettingsUI.OkDialog(); }); // Get the set of peptides to paste from the library, since there // are a lot. var setPeptides = new HashSet <Target>(); var library = SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries[0]; foreach (var libKey in library.Keys) { if (!libKey.IsModified) { setPeptides.Add(libKey.Target); } } string cpasPeptides = string.Join("\n", setPeptides.Select(p => p.ToString()).ToArray()); var pasteFilteredPeptideDlg = ShowDialog <PasteFilteredPeptidesDlg>( () => SkylineWindow.Paste(cpasPeptides)); RunUI(pasteFilteredPeptideDlg.NoDialog); Assert.IsTrue(WaitForCondition(() => SkylineWindow.Document.PeptideCount == setPeptides.Count), string.Format("Expecting {0} peptides, found {1}.", setPeptides.Count, SkylineWindow.Document.PeptideCount)); Assert.AreEqual(setPeptides.Count, SkylineWindow.Document.PeptideTransitionGroupCount, "Expecting precursors for peptides matched to library spectrum."); // New document docNew = new SrmDocument(SrmSettingsList.GetDefault()); RunUI(() => SkylineWindow.SwitchDocument(docNew, null)); // Tests for adding iRTs to spectral library after building // 1. ask to recalibrate iRTs // 2. ask to add iRTs // 3. if added iRTs, ask to add RT predictor // no recalibrate, add iRTs, no add predictor _libraryName = libraryBaseName + "_irt1"; // library_test_irt1 BuildLibraryIrt(true, false, false); RunUI(() => Assert.IsTrue(PeptideSettingsUI.Prediction.RetentionTime == null)); // no recalibrate, add iRTs, add predictor _libraryName = libraryBaseName + "_irt2"; // library_test_irt2 BuildLibraryIrt(true, false, true); RunUI(() => Assert.IsTrue(PeptideSettingsUI.Prediction.RetentionTime.Name.Equals(_libraryName))); var editIrtDlg2 = ShowDialog <EditIrtCalcDlg>(PeptideSettingsUI.EditCalculator); RunUI(() => Assert.IsTrue(ReferenceEquals(editIrtDlg2.IrtStandards, IrtStandard.BIOGNOSYS_10))); OkDialog(editIrtDlg2, editIrtDlg2.CancelDialog); // recalibrate, add iRTs, no add predictor _libraryName = libraryBaseName + "_irt3"; // library_test_irt3 BuildLibraryIrt(true, true, false); RunUI(() => Assert.IsTrue(PeptideSettingsUI.Prediction.RetentionTime.Name.Equals(libraryBaseName + "_irt2"))); // recalibrate, add iRTs, add predictor _libraryName = libraryBaseName + "_irt4"; // library_test_irt4 BuildLibraryIrt(true, true, true); RunUI(() => Assert.IsTrue(PeptideSettingsUI.Prediction.RetentionTime.Name.Equals(_libraryName))); var editIrtDlg4 = ShowDialog <EditIrtCalcDlg>(PeptideSettingsUI.EditCalculator); RunUI(() => Assert.IsTrue(ReferenceEquals(editIrtDlg4.IrtStandards, IrtStandard.EMPTY))); OkDialog(editIrtDlg4, editIrtDlg4.CancelDialog); OkDialog(PeptideSettingsUI, PeptideSettingsUI.CancelDialog); }
private void PerformTestMeasuredDriftValues(bool asSmallMolecules) { if (asSmallMolecules) { if (!RunSmallMoleculeTestVersions) { Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } } var testFilesDir = new TestFilesDir(TestContext, @"TestData\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest // Open document with some peptides but no results var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky"); // This was a malformed document, which caused problems after a fix to not recalculate // document library settings on open. To avoid rewriting this test for the document // which now contains 2 precursors, the first precursor is removed immediately. SrmDocument docOriginal = ResultsUtil.DeserializeDocument(docPath); var pathFirstPeptide = docOriginal.GetPathTo((int)SrmDocument.Level.Molecules, 0); var nodeFirstPeptide = (DocNodeParent)docOriginal.FindNode(pathFirstPeptide); docOriginal = (SrmDocument)docOriginal.RemoveChild(pathFirstPeptide, nodeFirstPeptide.Children[0]); if (asSmallMolecules) { var refine = new RefinementSettings(); docOriginal = refine.ConvertToSmallMolecules(docOriginal, testFilesDir.FullPath); } using (var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath)) { var doc = docContainer.Document; // Import an mz5 file that contains drift info const string replicateName = "ID12692_01_UCA168_3727_040714"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714" + ExtensionTestContext.ExtMz5)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); var document = docContainer.Document; // Clear out any current settings document = document.ChangeSettings(document.Settings.ChangeTransitionIonMobilityFiltering(s => TransitionIonMobilityFiltering.EMPTY)); // Verify ability to extract predictions from raw data var libraryName0 = "test0"; var dbPath0 = testFilesDir.GetTestPath(libraryName0 + IonMobilityDb.EXT); var newIMFiltering = document.Settings.TransitionSettings.IonMobilityFiltering.ChangeLibrary( IonMobilityLibrary.CreateFromResults( document, docContainer.DocumentFilePath, true, libraryName0, dbPath0)); var result = newIMFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary(); Assert.AreEqual(1, result.Count); var expectedDT = 4.0019; var expectedOffset = .4829; Assert.AreEqual(expectedDT, result.Values.First().First().IonMobility.Mobility.Value, .001); Assert.AreEqual(expectedOffset, result.Values.First().First().HighEnergyIonMobilityValueOffset ?? 0, .001); // Check ability to update, and to preserve unchanged var revised = new List <PrecursorIonMobilities>(); var libKey = result.Keys.First(); revised.Add(new PrecursorIonMobilities(libKey, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(expectedDT = 4, eIonMobilityUnits.drift_time_msec), null, expectedOffset = 0.234))); // N.B. CCS handling would require actual raw data in this test, it's covered in a perf test var pepSequence = "DEADEELS"; var libKey2 = asSmallMolecules ? new LibKey(SmallMoleculeLibraryAttributes.Create(pepSequence, "C12H5", null, null, null, null), Adduct.M_PLUS_2H) : new LibKey(pepSequence, Adduct.DOUBLY_PROTONATED); revised.Add(new PrecursorIonMobilities(libKey2, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, 0.123))); var libraryName = "test"; var dbPath = testFilesDir.GetTestPath(libraryName + IonMobilityDb.EXT); var imsdb = IonMobilityDb.CreateIonMobilityDb(dbPath, libraryName, false, revised); var newLibIM = new IonMobilityLibrary(libraryName, dbPath, imsdb); var ionMobilityWindowWidthCalculator = new IonMobilityWindowWidthCalculator( IonMobilityWindowWidthCalculator.IonMobilityWindowWidthType.resolving_power, 40, 0, 0, 0); var calculator = ionMobilityWindowWidthCalculator; document = document.ChangeSettings( document.Settings.ChangeTransitionIonMobilityFiltering( imf => imf.ChangeFilterWindowWidthCalculator(calculator). ChangeLibrary(newLibIM))); result = document.Settings.TransitionSettings.IonMobilityFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary(); Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedDT, result[libKey].First().IonMobility.Mobility.Value, .001); Assert.AreEqual(expectedOffset, result[libKey].First().HighEnergyIonMobilityValueOffset ?? 0, .001); Assert.AreEqual(5, result[libKey2].First().IonMobility.Mobility.Value, .001); Assert.AreEqual(0.123, result[libKey2].First().HighEnergyIonMobilityValueOffset ?? 0, .001); ionMobilityWindowWidthCalculator = new IonMobilityWindowWidthCalculator( IonMobilityWindowWidthCalculator.IonMobilityWindowWidthType.fixed_width, 40, 0, 0, 100); document = document.ChangeSettings( document.Settings.ChangeTransitionIonMobilityFiltering( imf => imf.ChangeFilterWindowWidthCalculator(ionMobilityWindowWidthCalculator). ChangeLibrary(newLibIM))); result = document.Settings.TransitionSettings.IonMobilityFiltering.IonMobilityLibrary.GetIonMobilityLibKeyMap().AsDictionary(); Assert.AreEqual(2, result.Count); Assert.AreEqual(expectedDT, result[libKey].First().IonMobility.Mobility.Value, .001); Assert.AreEqual(expectedOffset, result[libKey].First().HighEnergyIonMobilityValueOffset ?? 0, .001); Assert.AreEqual(5, result[libKey2].First().IonMobility.Mobility.Value, .001); Assert.AreEqual(0.123, result[libKey2].First().HighEnergyIonMobilityValueOffset ?? 0, .001); } }
public SmallMoleculeLibraryAttributes GetSmallMoleculeLibraryAttributes() { return(SmallMoleculeLibraryAttributes.Create(Name, Formula, MonoisotopicMass, AverageMass, // In case forumla is empty AccessionNumbers.GetInChiKey(), AccessionNumbers.GetNonInChiKeys())); }
public void TestLibIonMobilityInfo() { const string caffeineFormula = "C8H10N4O2"; const string caffeineInChiKey = "RYYVLZVUVIJVGH-UHFFFAOYSA-N"; const string caffeineHMDB = "HMDB01847"; const double HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC = -.01; var dbMolecule = new DbMolecule(new Target("JKLMN")) { Id = 123456 }; var dbPrecursorIon = new DbPrecursorIon(dbMolecule, Adduct.SINGLY_PROTONATED) { Id = 1234567 }; var dbIonMobilityValue = new DbPrecursorAndIonMobility(dbPrecursorIon, 1.2, 2.3, eIonMobilityUnits.drift_time_msec, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) { Id = 12345 }; DbPrecursorAndIonMobility dbPrecursorAndIonMobilityValue2 = new DbPrecursorAndIonMobility(dbIonMobilityValue); for (var loop = 0; loop < 2; loop++) { Assert.AreEqual(dbIonMobilityValue.GetHashCode(), dbPrecursorAndIonMobilityValue2.GetHashCode()); Assert.IsFalse(dbIonMobilityValue.Equals(null)); Assert.IsTrue(dbIonMobilityValue.Equals(dbPrecursorAndIonMobilityValue2 as object)); Assert.IsTrue(dbIonMobilityValue.Equals(dbIonMobilityValue)); Assert.IsTrue(dbIonMobilityValue.Equals(dbIonMobilityValue as object)); Assert.IsTrue(dbPrecursorAndIonMobilityValue2.Equals(dbIonMobilityValue)); dbIonMobilityValue.CollisionalCrossSectionSqA = 1.3; Assert.AreNotEqual(dbIonMobilityValue.CollisionalCrossSectionSqA, dbPrecursorAndIonMobilityValue2.CollisionalCrossSectionSqA); if (loop == 1) { dbIonMobilityValue.DbPrecursorIon = new DbPrecursorIon(new Target("foo"), Adduct.SINGLY_PROTONATED) { Id = 1234567 }; Assert.AreNotEqual(dbIonMobilityValue.DbPrecursorIon.GetTarget(), dbMolecule); } else { Assert.AreEqual(dbIonMobilityValue.DbPrecursorIon.DbMolecule, dbMolecule); } dbIonMobilityValue = new DbPrecursorAndIonMobility( new DbPrecursorIon( SmallMoleculeLibraryAttributes.Create("caffeine", caffeineFormula, caffeineInChiKey, caffeineHMDB), Adduct.FromStringAssumeProtonated("M+Na")) { Id = 23456 }, 1.2, 2.3, eIonMobilityUnits.drift_time_msec, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) { Id = 12345 }; dbPrecursorAndIonMobilityValue2 = new DbPrecursorAndIonMobility(dbIonMobilityValue); } var dictCCS1 = new Dictionary <LibKey, IonMobilityAndCCS[]>(); var im = IonMobilityValue.GetIonMobilityValue(12, eIonMobilityUnits.drift_time_msec); var ccs1 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 1, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 2, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Collisional cross sections var ccs2 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(im, 3, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.EMPTY, 4, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Collisional cross sections const string seq1 = "JKLM"; const string seq2 = "KLMN"; dictCCS1.Add(new LibKey(seq1, 1), ccs1.ToArray()); dictCCS1.Add(new LibKey(seq2, 1), ccs2.ToArray()); var lib = new List <LibraryIonMobilityInfo> { new LibraryIonMobilityInfo("test", false, dictCCS1) }; var peptideTimes = CollisionalCrossSectionGridViewDriver.CollectIonMobilitiesAndCollisionalCrossSections(null, lib, 1); var validatingIonMobilityPeptides = peptideTimes as ValidatingIonMobilityPrecursor[] ?? peptideTimes.ToArray(); Assert.AreEqual(2, validatingIonMobilityPeptides.Length); Assert.AreEqual(1.5, validatingIonMobilityPeptides[0].CollisionalCrossSectionSqA); Assert.AreEqual(3.5, validatingIonMobilityPeptides[1].CollisionalCrossSectionSqA); Assert.AreEqual(HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC, validatingIonMobilityPeptides[1].HighEnergyIonMobilityOffset); // This time with multiple CCS conformers supported lib = new List <LibraryIonMobilityInfo> { new LibraryIonMobilityInfo("test", true, dictCCS1) }; peptideTimes = CollisionalCrossSectionGridViewDriver.CollectIonMobilitiesAndCollisionalCrossSections(null, lib, 1); validatingIonMobilityPeptides = peptideTimes as ValidatingIonMobilityPrecursor[] ?? peptideTimes.ToArray(); Assert.AreEqual(4, validatingIonMobilityPeptides.Length); Assert.AreEqual(1, validatingIonMobilityPeptides[0].CollisionalCrossSectionSqA); Assert.AreEqual(2, validatingIonMobilityPeptides[1].CollisionalCrossSectionSqA); Assert.AreEqual(3, validatingIonMobilityPeptides[2].CollisionalCrossSectionSqA); Assert.AreEqual(4, validatingIonMobilityPeptides[3].CollisionalCrossSectionSqA); Assert.AreEqual(HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC, validatingIonMobilityPeptides[1].HighEnergyIonMobilityOffset); // Test serialization of molecule with '$' in it, which we use as a tab replacement against XML parser variability var molser = CustomMolecule.FromSmallMoleculeLibraryAttributes(SmallMoleculeLibraryAttributes.Create("caffeine$", caffeineFormula, caffeineInChiKey, caffeineHMDB)); var text = molser.ToSerializableString(); Assert.AreEqual(molser, CustomMolecule.FromSerializableString(text)); // Test handling of SmallMoleculeLibraryAttributes for mass-only descriptions var molserB = CustomMolecule.FromSmallMoleculeLibraryAttributes(SmallMoleculeLibraryAttributes.Create("caffeine$", null, new TypedMass(123.4, MassType.Monoisotopic), new TypedMass(123.45, MassType.Average), caffeineInChiKey, caffeineHMDB)); var textB = molserB.ToSerializableString(); Assert.AreEqual(molserB, CustomMolecule.FromSerializableString(textB)); var dictCCS2 = new Dictionary <LibKey, IonMobilityAndCCS[]>(); var ccs3 = new List <IonMobilityAndCCS> { IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(4, eIonMobilityUnits.drift_time_msec), 1.75, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC), IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, HIGH_ENERGY_DRIFT_TIME_OFFSET_MSEC) }; // Drift times const string seq3 = "KLMNJ"; dictCCS2.Add(new LibKey(seq3, Adduct.SINGLY_PROTONATED), ccs3.ToArray()); lib = new List <LibraryIonMobilityInfo> { new LibraryIonMobilityInfo("test", false, dictCCS2) }; peptideTimes = CollisionalCrossSectionGridViewDriver.CollectIonMobilitiesAndCollisionalCrossSections(null, lib, 1); validatingIonMobilityPeptides = peptideTimes as ValidatingIonMobilityPrecursor[] ?? peptideTimes.ToArray(); Assert.AreEqual(1, validatingIonMobilityPeptides.Length); Assert.AreEqual(1.75, validatingIonMobilityPeptides[0].CollisionalCrossSectionSqA); }