Example #1
0
        public static void MakeChromatogramInfo(SignedMz precursorMz, LibraryChromGroup chromGroup, LibraryChromGroup.ChromData chromData, out ChromatogramInfo chromatogramInfo, out TransitionChromInfo transitionChromInfo)
        {
            var crawPeakFinder = Crawdads.NewCrawdadPeakFinder();

            crawPeakFinder.SetChromatogram(chromGroup.Times, chromData.Intensities);
            var crawdadPeak =
                crawPeakFinder.GetPeak(
                    FindNearestIndex(chromGroup.Times, (float)chromGroup.StartTime),
                    FindNearestIndex(chromGroup.Times, (float)chromGroup.EndTime));
            var chromPeak = new ChromPeak(crawPeakFinder, crawdadPeak, 0, chromGroup.Times, chromData.Intensities, null);

            transitionChromInfo = new TransitionChromInfo(null, 0, chromPeak, new float?[0], Annotations.EMPTY,
                                                          UserSet.FALSE);
            var peaks  = new[] { chromPeak };
            var header = new ChromGroupHeaderInfo(precursorMz,
                                                  0,                       // file index
                                                  1,                       // numTransitions
                                                  0,                       // startTransitionIndex
                                                  peaks.Length,            // numPeaks
                                                  0,                       // startPeakIndex
                                                  0,                       // startscoreindex
                                                  0,                       // maxPeakIndex
                                                  chromGroup.Times.Length, // numPoints
                                                  0,                       // compressedSize
                                                  0,                       // uncompressedsize
                                                  0,                       //location
                                                  0, -1, -1, null, null);

            chromatogramInfo = new ChromatogramInfo(header,
                                                    new Dictionary <Type, int>(), 0,
                                                    new ChromCachedFile[0],
                                                    new[] { new ChromTransition(chromData.Mz, 0, 0, 0, ChromSource.unknown), },
                                                    peaks, null,
                                                    chromGroup.Times, new[] { chromData.Intensities }, null, null);
        }
Example #2
0
        private int IndexOfFilter(SignedMz precursorMz, double window, int left, int right)
        {
            // Binary search for the right precursorMz
            if (left > right)
            {
                return(-1);
            }
            int mid     = (left + right) / 2;
            int compare = CompareMz(precursorMz, _filterMzValues[mid].Q1, window);

            if (compare < 0)
            {
                return(IndexOfFilter(precursorMz, window, left, mid - 1));
            }
            if (compare > 0)
            {
                return(IndexOfFilter(precursorMz, window, mid + 1, right));
            }

            // Scan backward until the first matching element is found.
            while (mid > 0 && CompareMz(precursorMz, _filterMzValues[mid - 1].Q1, window) == 0)
            {
                mid--;
            }

            return(mid);
        }
Example #3
0
        /// <summary>
        /// Return doc node for a peptide associated with a given precursor Mz.  May return
        /// null if the precursor Mz lies outside the matching tolerance setting.
        /// </summary>
        public PeptideDocNode FindPeptide(SignedMz precursorMz)
        {
            if (_precursorMzPeptideList.Count == 0)
            {
                return(null);
            }

            // Find closest precursor Mz match.
            var lookup = new PeptidePrecursorMz(null, precursorMz);
            int i      = _precursorMzPeptideList.BinarySearch(lookup, PeptidePrecursorMz.COMPARER);

            if (i < 0)
            {
                i = ~i;
                if (i >= _precursorMzPeptideList.Count)
                {
                    i = _precursorMzPeptideList.Count - 1;
                }
                else if (i > 0 &&
                         precursorMz - _precursorMzPeptideList[i - 1].PrecursorMz <
                         _precursorMzPeptideList[i].PrecursorMz - precursorMz)
                {
                    i--;
                }
            }
            var closestMatch = _precursorMzPeptideList[i];

            // Return color seed only if the match is within allowed tolerance.
            return(Math.Abs(closestMatch.PrecursorMz - precursorMz) > _mzMatchTolerance
                ? null
                : closestMatch.NodePeptide);
        }
Example #4
0
        public MsDataSpectrum[] GetMsDataFileSpectraWithCommonRetentionTime(int dataFileSpectrumStartIndex)
        {
            SignedMz      precursor     = Transitions.Select(transition => transition.PrecursorMz).FirstOrDefault();
            ChorusAccount chorusAccount = ChorusUrl.FindChorusAccount(Settings.Default.ChorusAccountList);

            return(_chorusSession.GetSpectra(chorusAccount, ChorusUrl, Source, precursor, dataFileSpectrumStartIndex));
        }
Example #5
0
 public TransitionDocNode(Transition id,
                          Annotations annotations,
                          TransitionLosses losses,
                          double massH,
                          TransitionIsotopeDistInfo isotopeDistInfo,
                          TransitionLibInfo libInfo,
                          Results <TransitionChromInfo> results)
     : base(id, annotations)
 {
     Losses = losses;
     if (losses != null)
     {
         massH -= losses.Mass;
     }
     if (id.IsCustom())
     {
         Mz = new SignedMz(BioMassCalc.CalculateIonMz(massH, id.Charge), id.IsNegative());
     }
     else
     {
         Mz = new SignedMz(SequenceMassCalc.GetMZ(massH, id.Charge) + SequenceMassCalc.GetPeptideInterval(id.DecoyMassShift), id.IsNegative());
     }
     IsotopeDistInfo = isotopeDistInfo;
     LibInfo         = libInfo;
     Results         = results;
 }
Example #6
0
 public PrecursorTextId(SignedMz precursorMz, IonMobilityFilter ionMobilityFilter, Target target, ChromExtractor extractor) : this()
 {
     PrecursorMz = precursorMz;
     IonMobility = ionMobilityFilter ?? IonMobilityFilter.EMPTY;
     Target      = target;
     Extractor   = extractor;
 }
Example #7
0
        public MsDataSpectrum[] GetSpectra(ChorusUrl chorusUrl, ChromSource source,
                                           SignedMz precursor, int scanId)
        {
            string strSource;
            int    msLevel = 1;

            // ReSharper disable NonLocalizedString
            switch (source)
            {
            case ChromSource.ms1:
                strSource = "ms1";
                break;

            case ChromSource.sim:
                strSource = "sim";
                break;

            case ChromSource.fragment:
                strSource = "ms2";
                msLevel   = 2;
                break;

            default:
                throw new ArgumentException("Unknown source " + source);
            }

            string strUri = string.Format(CultureInfo.InvariantCulture,
                                          "{0}/skyline/api/chroextract-drift/file/{1}/source/{2}/precursor/{3}/{4}",
                                          chorusUrl.ServerUrl,
                                          chorusUrl.FileId,
                                          strSource,
                                          precursor.RawValue, // This will be a negative value for negative ion mode data
                                          scanId);
            // ReSharper restore NonLocalizedString

            var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(strUri));

            AddAuthHeader(ChorusAccount, webRequest);
            return(SendRequest(webRequest, response =>
            {
                string strResponse = string.Empty;
                var responseStream = response.GetResponseStream();
                if (null != responseStream)
                {
                    var streamReader = new StreamReader(responseStream);
                    strResponse = streamReader.ReadToEnd();
                }
                JObject jObject = JsonConvert.DeserializeObject <JObject>(strResponse);
                JArray array = (JArray)jObject["results"];  // Not L10N
                return array.OfType <JObject>().Select(obj => GetSpectrumFromJObject(obj, msLevel)).ToArray();
            }));
        }
Example #8
0
        public void SignedMzUnitTest()
        {
            var zero = new SignedMz(0, false);

            Assert.AreEqual(zero, SignedMz.ZERO);
//            var zeroNeg = new SignedMz(0, true);
//            Assert.AreNotEqual(zeroNeg, SignedMz.ZERO);
            var neg = new SignedMz(-9.0);  // For deserialization (note single ctor arg) - a negative value is taken to mean negative polarity

            Assert.AreEqual(9.0, neg.Value);
            Assert.IsTrue(neg.IsNegative);

            for (var loop = 0; loop < 2; loop++)
            {
                var negative = loop > 0;
                var one      = new SignedMz(1, negative);
                var two      = new SignedMz(2, negative);
                var three    = new SignedMz(3, negative);
                Assert.AreEqual(one, new SignedMz(-1, negative));  // The notion of ion polarity is unaffected by the sign of the mz value, since we can do addition and subtraction on these
                if (negative)
                {
                    Assert.AreEqual(one, new SignedMz(-1));
                }
                else
                {
                    Assert.AreNotEqual(one, new SignedMz(-1));
                }
                Assert.AreEqual(negative, one.IsNegative);
                Assert.AreEqual(2, two.Value);
                Assert.AreEqual(negative ? -2 : 2, two.RawValue);
                Assert.AreEqual(three, one + two);
                Assert.AreEqual(one, three - two);
                Assert.AreEqual(one, two - three);  // Subtraction always results in an absolute value with the original sign
                Assert.AreEqual(one, three - 2);
                Assert.AreEqual(three, one + 2);
                Assert.IsTrue(three > one);
                Assert.IsFalse(three < one);
                Assert.IsTrue(three == one + two);
                Assert.IsFalse(three != one + two);
                var bad = new SignedMz(1, !negative);
                AssertEx.ThrowsException <InvalidOperationException>(() => one + bad); // Mixed-polarity math is meaningless
                AssertEx.ThrowsException <InvalidOperationException>(() => one - bad);
                Assert.AreEqual(three, three + SignedMz.ZERO);                         // Make sure adding or subtracting zero always works
                Assert.AreEqual(three, three - SignedMz.ZERO);
                Assert.AreEqual(three, SignedMz.ZERO + three);
                Assert.AreEqual(three, SignedMz.ZERO - three);
                Assert.AreEqual(SignedMz.ZERO, SignedMz.ZERO + SignedMz.ZERO);
                Assert.AreEqual(SignedMz.ZERO, SignedMz.ZERO - SignedMz.ZERO);
                Assert.AreEqual(SignedMz.ZERO, three - three);
            }
        }
Example #9
0
        public void SignedMzUnitTest()
        {
            var empty = new SignedMz(null, false);

            Assert.AreEqual(empty, SignedMz.EMPTY);
            Assert.AreEqual(((double?)null).GetHashCode(), empty.GetHashCode());
            Assert.IsFalse(empty.HasValue);
            var zero    = new SignedMz(0, false);
            var zeroNeg = new SignedMz(0, true);

            Assert.AreEqual(zero, SignedMz.ZERO);
            Assert.AreNotEqual(zeroNeg, SignedMz.ZERO);
            AssertEx.ThrowsException <Exception>(() => zero.Value == empty.Value);
            var neg = new SignedMz(-9.0);  // For deserialization (note single ctor arg) - a negative value is taken to mean negative polarity

            Assert.AreEqual(9.0, neg.Value);
            Assert.IsTrue(neg.IsNegative);

            for (var loop = 0; loop < 2; loop++)
            {
                var negative = loop > 0;
                var one      = new SignedMz(1, negative);
                var two      = new SignedMz(2, negative);
                var three    = new SignedMz(3, negative);
                var minusOne = new SignedMz(-1, negative);  // The notion of ion polarity is unaffected by the sign of the mz value, since we can do addition and subtraction on these
                Assert.AreEqual(negative, minusOne.IsNegative);
                Assert.AreEqual(negative, one.IsNegative);
                Assert.AreEqual(2, two.Value);
                Assert.AreEqual(negative ? -2 : 2, two.RawValue);
                Assert.AreEqual(negative ? 1 : -1, minusOne.RawValue);
                Assert.AreEqual(three, one + two);
                Assert.AreEqual(two, three + minusOne);
                Assert.AreEqual(one, three - two);
                Assert.AreEqual(-1.0, two - three);
                Assert.AreEqual(minusOne, two - three);
                Assert.AreEqual(one, three - 2);
                Assert.AreEqual(three, one + 2);
                Assert.IsTrue(three > one);
                Assert.IsFalse(three < one);
                Assert.IsTrue(three == one + two);
                Assert.IsFalse(three != one + two);
                var bad = new SignedMz(1, !negative);
                AssertEx.ThrowsException <InvalidOperationException>(() => one + bad);  // Mixed-polarity math is meaningless
                AssertEx.ThrowsException <InvalidOperationException>(() => one - bad);
            }
        }
Example #10
0
        public static void MakeChromatogramInfo(SignedMz precursorMz, LibraryChromGroup chromGroup, LibraryChromGroup.ChromData chromData, out ChromatogramInfo chromatogramInfo, out TransitionChromInfo transitionChromInfo)
        {
            var timeIntensities = new TimeIntensities(chromGroup.Times, chromData.Intensities, null, null);
            var crawPeakFinder  = Crawdads.NewCrawdadPeakFinder();

            crawPeakFinder.SetChromatogram(chromGroup.Times, chromData.Intensities);
            var crawdadPeak =
                crawPeakFinder.GetPeak(
                    FindNearestIndex(chromGroup.Times, (float)chromGroup.StartTime),
                    FindNearestIndex(chromGroup.Times, (float)chromGroup.EndTime));
            var chromPeak = new ChromPeak(crawPeakFinder, crawdadPeak, 0, timeIntensities, null);

            transitionChromInfo = new TransitionChromInfo(null, 0, chromPeak,
                                                          IonMobilityFilter.EMPTY, // CONSIDER(bspratt) IMS in chromatogram libraries?
                                                          new float?[0], Annotations.EMPTY,
                                                          UserSet.FALSE);
            var peaks  = new[] { chromPeak };
            var header = new ChromGroupHeaderInfo(precursorMz,
                                                  0,                                                    // file index
                                                  1,                                                    // numTransitions
                                                  0,                                                    // startTransitionIndex
                                                  peaks.Length,                                         // numPeaks
                                                  0,                                                    // startPeakIndex
                                                  0,                                                    // startscoreindex
                                                  0,                                                    // maxPeakIndex
                                                  chromGroup.Times.Length,                              // numPoints
                                                  0,                                                    // compressedSize
                                                  0,                                                    // uncompressedsize
                                                  0,                                                    //location
                                                  0, -1, -1, null, null, null, eIonMobilityUnits.none); // CONSIDER(bspratt) IMS in chromatogram libraries?
            var driftTimeFilter = IonMobilityFilter.EMPTY;                                              // CONSIDER(bspratt) IMS in chromatogram libraries?
            var groupInfo       = new ChromatogramGroupInfo(header,
                                                            new Dictionary <Type, int>(),
                                                            new byte[0],
                                                            new ChromCachedFile[0],
                                                            new[] { new ChromTransition(chromData.Mz, 0, (float)(driftTimeFilter.IonMobility.Mobility ?? 0), (float)(driftTimeFilter.IonMobilityExtractionWindowWidth ?? 0), ChromSource.unknown), },
                                                            peaks,
                                                            null)
            {
                TimeIntensitiesGroup = TimeIntensitiesGroup.Singleton(timeIntensities)
            };

            chromatogramInfo = new ChromatogramInfo(groupInfo, 0);
        }
Example #11
0
 public ExtractedSpectrum(Target target,
                          Color peptideColor,
                          SignedMz precursorMz,
                          IonMobilityFilter ionMobility,
                          ChromExtractor chromExtractor,
                          int filterIndex,
                          SpectrumProductFilter[] productFilters,
                          float[] intensities,
                          float[] massErrors)
 {
     Target         = target;
     PeptideColor   = peptideColor;
     PrecursorMz    = precursorMz;
     IonMobility    = ionMobility;
     Extractor      = chromExtractor;
     FilterIndex    = filterIndex;
     ProductFilters = productFilters;
     Intensities    = intensities;
     MassErrors     = massErrors;
 }
Example #12
0
 public ExtractedSpectrum(string textId,
                          Color peptideColor,
                          SignedMz precursorMz,
                          double ionMobilityValue,
                          double ionMobilityExtractionWidth,
                          ChromExtractor chromExtractor,
                          int filterIndex,
                          SpectrumProductFilter[] productFilters,
                          float[] intensities,
                          float[] massErrors)
 {
     TextId                     = textId;
     PeptideColor               = peptideColor;
     PrecursorMz                = precursorMz;
     IonMobilityValue           = ionMobilityValue;
     IonMobilityExtractionWidth = ionMobilityExtractionWidth;
     Extractor                  = chromExtractor;
     FilterIndex                = filterIndex;
     ProductFilters             = productFilters;
     Intensities                = intensities;
     MassErrors                 = massErrors;
 }
Example #13
0
        public SpectrumFilterPair(ChromatogramRequestDocumentChromatogramGroup requestGroup)
        {
            Q1 = new SignedMz(requestGroup.PrecursorMz);
            ModifiedSequence = new Target(requestGroup.ModifiedSequence);
            switch (requestGroup.Extractor)
            {
            case RemoteApi.GeneratedCode.ChromExtractor.BasePeak:
                Extractor = ChromExtractor.base_peak;
                break;

            case RemoteApi.GeneratedCode.ChromExtractor.Summed:
                Extractor = ChromExtractor.summed;
                break;
            }
            if (requestGroup.MinTimeSpecified)
            {
                MinTime = requestGroup.MinTime;
            }
            if (requestGroup.MaxTimeSpecified)
            {
                MaxTime = requestGroup.MaxTime;
            }
            switch (requestGroup.Source)
            {
            case RemoteApi.GeneratedCode.ChromSource.Ms1:
                Ms1ProductFilters = requestGroup.Chromatogram.Select(
                    product => new SpectrumProductFilter(product.ProductMz, product.MzWindow)).ToArray();
                HighAccQ1 = requestGroup.MassErrors;
                break;

            case RemoteApi.GeneratedCode.ChromSource.Ms2:
                Ms2ProductFilters = requestGroup.Chromatogram.Select(
                    product => new SpectrumProductFilter(product.ProductMz, product.MzWindow)).ToArray();
                HighAccQ3 = requestGroup.MassErrors;
                break;
            }
        }
Example #14
0
 public PeptidePrecursorMz(PeptideDocNode nodePeptide, SignedMz precursorMz)
 {
     NodePeptide = nodePeptide;
     PrecursorMz = precursorMz;
 }
Example #15
0
        public void CalcDiaIsolationValues(ref SignedMz isolationTargetMz,
                                           ref double?isolationWidth)
        {
            double isolationWidthValue;
            var    isolationScheme = _fullScan.IsolationScheme;

            if (isolationScheme == null)
            {
                throw new InvalidOperationException("Unexpected attempt to calculate DIA isolation window without an isolation scheme"); // Not L10N - for developers
            }

            // Calculate window for a simple isolation scheme.
            else if (isolationScheme.PrecursorFilter.HasValue)
            {
                // Use the user specified isolation width, unless it is larger than
                // the acquisition isolation width.  In this case the chromatograms
                // may be very confusing (spikey), because of incorrectly included
                // data points.
                isolationWidthValue = isolationScheme.PrecursorFilter.Value +
                                      (isolationScheme.PrecursorRightFilter ?? 0);
                if (isolationWidth.HasValue && isolationWidth.Value < isolationWidthValue)
                {
                    isolationWidthValue = isolationWidth.Value;
                }

                // Make sure the isolation target is centered in the desired window, even
                // if the window was specified as being asymetric
                if (isolationScheme.PrecursorRightFilter.HasValue)
                {
                    isolationTargetMz += isolationScheme.PrecursorRightFilter.Value - isolationWidthValue / 2;
                }
            }

            // Find isolation window.
            else if (isolationScheme.PrespecifiedIsolationWindows.Count > 0)
            {
                var isolationWindow = isolationScheme.GetIsolationWindow(isolationTargetMz, _instrument.MzMatchTolerance);
                if (isolationWindow == null)
                {
                    _filterPairDictionary[new IsolationWindowFilter(isolationTargetMz, isolationWidth)] = new List <SpectrumFilterPair>();
                    isolationWidth = null;
                    return;
                }

                isolationWidthValue = isolationWindow.End - isolationWindow.Start;
                isolationTargetMz   = isolationTargetMz.ChangeMz(isolationWindow.Start + isolationWidthValue / 2);
            }

            // MSe just uses the instrument isolation window
            else if (isolationWidth.HasValue && isolationScheme.IsAllIons)
            {
                isolationWidthValue = isolationWidth.Value;
            }

            // No defined isolation scheme?
            else
            {
                throw new InvalidDataException(Resources.SpectrumFilter_FindFilterPairs_Isolation_scheme_does_not_contain_any_isolation_windows);
            }
            isolationWidth = isolationWidthValue;
        }
Example #16
0
        public SpectrumFilter(SrmDocument document, MsDataFileUri msDataFileUri, IFilterInstrumentInfo instrumentInfo,
                              IRetentionTimePredictor retentionTimePredictor = null, bool firstPass = false)
        {
            _fullScan          = document.Settings.TransitionSettings.FullScan;
            _instrument        = document.Settings.TransitionSettings.Instrument;
            _acquisitionMethod = _fullScan.AcquisitionMethod;
            if (instrumentInfo != null)
            {
                _isWatersFile = instrumentInfo.IsWatersFile;
            }
            IsFirstPass = firstPass;

            var comparer = PrecursorTextId.PrecursorTextIdComparerInstance;
            var dictPrecursorMzToFilter = new SortedDictionary <PrecursorTextId, SpectrumFilterPair>(comparer);

            if (EnabledMs || EnabledMsMs)
            {
                if (EnabledMs)
                {
                    _isHighAccMsFilter = !Equals(_fullScan.PrecursorMassAnalyzer,
                                                 FullScanMassAnalyzerType.qit);

                    if (!firstPass)
                    {
                        var key = new PrecursorTextId(SignedMz.ZERO, null, ChromExtractor.summed);  // TIC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                                                                                _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                        key = new PrecursorTextId(SignedMz.ZERO, null, ChromExtractor.base_peak);   // BPC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                                                                                _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                    }
                }
                if (EnabledMsMs)
                {
                    _isHighAccProductFilter = !Equals(_fullScan.ProductMassAnalyzer,
                                                      FullScanMassAnalyzerType.qit);

                    if (_fullScan.AcquisitionMethod == FullScanAcquisitionMethod.DIA &&
                        _fullScan.IsolationScheme.IsAllIons)
                    {
                        if (instrumentInfo != null)
                        {
                            _isWatersMse  = _isWatersFile;
                            _isAgilentMse = instrumentInfo.IsAgilentFile;
                        }
                        _mseLevel = 1;
                    }
                }

                Func <double, double> calcWindowsQ1 = _fullScan.GetPrecursorFilterWindow;
                Func <double, double> calcWindowsQ3 = _fullScan.GetProductFilterWindow;
                _minTime = _instrument.MinTime;
                _maxTime = _instrument.MaxTime;
                bool canSchedule = CanSchedule(document, retentionTimePredictor);
                // TODO: Figure out a way to turn off time sharing on first SIM scan so that
                //       times can be shared for MS1 without SIM scans
                _isSharedTime = !canSchedule;

                // If we're using bare measured drift times from spectral libraries, go get those now
                var libraryIonMobilityInfo = document.Settings.PeptideSettings.Prediction.UseLibraryDriftTimes
                    ? document.Settings.GetIonMobilities(msDataFileUri)
                    : null;

                foreach (var nodePep in document.Molecules)
                {
                    if (firstPass && !retentionTimePredictor.IsFirstPassPeptide(nodePep))
                    {
                        continue;
                    }

                    foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                    {
                        if (nodeGroup.Children.Count == 0)
                        {
                            continue;
                        }

                        double?       minTime = _minTime, maxTime = _maxTime;
                        double?       startDriftTimeMsec = null, endDriftTimeMsec = null;
                        double        windowDT;
                        double        highEnergyDriftTimeOffsetMsec = 0;
                        DriftTimeInfo centerDriftTime               = document.Settings.PeptideSettings.Prediction.GetDriftTime(
                            nodePep, nodeGroup, libraryIonMobilityInfo, out windowDT);
                        if (centerDriftTime.DriftTimeMsec(false).HasValue)
                        {
                            startDriftTimeMsec            = centerDriftTime.DriftTimeMsec(false) - windowDT / 2; // Get the low energy drift time
                            endDriftTimeMsec              = startDriftTimeMsec + windowDT;
                            highEnergyDriftTimeOffsetMsec = centerDriftTime.HighEnergyDriftTimeOffsetMsec;
                        }

                        if (canSchedule)
                        {
                            if (RetentionTimeFilterType.scheduling_windows == _fullScan.RetentionTimeFilterType)
                            {
                                double?centerTime = null;
                                double windowRT   = 0;
                                if (retentionTimePredictor != null)
                                {
                                    centerTime = retentionTimePredictor.GetPredictedRetentionTime(nodePep);
                                }
                                else
                                {
                                    var prediction = document.Settings.PeptideSettings.Prediction;
                                    if (prediction.RetentionTime == null || !prediction.RetentionTime.IsAutoCalculated)
                                    {
                                        centerTime = document.Settings.PeptideSettings.Prediction.PredictRetentionTimeForChromImport(
                                            document, nodePep, nodeGroup, out windowRT);
                                    }
                                }
                                // Force the center time to be at least zero
                                if (centerTime.HasValue && centerTime.Value < 0)
                                {
                                    centerTime = 0;
                                }
                                if (_fullScan.RetentionTimeFilterLength != 0)
                                {
                                    windowRT = _fullScan.RetentionTimeFilterLength * 2;
                                }
                                if (centerTime != null)
                                {
                                    double startTime = centerTime.Value - windowRT / 2;
                                    double endTime   = startTime + windowRT;
                                    minTime = Math.Max(minTime ?? 0, startTime);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, endTime);
                                }
                            }
                            else if (RetentionTimeFilterType.ms2_ids == _fullScan.RetentionTimeFilterType)
                            {
                                var times = document.Settings.GetBestRetentionTimes(nodePep, msDataFileUri);
                                if (times.Length > 0)
                                {
                                    minTime = Math.Max(minTime ?? 0, times.Min() - _fullScan.RetentionTimeFilterLength);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, times.Max() + _fullScan.RetentionTimeFilterLength);
                                }
                            }
                        }

                        SpectrumFilterPair filter;
                        string             textId = nodePep.RawTextId; // Modified Sequence for peptides, or some other string for custom ions
                        var mz  = new SignedMz(nodeGroup.PrecursorMz, nodeGroup.PrecursorCharge < 0);
                        var key = new PrecursorTextId(mz, textId, ChromExtractor.summed);
                        if (!dictPrecursorMzToFilter.TryGetValue(key, out filter))
                        {
                            filter = new SpectrumFilterPair(key, nodePep.Color, dictPrecursorMzToFilter.Count, minTime, maxTime,
                                                            startDriftTimeMsec, endDriftTimeMsec, highEnergyDriftTimeOffsetMsec,
                                                            _isHighAccMsFilter, _isHighAccProductFilter);
                            dictPrecursorMzToFilter.Add(key, filter);
                        }

                        if (!EnabledMs)
                        {
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                        else if (!EnabledMsMs)
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                        }
                        else
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     where !nodeTran.IsMs1
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                    }
                }
                _filterMzValues = dictPrecursorMzToFilter.Values.ToArray();

                var listChromKeyFilterIds = new List <ChromKey>();
                foreach (var spectrumFilterPair in _filterMzValues)
                {
                    spectrumFilterPair.AddChromKeys(listChromKeyFilterIds);
                }
                _productChromKeys = listChromKeyFilterIds.ToArray();

                // Sort a copy of the filter pairs by maximum retention time so that we can detect when
                // filters are no longer active.
                _filterRTValues = new SpectrumFilterPair[_filterMzValues.Length];
                Array.Copy(_filterMzValues, _filterRTValues, _filterMzValues.Length);
                Array.Sort(_filterRTValues, CompareByRT);
            }

            InitRTLimits();
        }
Example #17
0
 public IsolationWindowFilter(SignedMz isolationMz, double?isolationWidth) : this()
 {
     IsolationMz    = isolationMz;
     IsolationWidth = isolationWidth;
 }
Example #18
0
 public PrecursorTextId(SignedMz precursorMz, string textId, ChromExtractor extractor) : this()
 {
     PrecursorMz = precursorMz;
     TextId      = textId;
     Extractor   = extractor;
 }
Example #19
0
 public SpectrumFilterValues(SignedMz mz, double ionMobilityHighEnergyOffset)
 {
     this.mz = mz;
     this.ionMobilityHighEnergyOffset = ionMobilityHighEnergyOffset;
 }
Example #20
0
 private static int CompareMz(SignedMz mz1, SignedMz mz2, double window)
 {
     return(mz1.CompareTolerant(mz2, 0.5 * window));
 }
Example #21
0
 public bool MatchesDdaPrecursor(SignedMz precursorMz)
 {
     return(Ms1ProductFilters.Any(filter => 0 == filter.TargetMz.CompareTolerant(precursorMz, filter.FilterWidth)));
 }
Example #22
0
 public PrecursorTextId(SignedMz precursorMz, Target target, ChromExtractor extractor) : this()
 {
     PrecursorMz = precursorMz;
     Target      = target;
     Extractor   = extractor;
 }
Example #23
0
 public SpectrumProductFilter(SignedMz targetMz, double filterWidth)
 {
     TargetMz    = targetMz;
     FilterWidth = filterWidth;
 }
Example #24
0
        public MsDataSpectrum[] GetMsDataFileSpectraWithCommonRetentionTime(int dataFileSpectrumStartIndex)
        {
            SignedMz precursor = Transitions.Select(transition => transition.PrecursorMz).FirstOrDefault();

            return(_chorusSession.GetSpectra(ChorusUrl, Source, precursor, dataFileSpectrumStartIndex));
        }
Example #25
0
 private int IndexOfFilter(SignedMz precursorMz, double window)
 {
     return(IndexOfFilter(precursorMz, window, 0, _filterMzValues.Length - 1));
 }
Example #26
0
 public SpectrumProductFilter(SignedMz targetMz, double filterWidth, double highEnergyIonMobilityValueOffset)
 {
     TargetMz    = targetMz;
     FilterWidth = filterWidth;
     HighEnergyIonMobilityValueOffset = highEnergyIonMobilityValueOffset;
 }