예제 #1
0
        private void TestReports(SrmDocument doc1, string msg = null)
        {
            // Verify reports working for CCS
            var row          = 0;
            var documentGrid = ShowDialog <DocumentGridForm>(() => SkylineWindow.ShowDocumentGrid(true));

            EnableDocumentGridColumns(documentGrid,
                                      Resources.SkylineViewContext_GetTransitionListReportSpec_Small_Molecule_Transition_List,
                                      doc1.PeptideTransitionCount * doc1.MeasuredResults.Chromatograms.Count,
                                      new[]
            {
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.CollisionalCrossSection",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityMS1",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityFragment",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityUnits",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityWindow"
            });
            CheckFieldByName(documentGrid, "IonMobilityMS1", row, 0.832, msg);
            CheckFieldByName(documentGrid, "IonMobilityFragment", row, (double?)null, msg); // Document is all precursor
            CheckFieldByName(documentGrid, "IonMobilityUnits", row, IonMobilityValue.GetUnitsString(eIonMobilityUnits.inverse_K0_Vsec_per_cm2), msg);
            CheckFieldByName(documentGrid, "IonMobilityWindow", row, 0.04, msg);
            CheckFieldByName(documentGrid, "CollisionalCrossSection", row, 474.26, msg);
            // And clean up after ourselves
            RunUI(() => documentGrid.Close());
        }
예제 #2
0
        public bool IsSimSpectrum(MsDataSpectrum dataSpectrum, MsDataSpectrum[] spectra)
        {
            if (!EnabledMs || _mseLevel > 0)
            {
                return(false);
            }
            bool isSimSpectrum = dataSpectrum.Level == 1 &&
                                 IsSimIsolation(GetIsolationWindows(dataSpectrum.Precursors).FirstOrDefault());

            if (isSimSpectrum && spectra.Length > 1)
            {
                // If this is actually a run of IMS bins, look at the aggregate isolation window
                var    rt     = spectra[0].RetentionTime;
                var    win    = GetIsolationWindows(spectra[0].Precursors).FirstOrDefault();
                double mzLow  = win.IsolationMz.Value - win.IsolationWidth.Value / 2;
                double mzHigh = win.IsolationMz.Value + win.IsolationWidth.Value / 2;
                for (var i = 1; i < spectra.Length; i++)
                {
                    var spec = spectra[i];
                    if (!Equals(spec.RetentionTime, rt) || !IonMobilityValue.IsExpectedValueOrdering(spectra[i - 1].IonMobility, spec.IonMobility))
                    {
                        return(true);  // Not a run of IMS bins, must have been actual SIM scan
                    }
                    win    = GetIsolationWindows(spec.Precursors).FirstOrDefault();
                    mzLow  = Math.Min(mzLow, win.IsolationMz.Value - win.IsolationWidth.Value / 2);
                    mzHigh = Math.Max(mzHigh, win.IsolationMz.Value + win.IsolationWidth.Value / 2);
                }
                var width = mzHigh - mzLow;
                isSimSpectrum = IsSimIsolation(new IsolationWindowFilter(new SignedMz(mzLow + width / 2), width));
            }
            return(isSimSpectrum);
        }
예제 #3
0
        private void TestReports(SrmDocument doc1, int row, double expectedDtWindow, string msg = null)
        {
            // Verify reports working for CCS
            var documentGrid = ShowDialog <DocumentGridForm>(() => SkylineWindow.ShowDocumentGrid(true));

            EnableDocumentGridColumns(documentGrid,
                                      Resources.SkylineViewContext_GetTransitionListReportSpec_Small_Molecule_Transition_List,
                                      doc1.PeptideTransitionCount * doc1.MeasuredResults.Chromatograms.Count,
                                      new[]
            {
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.CollisionalCrossSection",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityMS1",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityFragment",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityUnits",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityWindow"
            });

            CheckFieldByName(documentGrid, "IonMobilityMS1", row, _testCase == 1 ? 18.43 : 23.50, msg);
            CheckFieldByName(documentGrid, "IonMobilityFragment", row, (double?)null, msg); // Document is all precursor
            CheckFieldByName(documentGrid, "IonMobilityUnits", row, IonMobilityValue.GetUnitsString(eIonMobilityUnits.drift_time_msec), msg);
            CheckFieldByName(documentGrid, "IonMobilityWindow", row, expectedDtWindow, msg);
            CheckFieldByName(documentGrid, "CollisionalCrossSection", row, _testCase == 1 ? 292.4 : 333.34, msg);
            // And clean up after ourselves
            RunUI(() => documentGrid.Close());
        }
예제 #4
0
 public double?CCSFromIonMobility(IonMobilityValue ionMobilityValue, double mz, int charge)
 {
     if (_dataFile == null)
     {
         return(null);
     }
     return(_dataFile.CCSFromIonMobilityValue(ionMobilityValue, mz, charge));
 }
예제 #5
0
 /// <summary>
 /// Return a collisional cross section for this ion mobility at this mz, if reader supports this
 /// </summary>
 public double?CCSFromIonMobility(IonMobilityValue ionMobility, double mz, int charge)
 {
     if (_scanProvider == null)
     {
         return(null);
     }
     return(_scanProvider.CCSFromIonMobility(ionMobility, mz, charge));
 }
예제 #6
0
 public double CCSFromIonMobility(IonMobilityValue im, double mz, int charge)
 {
     if (ProvidesCollisionalCrossSectionConverter)
     {
         return(_ionMobilityFunctionsProvider.CCSFromIonMobility(im, mz, charge));
     }
     Assume.IsNotNull(_ionMobilityFunctionsProvider, "No ion mobility to CCS translation is possible for this data set"); // Not L10N
     return(0);
 }
예제 #7
0
 public bool ContainsIonMobilityValue(IonMobilityValue ionMobility, double highEnergyOffset)
 {
     if (!ionMobility.HasValue)
     {
         return(true); // It doesn't NOT have the ion mobility, since there isn't one
     }
     return((!MinIonMobilityValue.HasValue || MinIonMobilityValue.Value + highEnergyOffset <= ionMobility.Mobility) &&
            (!MaxIonMobilityValue.HasValue || MaxIonMobilityValue.Value + highEnergyOffset >= ionMobility.Mobility));
 }
예제 #8
0
        // TODO(bspratt) either upgrade this for all ion mobility types, or rip out this code altogether
        public IonMobilityAndCCS GetDriftTimeInfo(LibKey key, ChargeRegressionLine regression)
        {
            DbIonMobilityPeptide pep;

            if (DictLibrary.TryGetValue(key, out pep))
            {
                return(IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(regression.GetY(pep.CollisionalCrossSection), eIonMobilityUnits.drift_time_msec), pep.CollisionalCrossSection, pep.HighEnergyDriftTimeOffsetMsec));
            }
            return(null);
        }
예제 #9
0
        public Dictionary <LibKey, IonMobilityAndCCS> GetTableMeasuredIonMobility(bool useHighEnergyOffsets, MsDataFileImpl.eIonMobilityUnits units)
        {
            var e    = new CancelEventArgs();
            var dict = new Dictionary <LibKey, IonMobilityAndCCS>();

            foreach (DataGridViewRow row in _gridMeasuredDriftTimePeptides.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                string seq;
                if (!ValidateSequence(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_SEQUENCE], out seq))
                {
                    return(null);
                }

                Adduct charge;
                if (!ValidateCharge(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CHARGE], out charge))
                {
                    return(null);
                }

                double mobility;
                if (!ValidateDriftTime(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_ION_MOBILITY], out mobility))
                {
                    return(null);
                }

                double?ccs;
                if (!ValidateCCS(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CCS], out ccs))
                {
                    return(null);
                }

                double highEnergyOffset = 0; // Set default value in case user does not provide one
                if (useHighEnergyOffsets && !ValidateHighEnergyDriftTimeOffset(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET], out highEnergyOffset))
                {
                    return(null);
                }
                var ionMobility = IonMobilityValue.GetIonMobilityValue(mobility, units);
                try
                {
                    dict.Add(new LibKey(seq, charge.AdductCharge), IonMobilityAndCCS.GetIonMobilityAndCCS(ionMobility, ccs, highEnergyOffset));
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                    // just take the first seen
                }
            }
            return(dict);
        }
예제 #10
0
        public bool ContainsIonMobilityValue(IonMobilityValue ionMobility, bool highEnergy)
        {
            if (!ionMobility.HasValue)
            {
                return(true); // It doesn't NOT have the ion mobility, since there isn't one
            }
            double offset = highEnergy ? HighEnergyIonMobilityValueOffset : 0;

            return((!MinIonMobilityValue.HasValue || MinIonMobilityValue.Value + offset <= ionMobility.Mobility) &&
                   (!MaxIonMobilityValue.HasValue || MaxIonMobilityValue.Value + offset >= ionMobility.Mobility));
        }
예제 #11
0
 public IonMobilityFilter GetIonMobilityWindow()
 {
     if (MinIonMobilityValue.HasValue && MaxIonMobilityValue.HasValue)
     {
         // High energy (product ion) scans may have a faster ion mobility, as in Waters MsE, that gets applied elsewhere
         var width  = MaxIonMobilityValue.Value - MinIonMobilityValue.Value;
         var center = MinIonMobilityValue.Value + 0.5 * width;
         return(IonMobilityFilter.GetIonMobilityFilter(IonMobilityValue.GetIonMobilityValue(center, IonMobilityInfo.IonMobility.Units), width, IonMobilityInfo.CollisionalCrossSectionSqA));
     }
     else
     {
         return(IonMobilityFilter.EMPTY);
     }
 }
예제 #12
0
 public IonMobilityFilter GetIonMobilityWindow(bool highEnergy)
 {
     if (MinIonMobilityValue.HasValue && MaxIonMobilityValue.HasValue)
     {
         // High energy (product ion) scans may have a faster ion mobility, as in Waters MsE
         double offset = highEnergy ? HighEnergyIonMobilityValueOffset : 0;
         var    width  = MaxIonMobilityValue.Value - MinIonMobilityValue.Value;
         var    center = offset + MinIonMobilityValue.Value + 0.5 * width;
         return(IonMobilityFilter.GetIonMobilityFilter(IonMobilityValue.GetIonMobilityValue(center, IonMobilityInfo.IonMobility.Units), width, IonMobilityInfo.CollisionalCrossSectionSqA));
     }
     else
     {
         return(IonMobilityFilter.EMPTY);
     }
 }
예제 #13
0
        private void TestReports(SrmDocument doc1, string msg = null)
        {
            // Verify reports working for CCS
            var row          = 0;
            var documentGrid = ShowDialog <DocumentGridForm>(() => SkylineWindow.ShowDocumentGrid(true));

            EnableDocumentGridColumns(documentGrid,
                                      Resources.SkylineViewContext_GetTransitionListReportSpec_Small_Molecule_Transition_List,
                                      doc1.PeptideTransitionCount,
                                      new[]
            {
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.CollisionalCrossSection",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityMS1",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityFragment",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityUnits",
                "Proteins!*.Peptides!*.Precursors!*.Results!*.Value.IonMobilityWindow"
            });
            CheckFieldByName(documentGrid, "PrecursorResult.IonMobilityMS1", row, 1.1732, msg);
            CheckFieldByName(documentGrid, "PrecursorResult.IonMobilityFragment", row, 1.1732, msg);
            CheckFieldByName(documentGrid, "PrecursorResult.IonMobilityUnits", row, IonMobilityValue.GetUnitsString(eIonMobilityUnits.inverse_K0_Vsec_per_cm2), msg);
            CheckFieldByName(documentGrid, "PrecursorResult.IonMobilityWindow", row, 0.12, msg);
            CheckFieldByName(documentGrid, "PrecursorResult.CollisionalCrossSection", row, 666.9175, msg);
            EnableDocumentGridColumns(documentGrid,
                                      Resources.ReportSpecList_GetDefaults_Peptide_RT_Results,
                                      doc1.PeptideCount * doc1.MeasuredResults.Chromatograms.Count, null);
            foreach (var rt in new[] {
                14.35, 14.34, 14.33, 14.33, 14.15, 14.12, 14.11, 14.11, 14.63, 14.61, 14.61, 14.61, 14.75, 14.74, 14.72, 14.73, 14.06, 14.04,
                14.03, 14.03, 14.43, 14.43, 14.42, 14.43, 14.36, 14.37, 14.35, 14.35, 14.31, 14.31, 14.29, 14.28, 14.48, 14.49, 14.47, 14.48,
                14.69, 14.67, 14.67, 14.67, 14.61, 14.34, 14.34, 14.35, 14.25, 14.25, 14.22, 14.23, 14.37, 14.36, 14.35, 14.35, 14.51, 14.52,
                14.5, 14.5, 14.24, 14.25, 14.22, 14.23, 14.81, 14.78, 14.78, 14.78, 14.63, 14.61, 14.61, 14.61, 14.48, 14.46, 14.46, 14.47,
                14.52, 14.49, 14.49, 14.49, 14.67, 14.65, 14.65, 14.65, 14.46, 14.45, 14.45, 14.45, 14.44, 14.43, 14.42, 14.43, 14.24, 14.24,
                14.25, 14.25, 14.48, 14.46, 14.45, 14.44, 14.19, 14.16, 14.16, 14.17, 14.38, 14.34, 14.34, 14.36, 14.88, 14.86, 14.86, 14.85,
                14.22, 14.22, 14.21, 14.21, 14.19, 14.19, 14.18, 14.18, 14.11, 14.09, 14.09, 14.1, 14.72, 14.7, 14.71, 14.71, 14.64, 14.61,
                14.62, 14.61, 14.12, 14.1, 14.1, 14.1, 14.23, 14.21, 14.2, 14.2
            })
            {
                CheckFieldByName(documentGrid, "PeptideRetentionTime", row++, rt, msg, true);
            }

            // And clean up after ourselves
            RunUI(() => documentGrid.Close());
        }
예제 #14
0
        private MsDataSpectrum GetSpectrumFromJObject(JObject jObject, int msLevel)
        {
            // ReSharper disable NonLocalizedString
            string strMzs         = jObject["mzs-base64"].ToString();
            string strIntensities = jObject["intensities-base64"].ToString();

            byte[]   mzBytes        = Convert.FromBase64String(strMzs);
            byte[]   intensityBytes = Convert.FromBase64String(strIntensities);
            double[] mzs            = PrimitiveArrays.FromBytes <double>(
                PrimitiveArrays.ReverseBytesInBlocks(mzBytes, sizeof(double)));
            float[] intensityFloats = PrimitiveArrays.FromBytes <float>(
                PrimitiveArrays.ReverseBytesInBlocks(intensityBytes, sizeof(float)));
            double[]         intensities = intensityFloats.Select(f => (double)f).ToArray();
            IonMobilityValue ionMobility = IonMobilityValue.EMPTY;
            JToken           jDriftTime;

            if (jObject.TryGetValue("driftTime", out jDriftTime))
            {
                var driftTime = jDriftTime.ToObject <double>();
                if (driftTime != 0)
                {
                    ionMobility = IonMobilityValue.GetIonMobilityValue(driftTime, MsDataFileImpl.eIonMobilityUnits.drift_time_msec);
                }
            }
            MsDataSpectrum spectrum = new MsDataSpectrum
            {
                Index         = jObject["index"].ToObject <int>(),
                RetentionTime = jObject["rt"].ToObject <double>(),
                Mzs           = mzs,
                Intensities   = intensities,
                IonMobility   = ionMobility,
            };

            return(spectrum);
            // ReSharper restore NonLocalizedString
        }
예제 #15
0
        public Dictionary <LibKey, IonMobilityAndCCS> GetTableMeasuredIonMobility(bool useHighEnergyOffsets, eIonMobilityUnits units)
        {
            var e    = new CancelEventArgs();
            var dict = new Dictionary <LibKey, IonMobilityAndCCS>();

            foreach (DataGridViewRow row in _gridMeasuredDriftTimePeptides.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                string seq;
                if (!ValidateSequence(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_SEQUENCE], out seq))
                {
                    return(null);
                }

                // OK, we have a non-empty "sequence" string, but is that actually a peptide or a molecule?
                // See if there's anything in the document whose text representation matches what's in the list

                var target = _targetResolver.ResolveTarget(seq);
                if (target == null || target.IsEmpty)
                {
                    return(null);
                }

                Adduct charge;
                if (!ValidateCharge(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CHARGE], target.IsProteomic, out charge))
                {
                    return(null);
                }

                double mobility;
                if (!ValidateDriftTime(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_ION_MOBILITY], out mobility))
                {
                    return(null);
                }

                double?ccs;
                if (!ValidateCCS(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CCS], out ccs))
                {
                    return(null);
                }

                double highEnergyOffset = 0; // Set default value in case user does not provide one
                if (useHighEnergyOffsets && !ValidateHighEnergyDriftTimeOffset(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET], out highEnergyOffset))
                {
                    return(null);
                }
                var ionMobility = IonMobilityValue.GetIonMobilityValue(mobility, units);
                try
                {
                    dict.Add(new LibKey(target, charge), IonMobilityAndCCS.GetIonMobilityAndCCS(ionMobility, ccs, highEnergyOffset));
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                    // just take the first seen
                }
            }
            return(dict);
        }
예제 #16
0
 public virtual IonMobilityAndCCS GetIonMobilityAndCCS()
 {
     return(IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(IonMobilityNullable,
                                                                                        IonMobilityUnits), CollisionalCrossSectionNullable, HighEnergyIonMobilityOffset));
 }
예제 #17
0
        private void EvaluateBestIonMobilityValue(int msLevel, LibKey libKey, float tolerance, List <TransitionFullScanInfo> transitions)
        {
            IonMobilityValue ionMobilityValue = IonMobilityValue.EMPTY;
            double           maxIntensity     = 0;

            // Avoid picking MS2 ion mobility values wildly different from MS1 valuess
            IonMobilityValue ms1IonMobilityBest;

            if ((msLevel == 2) && _ms1IonMobilities.ContainsKey(libKey))
            {
                ms1IonMobilityBest =
                    _ms1IonMobilities[libKey].OrderByDescending(p => p.Intensity)
                    .FirstOrDefault()
                    .IonMobility.IonMobility;
            }
            else
            {
                ms1IonMobilityBest = IonMobilityValue.EMPTY;
            }

            double maxHighEnergyDriftOffsetMsec = UseHighEnergyOffset ? 2 : 0; // CONSIDER(bspratt): user definable? or dynamically set by looking at scan to scan drift delta? Or resolving power?

            foreach (var scan in _msDataFileScanHelper.MsDataSpectra.Where(scan => scan != null))
            {
                if (!scan.IonMobility.HasValue || !scan.Mzs.Any())
                {
                    continue;
                }
                if (ms1IonMobilityBest.HasValue &&
                    (scan.IonMobility.Mobility <
                     ms1IonMobilityBest.Mobility - maxHighEnergyDriftOffsetMsec ||
                     scan.IonMobility.Mobility >
                     ms1IonMobilityBest.Mobility + maxHighEnergyDriftOffsetMsec))
                {
                    continue;
                }

                // Get the total intensity for all transitions of current msLevel
                double totalIntensity = 0;
                foreach (var t in transitions)
                {
                    Assume.IsTrue(t.ProductMz.IsNegative == scan.NegativeCharge);  // It would be strange if associated scan did not have same polarity
                    var mzPeak  = t.ProductMz;
                    var halfwin = (t.ExtractionWidth ?? tolerance) / 2;
                    var mzLow   = mzPeak - halfwin;
                    var mzHigh  = mzPeak + halfwin;
                    var first   = Array.BinarySearch(scan.Mzs, mzLow);
                    if (first < 0)
                    {
                        first = ~first;
                    }
                    for (var i = first; i < scan.Mzs.Length; i++)
                    {
                        if (scan.Mzs[i] > mzHigh)
                        {
                            break;
                        }
                        totalIntensity += scan.Intensities[i];
                    }
                }
                if (maxIntensity < totalIntensity)
                {
                    ionMobilityValue = scan.IonMobility;
                    maxIntensity     = totalIntensity;
                }
            }
            if (ionMobilityValue.HasValue)
            {
                var dict   = (msLevel == 1) ? _ms1IonMobilities : _ms2IonMobilities;
                var ccs    = msLevel == 1 && _msDataFileScanHelper.ProvidesCollisionalCrossSectionConverter ? _msDataFileScanHelper.CCSFromIonMobility(ionMobilityValue, transitions.First().PrecursorMz, libKey.Charge) : null;
                var result = new IonMobilityIntensityPair
                {
                    IonMobility = IonMobilityAndCCS.GetIonMobilityAndCCS(ionMobilityValue, ccs, 0),
                    Intensity   = maxIntensity
                };
                List <IonMobilityIntensityPair> listPairs;
                if (!dict.TryGetValue(libKey, out listPairs))
                {
                    listPairs = new List <IonMobilityIntensityPair>();
                    dict.Add(libKey, listPairs);
                }
                listPairs.Add(result);
            }
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        protected override void DoTest()
        {
            // IsPauseForScreenShots = true; // For a quick demo when you need it
            string skyFile = TestFilesDir.GetTestPath("test_measured_drift_times_perf.sky");

            Program.ExtraRawFileSearchFolder = TestFilesDir.PersistentFilesDir; // So we don't have to reload the raw files, which have moved relative to skyd file
            RunUI(() => SkylineWindow.OpenFile(skyFile));

            var document = WaitForDocumentLoaded(240000);  // If it decides to remake chromatograms this can take awhile

            AssertEx.IsDocumentState(document, null, 1, 34, 38, 398);
            RunUI(() =>
            {
                SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("local.sky")); // Avoid "document changed since last edit" message
                document = SkylineWindow.DocumentUI;
            });
            List <ValidatingIonMobilityPrecursor> curatedDTs = null;
            var measuredDTs = new List <List <ValidatingIonMobilityPrecursor> >();
            var precursors  = new LibKeyIndex(document.MoleculePrecursorPairs.Select(
                                                  p => p.NodePep.ModifiedTarget.GetLibKey(p.NodeGroup.PrecursorAdduct).LibraryKey));

            PauseForScreenShot(@"Legacy ion mobility values loaded, placed in .imsdb database file"); // For a quick demo when you need it
            for (var pass = 0; pass < 2; pass++)
            {
                // Verify ability to extract predictions from raw data
                var transitionSettingsDlg = ShowDialog <TransitionSettingsUI>(
                    () => SkylineWindow.ShowTransitionSettingsUI(TransitionSettingsUI.TABS.IonMobility));
                PauseForScreenShot("new Transition Settings tab"); // For a quick demo when you need it
                // Simulate user picking Edit Current from the Ion Mobility Library combo control
                var ionMobilityLibraryDlg = ShowDialog <EditIonMobilityLibraryDlg>(transitionSettingsDlg.IonMobilityControl.EditIonMobilityLibrary);
                PauseForScreenShot("next, we'll update values with 'Use Results' button"); // For a quick demo when you need it
                RunUI(() =>
                {
                    if (curatedDTs == null)
                    {
                        curatedDTs = ionMobilityLibraryDlg.LibraryMobilitiesFlat.ToList();
                    }
                    ionMobilityLibraryDlg.SetOffsetHighEnergySpectraCheckbox(true);
                    ionMobilityLibraryDlg.GetIonMobilitiesFromResults();
                });
                PauseForScreenShot("values updated");// For a quick demo when you need it
                RunUI(() =>
                {
                    measuredDTs.Add(ionMobilityLibraryDlg.LibraryMobilitiesFlat.ToList());
                    ionMobilityLibraryDlg.OkDialog();
                });
                WaitForClosedForm(ionMobilityLibraryDlg);
                RunUI(() =>
                {
                    transitionSettingsDlg.OkDialog();
                });
                WaitForClosedForm(transitionSettingsDlg);

                document = SkylineWindow.Document;
                var count = 0;
                for (var n = 0; n < curatedDTs.Count; n++)
                {
                    var cdt         = curatedDTs[n];
                    var key         = cdt.Precursor;
                    var indexM      = measuredDTs[pass].FindIndex(m => m.Precursor.Equals(key));
                    var measured    = measuredDTs[pass][indexM];
                    var measuredDT  = measured.IonMobility;
                    var measuredHEO = measured.HighEnergyIonMobilityOffset;
                    if (precursors.ItemsMatching(key, true).Any())
                    {
                        count++;
                        AssertEx.AreNotEqual(cdt.IonMobility, measuredDT, "measured drift time should differ somewhat for " + measured.Precursor);
                    }

                    AssertEx.AreEqual(cdt.IonMobility, measuredDT, 1.0, "measured drift time differs too much for " + key);
                    AssertEx.AreEqual(cdt.HighEnergyIonMobilityOffset, measuredHEO, 2.0, "measured drift time high energy offset differs too much for " + key);
                }
                AssertEx.AreEqual(document.MoleculeTransitionGroupCount, count, "did not find drift times for all precursors"); // Expect to find a value for each precursor

                if (pass == 1)
                {
                    break;
                }

                // Verify that we select based on strongest results by removing the training set and relying on the other noisier set
                RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
                {
                    var chromatograms         = document.Settings.MeasuredResults.Chromatograms;
                    var chromTraining         = chromatograms[0];
                    var chroms                = new[] { chromTraining };
                    dlg.SelectedChromatograms = chroms; // Passing this chromatograms[0] results in the other set being deleted - compiler problem?
                    dlg.RemoveReplicates();
                    dlg.OkDialog();
                });

                document = WaitForDocumentChange(document);
                AssertEx.AreEqual(1, document.Settings.MeasuredResults.Chromatograms.Count);
            }
            // Results should be slightly different without the training set of chromatograms to contain a potentially stronger peak
            var ccount   = 0;
            var noChange = new List <LibKey>();

            for (var n = 0; n < measuredDTs[0].Count; n++)
            {
                var validatingIonMobilityPeptide0 = measuredDTs[0][n];
                var validatingIonMobilityPeptide1 = measuredDTs[1][n];
                var key = measuredDTs[0][n].Precursor;
                if (precursors.ItemsMatching(key, true).Any())
                {
                    ccount++;
                    if (validatingIonMobilityPeptide0.HighEnergyIonMobilityOffset == validatingIonMobilityPeptide1.HighEnergyIonMobilityOffset)
                    {
                        noChange.Add(key);
                    }
                }
                AssertEx.AreEqual(validatingIonMobilityPeptide0.IonMobility, validatingIonMobilityPeptide1.IonMobility, 1.0, "averaged measured drift time differs for " + key);
                AssertEx.AreEqual(validatingIonMobilityPeptide0.HighEnergyIonMobilityOffset, validatingIonMobilityPeptide1.HighEnergyIonMobilityOffset, 2.0, "averaged measured drift time high energy offset differs for " + key);
                AssertEx.AreEqual(validatingIonMobilityPeptide0.CollisionalCrossSectionSqA, validatingIonMobilityPeptide1.CollisionalCrossSectionSqA, 1.0, "averaged measured CCS differs for " + key);
            }
            AssertEx.AreEqual(document.MoleculeTransitionGroupCount, ccount, "did not find drift times for all precursors"); // Expect to find a value for each precursor
            AssertEx.IsTrue(noChange.Count < ccount / 2, "expected most values to shift a little without the nice clean training data");


            // And finally verify ability to reimport with altered drift filter (would formerly fail on an erroneous Assume)

            // Simulate user picking Edit Current from the Ion Mobility Library combo control, and messing with all the measured drift time values
            var transitionSettingsDlg2 = ShowDialog <TransitionSettingsUI>(
                () => SkylineWindow.ShowTransitionSettingsUI(TransitionSettingsUI.TABS.Prediction));
            var editIonMobilityLibraryDlg = ShowDialog <EditIonMobilityLibraryDlg>(transitionSettingsDlg2.IonMobilityControl.EditIonMobilityLibrary);

            RunUI(() =>
            {
                var revised = new List <ValidatingIonMobilityPrecursor>();
                foreach (var item in editIonMobilityLibraryDlg.LibraryMobilitiesFlat)
                {
                    var im  = item.IonMobility;
                    var heo = item.HighEnergyIonMobilityOffset;
                    revised.Add(new ValidatingIonMobilityPrecursor(item.Precursor,
                                                                   IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(im * 1.02, item.IonMobilityUnits),
                                                                                                          item.CollisionalCrossSectionSqA * 1.02, heo * 1.02)));
                }
                editIonMobilityLibraryDlg.LibraryMobilitiesFlat = revised;
                editIonMobilityLibraryDlg.OkDialog();
            });
            WaitForClosedForm(editIonMobilityLibraryDlg);
            RunUI(() =>
            {
                transitionSettingsDlg2.OkDialog();
            });
            WaitForClosedForm(transitionSettingsDlg2);
            var docChangedDriftTimePredictor = WaitForDocumentChange(document);

            // Reimport data for a replicate - without the fix this will throw
            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                var chromatograms         = docChangedDriftTimePredictor.Settings.MeasuredResults.Chromatograms;
                dlg.SelectedChromatograms = new[] { chromatograms[0] };
                dlg.ReimportResults();
                dlg.OkDialog();
            });

            WaitForDocumentChangeLoaded(docChangedDriftTimePredictor, WAIT_TIME * 2);
        }
예제 #21
0
        private void PerformTestMeasuredDriftValues(bool asSmallMolecules)
        {
            if (asSmallMolecules)
            {
                if (!RunSmallMoleculeTestVersions)
                {
                    Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                    return;
                }
                TestSmallMolecules = false;                                                          // No need to add the magic small molecule test node
            }
            var testFilesDir = new TestFilesDir(TestContext, @"Test\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;
                document = document.ChangeSettings(document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, IonMobilityPredictor.EMPTY)));

                // Verify ability to extract predictions from raw data
                var newPred = document.Settings.PeptideSettings.Prediction.IonMobilityPredictor.ChangeMeasuredIonMobilityValuesFromResults(
                    document, docContainer.DocumentFilePath);
                var result = newPred.MeasuredMobilityIons;
                Assert.AreEqual(TestSmallMolecules ? 2 : 1, result.Count);
                const double expectedDT     = 4.0019;
                var          expectedOffset = .4829;
                Assert.AreEqual(expectedDT, result.Values.First().IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result.Values.First().HighEnergyIonMobilityValueOffset, .001);

                // Check ability to update, and to preserve unchanged
                var revised = new Dictionary <LibKey, IonMobilityAndCCS>();
                var libKey  = result.Keys.First();
                revised.Add(libKey, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(4, eIonMobilityUnits.drift_time_msec), null, 0.234));  // N.B. CCS handling would require actual raw data in this test, it's covered in a perf test
                var libKey2 = new LibKey("DEADEELS", asSmallMolecules ? Adduct.NonProteomicProtonatedFromCharge(2) : Adduct.DOUBLY_PROTONATED);
                revised.Add(libKey2, IonMobilityAndCCS.GetIonMobilityAndCCS(IonMobilityValue.GetIonMobilityValue(5, eIonMobilityUnits.drift_time_msec), null, 0.123));
                document =
                    document.ChangeSettings(
                        document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, new IonMobilityPredictor("test", revised, null, null, IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.resolving_power, 40, 0, 0))));
                newPred = document.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor(
                    document.Settings.PeptideSettings.Prediction.IonMobilityPredictor.ChangeMeasuredIonMobilityValuesFromResults(
                        document, docContainer.DocumentFilePath)).IonMobilityPredictor;
                result = newPred.MeasuredMobilityIons;
                Assert.AreEqual(TestSmallMolecules ? 3 : 2, result.Count);
                Assert.AreEqual(expectedDT, result[libKey].IonMobility.Mobility.Value, .001);
                Assert.AreEqual(expectedOffset, result[libKey].HighEnergyIonMobilityValueOffset, .001);
                Assert.AreEqual(5, result[libKey2].IonMobility.Mobility.Value, .001);
                Assert.AreEqual(0.123, result[libKey2].HighEnergyIonMobilityValueOffset, .001);
            }
        }
예제 #22
0
 public bool ContainsIonMobilityValue(IonMobilityValue ionMobility, double highEnergyOffset)
 {
     return(!ionMobility.HasValue || ContainsIonMobilityValue(ionMobility.Mobility.Value, highEnergyOffset));
 }
예제 #23
0
        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);
            }
        }
예제 #24
0
        public Dictionary <LibKey, IonMobilityAndCCS> GetTableMeasuredIonMobility(bool useHighEnergyOffsets, eIonMobilityUnits units)
        {
            var e    = new CancelEventArgs();
            var dict = new Dictionary <LibKey, IonMobilityAndCCS>();

            foreach (DataGridViewRow row in _gridMeasuredDriftTimePeptides.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                string seq;
                if (!ValidateSequence(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_SEQUENCE], out seq))
                {
                    return(null);
                }

                // OK, we have a non-empty "sequence" string, but is that actually a peptide or a molecule?
                // See if there's anything in the document whose text representation matches what's in the list
                var target = Program.MainWindow.Document.Molecules.Select(m => m.Target).FirstOrDefault(t => seq.Equals(t.ToString()));
                if (target == null || target.IsEmpty)
                {
                    // Does seq evaluate as a peptide?
                    target = !seq.All(c => char.IsUpper(c) || char.IsDigit(c) || @"[+-,.]()".Contains(c))
                        ? new Target(CustomMolecule.FromSerializableString(seq))
                        : Target.FromSerializableString(seq);
                }

                Adduct charge;
                if (!ValidateCharge(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CHARGE], target.IsProteomic, out charge))
                {
                    return(null);
                }

                double mobility;
                if (!ValidateDriftTime(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_ION_MOBILITY], out mobility))
                {
                    return(null);
                }

                double?ccs;
                if (!ValidateCCS(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_CCS], out ccs))
                {
                    return(null);
                }

                double highEnergyOffset = 0; // Set default value in case user does not provide one
                if (useHighEnergyOffsets && !ValidateHighEnergyDriftTimeOffset(e, row.Cells[EditDriftTimePredictorDlg.COLUMN_HIGH_ENERGY_OFFSET], out highEnergyOffset))
                {
                    return(null);
                }
                var ionMobility = IonMobilityValue.GetIonMobilityValue(mobility, units);
                try
                {
                    dict.Add(new LibKey(target, charge), IonMobilityAndCCS.GetIonMobilityAndCCS(ionMobility, ccs, highEnergyOffset));
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                    // just take the first seen
                }
            }
            return(dict);
        }
예제 #25
0
 public double?CCSFromIonMobility(IonMobilityValue ionMobilityValue, double mz, int charge)
 {
     return(null); // Unsupported
 }