Exemple #1
0
        private Dictionary <MSDeconvNode, List <MSDeconvNode> > GetEdges(List <MSDeconvNode> nodeList, Tolerance tol, double elutionInterval)
        {
            var edgeDict     = new Dictionary <MSDeconvNode, List <MSDeconvNode> >();
            var currentNode  = nodeList[0];
            var currentIndex = GetIndexRange(nodeList, elutionInterval, currentNode);

            foreach (var n1 in nodeList)
            {
                if (n1.ScanNumber != currentNode.ScanNumber)
                {
                    currentNode  = n1;
                    currentIndex = GetIndexRange(nodeList, elutionInterval, currentNode);
                    if (currentIndex.Item2 == -1)
                    {
                        break;
                    }
                }
                edgeDict.Add(n1, new List <MSDeconvNode>());
                for (var i = currentIndex.Item1; i < currentIndex.Item2; i++)
                {
                    var deltaMass = Math.Abs(nodeList[i].RealMonoMass - n1.RealMonoMass);
                    if (deltaMass <= tol.GetValue())
                    {
                        edgeDict[n1].Add(nodeList[i]);
                    }
                }
            }
            return(edgeDict);
        }
Exemple #2
0
        public FeatureSet GetFeatures(double mz, Tolerance tolerance, DataReader.FrameType frameType)
        {
            var intensityBlock = _uimfUtil.GetXic(mz, tolerance.GetValue(), frameType,
                                                  tolerance.GetUnit() == ToleranceUnit.Ppm ? DataReader.ToleranceType.PPM : DataReader.ToleranceType.Thomson);
            var features = new FeatureSet(intensityBlock);

            return(features);
        }
        public LcMsPeakMatrixLowResolution(LcMsRun run, int maxFeaturesPerSpec = 100, double tolerancePpm = 64, int minScanCharge = 20, int maxScanCharge = 100, double minScanMass = 20000, double maxScanMass = 60000)
        {
            Run          = run;
            _tolerance   = new Tolerance(Math.Max(tolerancePpm, 32));
            _minCharge   = minScanCharge;
            _maxCharge   = maxScanCharge;
            _minMass     = minScanMass;
            _maxMass     = maxScanMass;
            _ms1Features = new NodeSet <Ms1Feature>();

            var nBits = (int)Math.Round(27 - Math.Log(_tolerance.GetValue() / 16, 2));

            _comparer = new MzComparerWithBinning(nBits);

            _maxFeaturesPerSpec = maxFeaturesPerSpec;
        }
Exemple #4
0
        public void TestPpmErrorCalculation(string seqText, string rawFilePath, int scanNum)
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            ShowStarting(methodName, rawFilePath);

            var          tolerance   = new Tolerance(10, ToleranceUnit.Ppm);
            const int    maxCharge   = 15;
            const double relIntThres = 0.1;

            if (!File.Exists(rawFilePath))
            {
                Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, rawFilePath);
            }

            // init
            var sequence = Sequence.GetSequenceFromMsGfPlusPeptideStr(seqText);
            var lcms     = PbfLcMsRun.GetLcMsRun(rawFilePath);
            var spectrum = lcms.GetSpectrum(scanNum);

            var ionTypeFactory = new IonTypeFactory(maxCharge);
            var iontypes       = ionTypeFactory.GetAllKnownIonTypes();

            foreach (var iontype in iontypes)
            {
                var ion      = iontype.GetIon(sequence.Composition);
                var obsPeaks = spectrum.GetAllIsotopePeaks(ion, tolerance, relIntThres);
                if (obsPeaks == null)
                {
                    continue;
                }
                var isotopes = ion.GetIsotopes(relIntThres).ToArray();
                for (int i = 0; i < isotopes.Length; i++)
                {
                    if (obsPeaks[i] == null)
                    {
                        continue;
                    }
                    var obsMz    = obsPeaks[i].Mz;
                    var theoMz   = ion.GetIsotopeMz(isotopes[i].Index);
                    var ppmError = (obsMz - theoMz) / theoMz * 1e6;
                    Assert.True(ppmError <= tolerance.GetValue());
                }
            }
        }
        public void TestIsotopePeakAlignment(string rawFilePath, string idFilePath)
        {
            var idFileReader = IdFileReaderFactory.CreateReader(idFilePath);
            var lcms         = PbfLcMsRun.GetLcMsRun(rawFilePath);
            var ids          = idFileReader.Read();
            var idList       = ids.ToList();

            var rawFileName = Path.GetFileNameWithoutExtension(rawFilePath);

            foreach (var id in idList)
            {
                id.LcMs        = lcms;
                id.RawFileName = rawFileName;
            }

            var prsms = idList.Where(prsm => prsm.Sequence.Count > 0);

            const double relIntThres    = 0.1;
            var          tolerance      = new Tolerance(10, ToleranceUnit.Ppm);
            var          toleranceValue = tolerance.GetValue();

            const int maxCharge      = 15;
            var       ionTypeFactory = new IonTypeFactory(maxCharge);
            var       ionTypes       = ionTypeFactory.GetAllKnownIonTypes().ToArray();

            var psmsValidated    = 0;
            var ionsValidated    = 0;
            var validationErrors = new List <string>();

            foreach (var prsm in prsms)
            {
                foreach (var ionType in ionTypes)
                {
                    var composition   = prsm.Sequence.Aggregate(Composition.Zero, (current, aa) => current + aa.Composition);
                    var ion           = ionType.GetIon(composition);
                    var observedPeaks = prsm.Ms2Spectrum.GetAllIsotopePeaks(ion, tolerance, relIntThres);
                    if (observedPeaks == null)
                    {
                        continue;
                    }

                    var errors = IonUtils.GetIsotopePpmError(observedPeaks, ion, relIntThres);
                    foreach (var error in errors)
                    {
                        if (error == null)
                        {
                            continue;
                        }
                        if (error > toleranceValue)
                        {
                            validationErrors.Add(string.Format("In scan {0}, PSM {1} has error {2:F1} for ion at {3} m/z",
                                                               prsm.Scan, prsm.SequenceText, error, ion.GetIsotopeMz(0)));
                        }

                        ionsValidated++;
                    }
                }

                psmsValidated++;
            }

            Console.WriteLine("Validated {0:N0} ions for {1:N0} PSMs", ionsValidated, psmsValidated);

            if (validationErrors.Count <= 0)
            {
                return;
            }

            var validationMsg = string.Format("{0} ions had errors greater than {1} ppm", validationErrors.Count, tolerance);

            Console.WriteLine(validationMsg);
            foreach (var item in validationErrors.Take(10))
            {
                Console.WriteLine(item);
            }

            Assert.Fail(validationMsg);
        }
Exemple #6
0
        public Dictionary <int, FeatureSet> GetFeaturesMultiThreading(int minTargetBin, int maxTargetBin, Tolerance tolerance, DataReader.FrameType frameType)
        {
            var featureDictionary = new Dictionary <int, FeatureSet>();

            var targetMzList = Enumerable.Range(minTargetBin, maxTargetBin - minTargetBin + 1).Select(targetBin => _uimfUtil.GetMzFromBin(targetBin)).ToList();
            var featureStatisticsDictionary = _featureDetectionUtil.GetFeatureStatistics(targetMzList, tolerance.GetValue(), frameType,
                                                                                         tolerance.GetUnit() == ToleranceUnit.Ppm ? DataReader.ToleranceType.PPM : DataReader.ToleranceType.Thomson);

            foreach (var entry in featureStatisticsDictionary)
            {
                var targetBin    = _uimfUtil.GetBinFromMz(entry.Key);
                var featureStats = entry.Value;
                featureDictionary.Add(targetBin, new FeatureSet(featureStats));
            }
            return(featureDictionary);
        }