Example #1
0
        /// <summary>
        /// Add single Peptide-Spectrum match to RankTable.
        /// </summary>
        /// <param name="match"></param>
        public void AddMatch(SpectrumMatch match)
        {
            var ranks = new RankedPeaks(match.Spectrum);

            for (int i = 0; i < ranks.Peaks.Length; i++)
            {
                var index = i;
                if (index >= MaxRanks)
                {
                    index = MaxRanks - 1;
                }
                _rankTotals[index]++;
                _rankTotals[MaxRanks]++;
            }
            foreach (var ionType in IonTypes)
            {
                var ions = match.GetCleavageIons(ionType);
                foreach (var ion in ions)
                {
                    var rank      = ranks.RankIon(ion, _tolerance);
                    var rankIndex = GetRankIndex(rank);
                    _rankTable[ionType][rankIndex]++;
                }
            }
        }
Example #2
0
        private void Compute()
        {
            if (_computed)
            {
                return;
            }
            Initialize();
            var total = _dataSet.Count;

            for (int i = 0; i < total; i++)
            {
                var target = _dataSet.Dequeue();
                var charge = target.PrecursorCharge;
                if (!_charges.Contains(charge))
                {
                    continue;
                }
                var decoy = new SpectrumMatch(target, true);
                var mass  = target.PrecursorComposition.Mass;
                var index = _massSorter[charge].GetBinIndex(mass);
                ComputeMatch(target, charge, index);
                ComputeMatch(decoy, charge, index);
            }
            _computed = true;
        }
Example #3
0
 public LabeledMs1DataPoint(double mz, double retentionTime, double logTotalIonCurrent, double logInjectionTime, double massError, double RTError, SpectrumMatch identification)
 {
     this.mz                 = mz;
     this.retentionTime      = retentionTime;
     this.logTotalIonCurrent = logTotalIonCurrent;
     this.logInjectionTime   = logInjectionTime;
     this.massError          = massError;
     this.RTError            = RTError;
     this.identification     = identification;
     Inputs = new double[] { mz, retentionTime };
 }
Example #4
0
        public void AddMatch(SpectrumMatch match)
        {
            var charge = match.PrecursorCharge;

            if (!_offsets.ContainsKey(charge))
            {
                throw new Exception("Invalid charge.");
            }
            for (int i = charge; i > 0; i--)
            {
                _offsets[i].AddMatches(new List <SpectrumMatch> {
                    match
                });
            }
        }
Example #5
0
        public void AddMatch(SpectrumMatch match)
        {
            Total++;
            var ion            = _precursorIonTypes[Charge - 1].GetIon(match.PeptideComposition);
            var monoIsotopicMz = ion.GetMonoIsotopicMz();
            var min            = GetMinMz(monoIsotopicMz);
            var max            = GetMaxMz(monoIsotopicMz);

            var peaks = match.Spectrum.Peaks;
            var offsetMzCollection = (from peak in peaks
                                      where peak.Mz >= min && peak.Mz <= max
                                      select peak.Mz - monoIsotopicMz).ToList();

            AddOffsets(offsetMzCollection);
        }
Example #6
0
        public void AddMatch(SpectrumMatch match)
        {
            foreach (var ionType in _ionTypes)
            {
                var charge   = ionType.Charge;
                var sequence = match.Sequence;
                var pepSeq   = ionType.IsPrefixIon
                    ? sequence.GetRange(0, sequence.Count - 1)
                    : sequence.GetRange(1, sequence.Count - 1);
                var ions = match.GetCleavageIons(ionType);

                var nextIonIndex = 1;
                while (nextIonIndex < ions.Count)
                {
                    // look for peaks for current ion and next ion
                    _totalPairs++;
                    var currIonIndex = nextIonIndex - 1;
                    var currMz       = ions[currIonIndex].GetMonoIsotopicMz();
                    var currPeak     = match.Spectrum.FindPeak(currMz, _tolerance);
                    var nextMz       = ions[nextIonIndex].GetMonoIsotopicMz();
                    var nextPeak     = match.Spectrum.FindPeak(nextMz, _tolerance);

                    if (currPeak == null && nextPeak == null)
                    {
                        _ionPairFrequency[ionType].AddDatum(IonPairFound.Neither);
                    }
                    else if (nextPeak == null)
                    {
                        _ionPairFrequency[ionType].AddDatum(IonPairFound.First);
                    }
                    else if (currPeak == null)
                    {
                        _ionPairFrequency[ionType].AddDatum(IonPairFound.Second);
                    }
                    else
                    {
                        // found both peaks, compute mass error
                        _ionPairFrequency[ionType].AddDatum(IonPairFound.Both);
                        var aaIndex   = (ionType.IsPrefixIon ? nextIonIndex : currIonIndex);
                        var aaMz      = pepSeq[aaIndex].Mass / charge;
                        var massError = Math.Abs(nextPeak.Mz - currPeak.Mz) - aaMz;
                        _massError[ionType].AddDatum(massError);
                    }
                    nextIonIndex++;
                }
            }
        }
Example #7
0
        /// <summary>
        /// Add Peptide-Spectrum match to ion Probability table.
        /// </summary>
        /// <param name="match"></param>
        public void AddMatch(SpectrumMatch match)
        {
            var spectrum = match.Spectrum;

            var prefixes = match.Prefixes;
            var suffixes = match.Suffixes;

            for (int i = 0; i < prefixes.Count; i++)
            {
                var ionTypeFound = new Dictionary <IonType, bool>();
                foreach (var ionType in _ionTypes)
                {
                    var it = ionType;
                    if (_combineCharges)
                    {
                        it = ReducedChargeIonType(ionType);
                    }
                    if (!ionTypeFound.ContainsKey(it))
                    {
                        ionTypeFound.Add(it, false);
                    }

                    var cleavagePoints = ionType.BaseIonType.IsPrefix ? prefixes : suffixes;

                    var ion = ionType.GetIon(cleavagePoints[i]);

                    if (spectrum.ContainsIon(ion, _tolerance, _relativeIntensityThreshold))
                    {
                        ionTypeFound[it] = true;
                    }
                }
                foreach (var key in ionTypeFound.Keys)
                {
                    int       found = 0;
                    const int total = 1;
                    if (ionTypeFound[key])
                    {
                        found = 1;
                    }
                    AddIonProbability(new Probability <IonType>(key, found, total));
                }
            }
        }
Example #8
0
        public double GetScore(Sequence sequence, int charge, int scan, LcMsRun lcmsRun)
        {
            var mass             = sequence.Composition.Mass + Composition.H2O.Mass;
            var spectrum         = lcmsRun.GetSpectrum(scan);
            var ionTypes         = _rankScore.GetIonTypes(charge, mass);
            var filteredSpectrum = SpectrumFilter.FilterIonPeaks(sequence, spectrum, ionTypes, _tolerance);
            var match            = new SpectrumMatch(sequence, filteredSpectrum, charge);
            var score            = 0.0;
            var rankedPeaks      = new RankedPeaks(filteredSpectrum);

            foreach (var ionType in ionTypes)
            {
                var ions = match.GetCleavageIons(ionType);
                foreach (var ion in ions)
                {
                    var rank = rankedPeaks.RankIon(ion, _tolerance);
                    score += _rankScore.GetScore(ionType, rank, charge, mass);
                }
            }
            return(score);
        }
Example #9
0
        private void ComputeMatch(SpectrumMatch match, int charge, int massIndex)
        {
            var isDecoy        = match.Decoy;
            var massErrors     = _massErrors[charge][massIndex];
            var rankTable      = (isDecoy ? _drankTables[charge][massIndex] : _rankTables[charge][massIndex]);
            var ionFrequencies = _ionProbabilities[charge][massIndex];

            var acMatch = match;

            if (Config.AcquisitionMethod == AcquisitionMethod.Dia)
            {
                // filter out all peaks except ion peaks
                var ionPeakSpectrum = SpectrumFilter.FilterIonPeaks(match.Sequence, match.Spectrum,
                                                                    Config.IonTypes, Config.Tolerance);
                acMatch = new SpectrumMatch(acMatch.Sequence, ionPeakSpectrum, acMatch.ScanNum, acMatch.PrecursorCharge, acMatch.Decoy);
            }
            else
            {
                _precursorOffsets[charge][massIndex].AddMatch(match);
                // filter precursor peaks
                var precursorFilter = new PrecursorFilter(_precursorOffsets[charge][massIndex],
                                                          Config.MassErrorTolerance);
                acMatch = precursorFilter.Filter(acMatch);
            }
            rankTable.AddMatch(acMatch);
            if (isDecoy)
            {
                return;
            }

            massErrors.AddMatch(match);

            var filteredSpectrum = SpectrumFilter.GetFilteredSpectrum(match.Spectrum, Config.WindowWidth,
                                                                      Config.RetentionCount);
            var filteredMatch = new SpectrumMatch(match.Sequence, filteredSpectrum, match.PrecursorCharge);

            ionFrequencies.AddMatch(filteredMatch);
        }
        //TOPDOWN pROTEOFORM
        public static TopDownProteoform TopDownProteoform(string accession, double modified_mass, double retention_time)
        {
            SpectrumMatch h = new SpectrumMatch();

            h.reported_mass      = modified_mass;
            h.theoretical_mass   = modified_mass;
            h.ms2_retention_time = retention_time;
            h.sequence           = "MSSSSSSSSSS";
            h.begin         = 10;
            h.end           = 20;
            h.pfr_accession = "";
            h.name          = "";
            h.uniprot_id    = "";
            TopDownProteoform td = new TopDownProteoform(accession, new List <SpectrumMatch>()
            {
                h
            });

            td.topdown_geneName = new GeneName(new List <Tuple <string, string> > {
                new Tuple <string, string>("genename", "genename")
            });
            (td as ExperimentalProteoform).topdown_id = true;
            return(td);
        }
Example #11
0
 public DisplayTopDownHit(SpectrumMatch h)
     : base(h)
 {
     this.h = h;
 }
Example #12
0
        public List <Probability <IonType> > ComputeOffsetFrequencies(SpectrumMatch spectrumMatch)
        {
            var debugFile = File.AppendText(DebugFileName);

            var peptide  = spectrumMatch.Peptide;
            var sequence = spectrumMatch.Sequence;
            var spectrum = spectrumMatch.Spectrum;
            var prefixes = spectrumMatch.Prefixes;
            var suffixes = spectrumMatch.Suffixes;

            var prefixIonTypes = _ionTypes.Where(ionType => ionType.IsPrefixIon).ToList();
            var suffixIonTypes = _ionTypes.Where(ionType => !ionType.IsPrefixIon).ToList();

            var probabilities = new Dictionary <IonType, Probability <IonType> >();

            debugFile.WriteLine("Scan:\t{0}\tPeptide:\t{1}\tCharge:\t{2}", spectrumMatch.Spectrum.ScanNum, peptide, spectrumMatch.PrecursorCharge);
            debugFile.WriteLine("Prefixes");
            debugFile.WriteLine("Segment\tIon\tM/Z\tFound");

            for (int i = 0; i < prefixes.Count; i++)
            {
                var segment    = spectrumMatch.Sequence.GetRange(0, i + 1);
                var segmentStr = segment.Aggregate("", (current, aa) => current + aa.Residue);
                foreach (var ionType in prefixIonTypes)
                {
                    if (!probabilities.ContainsKey(ionType))
                    {
                        probabilities.Add(ionType, new Probability <IonType>(ionType));
                    }

                    var    ion     = ionType.GetIon(prefixes[i]);
                    double mz      = ion.GetMonoIsotopicMz();
                    var    present = spectrum.ContainsIon(ion, _tolerance, RelativeIntensityThreshold);
                    probabilities[ionType].Total++;
                    if (present)
                    {
                        probabilities[ionType].Found++;
                    }

                    debugFile.WriteLine("{0}\t{1}\t{2}\t{3}", segmentStr, ionType.Name, mz, present);
                }
            }

            debugFile.WriteLine("Suffixes");
            debugFile.WriteLine("Segment\tIon\tM/Z\tFound");

            for (int i = 0; i < suffixes.Count; i++)
            {
                var segment    = spectrumMatch.Sequence.GetRange(i + 1, sequence.Count - (i + 1));
                var segmentStr = segment.Aggregate("", (current, aa) => current + aa.Residue);
                foreach (var ionType in suffixIonTypes)
                {
                    if (!probabilities.ContainsKey(ionType))
                    {
                        probabilities.Add(ionType, new Probability <IonType>(ionType));
                    }

                    var    ion     = ionType.GetIon(suffixes[i]);
                    double mz      = ion.GetMonoIsotopicMz();
                    var    present = spectrum.ContainsIon(ion, _tolerance, RelativeIntensityThreshold);
                    probabilities[ionType].Total++;
                    if (present)
                    {
                        probabilities[ionType].Found++;
                    }

                    debugFile.WriteLine("{0}\t{1}\t{2}\t{3}", segmentStr, ionType.Name, mz, present);
                }
            }

            debugFile.WriteLine();
            debugFile.Close();
            return(probabilities.Values.ToList());
        }
Example #13
0
        public IList <SpectrumMatch> Read()
        {
            var specMatches = new List <SpectrumMatch>();
            var file        = File.ReadLines(_fileName);
            var mgfState    = MgfState.Label;

            var sequence = "";
            int scanNum = 0, charge = 0;
            var peaks = new List <Peak>();

            var peptideSet = new HashSet <string>();

            foreach (var line in file)
            {
                switch (mgfState)
                {
                case MgfState.Label:
                    if (line == "BEGIN IONS")
                    {
                        mgfState = MgfState.Parameter;
                    }
                    else
                    {
                        throw new FormatException("Invalid MGF file.");
                    }
                    break;

                case MgfState.Parameter:
                    var parameter = line.Split('=');
                    if (parameter.Length < 2)
                    {
                        throw new FormatException("Invalid line in MGF file: " + line);
                    }
                    if (parameter[0] == "SEQ")
                    {
                        sequence = parameter[1];
                    }
                    else if (parameter[0] == "SCANS")
                    {
                        scanNum = Convert.ToInt32(parameter[1]);
                    }
                    else if (parameter[0] == "CHARGE")
                    {
                        var chargeStr = parameter[1].Substring(0, parameter[1].Length - 1);
                        charge   = Convert.ToInt32(chargeStr);
                        mgfState = MgfState.Peak;
                        if (sequence == "" || scanNum == 0 || charge == 0)
                        {
                            throw new FormatException("Incomplete spectrum entry.");
                        }
                    }
                    break;

                case MgfState.Peak:
                    if (line == "END IONS")
                    {
                        if (peaks.Count == 0)
                        {
                            throw new FormatException("Empty peak list.");
                        }
                        mgfState = MgfState.Label;
                        if (peptideSet.Contains(sequence))
                        {
                            sequence = "";
                            scanNum  = 0;
                            charge   = 0;
                            peaks.Clear();
                            continue;
                        }
                        peptideSet.Add(sequence);
                        var spectrum = new ProductSpectrum(peaks, scanNum)
                        {
                            MsLevel = 2
                        };
                        var sequenceReader = new MgfSequenceReader();
                        var seq            = sequenceReader.GetSequence(sequence);
                        var specMatch      = new SpectrumMatch(seq, spectrum, scanNum, charge, _decoy);
                        sequence = "";
                        scanNum  = 0;
                        charge   = 0;
                        specMatches.Add(specMatch);
                        peaks.Clear();
                    }
                    else
                    {
                        var parts = line.Split('\t');
                        if (parts.Length < 2)
                        {
                            throw new FormatException("Invalid line in MGF file: " + line);
                        }
                        var mz        = Convert.ToDouble(parts[0]);
                        var intensity = Convert.ToDouble(parts[1]);
                        peaks.Add(new Peak(mz, intensity));
                    }
                    break;
                }
            }
            return(specMatches);
        }