Beispiel #1
0
        public override double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition)
        {
            var score = 0.0;

            foreach (var baseIonType in BaseIonTypes)
            {
                var fragmentComposition = baseIonType.IsPrefix
                              ? prefixFragmentComposition + baseIonType.OffsetComposition
                              : suffixFragmentComposition + baseIonType.OffsetComposition;
                
                if (fragmentComposition.Mass < Ms2Spectrum.Peaks[0].Mz) continue;
                var chargeRange = GetMinMaxChargeRange(fragmentComposition);

                var containsIon = false;
                for (var charge = chargeRange.Min; charge <= chargeRange.Max; charge++)
                {
                    var ion = new Ion(fragmentComposition, charge);
                    if (Ms2Spectrum.ContainsIon(ion, Tolerance, RelativeIsotopeIntensityThreshold))
                    {
                        containsIon = true;
                        break;
                    }
                }

                if (containsIon) score += 1.0;
            }
            return score;
        }
Beispiel #2
0
 public GroupParameter(Composition cutComposition, char nTermAA, char cTermAA, Ion precursorIon)
 {
     MassIndex = GetMassIndex(precursorIon.Composition);
     Charge = Math.Max(MinCharge, Math.Min(precursorIon.Charge, MaxCharge));
     LocationIndex = GetLocationIndex(precursorIon.Composition, cutComposition);
     FlankingResidueIndex =  GetFlankingResidueIndex(nTermAA, cTermAA); 
 }
 public IcBottomUpScores GetScores(char pre, string sequence, char post, Composition composition, int charge,
     int ms2ScanNum)
 {
     var nTerm = pre == FastaDatabase.Delimiter ? AminoAcid.ProteinNTerm : AminoAcid.PeptideNTerm;
     var cTerm = post == FastaDatabase.Delimiter ? AminoAcid.ProteinCTerm : AminoAcid.PeptideCTerm;
     return GetScores(pre, sequence, post, nTerm, cTerm, composition, charge, ms2ScanNum);
 }
 public new Composition Add(Composition c)
 {
     var comWithDelta = c as CompositionWithDeltaMass;
     return comWithDelta == null ? 
         new CompositionWithDeltaMass(AddComposition(c), _deltaMass, _deltaNominalMass)
         : new CompositionWithDeltaMass(AddComposition(c), _deltaMass + comWithDelta._deltaMass, _deltaNominalMass + comWithDelta._deltaNominalMass);
 }
Beispiel #5
0
        public void TestCompositions()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            var comp1 = Modification.Oxidation.Composition;
            var comp2 = new Composition(1, 2, 3, 4, 5, 6,
                                        new[]
                                            {
                                                new Tuple<Atom, short>(Atom.Get("Au"), 2),
                                                new Tuple<Atom, short>(Atom.Get("13C"), 3)
                                            });
            var comp3 = comp1 + comp2;

            Assert.AreEqual(comp1.ToString(), "C(0) H(0) N(0) O(1) S(0)");
            Assert.AreEqual(comp1.ToPlainString(), "O1");
            Assert.AreEqual(comp2.ToString(), "C(1) H(2) N(3) O(4) S(5) P(6) Au(2) 13C(3)");
            Assert.AreEqual(comp2.ToPlainString(), "C1H2N3O4S5P6Au213C3");
            Assert.AreEqual(comp3.ToString(), "C(1) H(2) N(3) O(5) S(5) P(6) Au(2) 13C(3)");
            var comp4 = new Composition(1, 2, 3, 4, 5, 6,
                                        new[]
                                            {
                                                new Tuple<Atom, short>(Atom.Get("Au"), 2),
                                                new Tuple<Atom, short>(Atom.Get("13C"), 3)
                                            });

            // Testing GetHashCode() and Equals() 
            Assert.IsTrue(comp2.Equals(comp4));
            Assert.IsTrue(comp2.GetHashCode() == comp4.GetHashCode());
            Assert.IsTrue(comp2.Equals(comp2 + Composition.Zero));
        }
        public IcBottomUpScores GetScores(char pre, string sequence, char post, AminoAcid nTerm, AminoAcid cTerm, Composition composition, int charge, int ms2ScanNum)
        {
            ScoredSpectrum scoredSpectrum;
            var index = GetChargetScanNumPairIndex(charge, ms2ScanNum);
            if (!_scoredSpectra.TryGetValue(index, out scoredSpectrum))
            {
                var spec = Run.GetSpectrum(ms2ScanNum) as ProductSpectrum;
                if (spec == null) return null;
                scoredSpectrum = new ScoredSpectrum(spec, _rankScorer, charge, composition.Mass, Tolerance);
                _scoredSpectra.Add(index, scoredSpectrum);
            }

            var seqGraph = SequenceGraph.CreateGraph(AminoAcidSet, nTerm, sequence, cTerm);
            if (seqGraph == null)
            {
                return null;
            }

            Tuple<double, string> scoreAndModifications = null;
            var bestScore = double.NegativeInfinity;
            var protCompositions = seqGraph.GetSequenceCompositions();
            for (var modIndex = 0; modIndex < protCompositions.Length; modIndex++)
            {
                seqGraph.SetSink(modIndex);
                var protCompositionWithH2O = seqGraph.GetSinkSequenceCompositionWithH2O();
                if (!protCompositionWithH2O.Equals(composition)) continue;

                var curScoreAndModifications = seqGraph.GetFragmentScoreAndModifications(scoredSpectrum);
                var curScore = curScoreAndModifications.Item1;
                if (curScore > bestScore)
                {
                    scoreAndModifications = curScoreAndModifications;
                    bestScore = curScore;
                }
            }

            if (scoreAndModifications == null) return null;

            var ms2Score = scoreAndModifications.Item1;

            // TODO: This assumes enzyme is trypsin
            const double probN = 0.99999;
            const double probC = 0.99999;
            const double sumAAProbabilities = 0.1;
            var creditN = Math.Log(probN / sumAAProbabilities);
            var penaltyN = Math.Log((1.0 - probN) / (1.0 - sumAAProbabilities));
            var creditC = Math.Log(probC / sumAAProbabilities);
            var penaltyC = Math.Log((1.0 - probC) / (1.0 - sumAAProbabilities));

            if (pre == 'K' || pre == 'R' || pre == FastaDatabase.Delimiter || pre == '-') ms2Score += creditN;
            else ms2Score += penaltyN;

            var lastResidue = sequence[sequence.Length - 1];
            if (lastResidue == 'K' || lastResidue == 'R' || post == FastaDatabase.Delimiter || post == '-') ms2Score += creditC;
            else ms2Score += penaltyC;

            var modifications = scoreAndModifications.Item2;

            return new IcBottomUpScores(ms2Score, modifications);
        }
Beispiel #7
0
 public AminoAcid(char residue, string name, Composition.Composition comp)
 {
     Residue = residue;
     Name = name;
     Composition = comp;
     Mass = Composition.Mass;
     _nominalMass = Composition.NominalMass;
 }
        public double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition)
        {
            var score = 0.0;

            foreach (var baseIonType in _baseIonTypes)
            {
                var fragmentComposition = baseIonType.IsPrefix
                              ? prefixFragmentComposition + baseIonType.OffsetComposition
                              : suffixFragmentComposition + baseIonType.OffsetComposition;
                fragmentComposition.ComputeApproximateIsotopomerEnvelop();
                var isotopomerEnvelope = fragmentComposition.GetIsotopomerEnvelop();

                //var bestFitScore = 1.0;
                var bestCosineScore = 0.0;
                var bestObsIntensity = -1.0;
                for (var charge = _minCharge; charge <= _maxCharge; charge++)
                {
                    var ion = new Ion(fragmentComposition, charge);
                    var cosineScore = _ms2Spec.GetConsineScore(ion, _tolerance, RelativeIntensityThreshold);
                    if (cosineScore > bestCosineScore) bestCosineScore = cosineScore;
                    //var observedPeaks = _ms2Spec.GetAllIsotopePeaks(ion, _tolerance, RelativeIntensityThreshold);

                    //if (observedPeaks == null) continue;

                    //var theoIntensities = new float[observedPeaks.Length];
                    //var observedIntensities = new float[observedPeaks.Length];
                    //var maxObservedIntensity = float.NegativeInfinity;
                    //for (var i = 0; i < observedPeaks.Length; i++)
                    //{
                    //    theoIntensities[i] = isotopomerEnvelope[i];
                    //    if (observedPeaks[i] != null)
                    //    {
                    //        var observedIntensity = (float)observedPeaks[i].Intensity;
                    //        observedIntensities[i] = observedIntensity;
                    //        if (observedIntensity > maxObservedIntensity) maxObservedIntensity = observedIntensity;
                    //    }
                    //    else
                    //    {
                    //        observedIntensities[i] = 0;
                    //    }
                    //}

                    //for (var i = 0; i < observedPeaks.Length; i++)
                    //{
                    //    observedIntensities[i] /= maxObservedIntensity;
                    //}
                    //var fitScore = FitScoreCalculator.GetFitOfNormalizedVectors(isotopomerEnvelope, observedIntensities);
                    //if (fitScore < bestFitScore)
                    //{
                    //    bestFitScore = fitScore;
                    //    bestObsIntensity = maxObservedIntensity;
                    //}
                }
                //score += GetScore(baseIonType, bestFitScore, bestObsIntensity);
                score += GetScore(baseIonType, bestCosineScore, bestObsIntensity);
            }
            return score;
        }
Beispiel #9
0
 public Composition(Composition composition)
     : this(composition.C, composition.H,
         composition.N, composition.O, composition.S, composition.P)
 {
     if (composition._additionalElements != null)
     {
         _additionalElements = new Dictionary<Atom, short>(composition._additionalElements);
     }
 }
Beispiel #10
0
 public double GetCutScore(char nTermAA, char cTermAA, Composition cutComposition, Feature precursorFeature)
 {
     UpdatePrecursorFeatureNode(precursorFeature);
     var parameter = new GroupParameter(cutComposition, nTermAA, cTermAA, _precursorIon);
     _graph = new FragmentFeatureGraph(_imsData, PrecursorFeatureNode, precursorFeature, _precursorIon,
                                          cutComposition, parameter, _scoringParams);
     SupportingIonTypes = _graph.supportingIonTypes;
     return _graph.Score;
 }
Beispiel #11
0
        public override double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition)
        {
            var score = 0.0;
            foreach (var baseIonType in BaseIonTypes)
            {
                var fragmentComposition = baseIonType.IsPrefix
                              ? prefixFragmentComposition + baseIonType.OffsetComposition
                              : suffixFragmentComposition + baseIonType.OffsetComposition;

                var observedCharge = 0;
                var envelopeCorr = 0d;
                var envelopeDist = 0d;
                var mostAbundantIsotopeIndex = fragmentComposition.GetMostAbundantIsotopeZeroBasedIndex();

                var observedPeaks = FindMostIntensePeak(fragmentComposition, CorrThreshold, DistThreshold, out observedCharge,
                    out envelopeCorr, out envelopeDist);
                var fragmentIonMass = fragmentComposition.Mass;

                if (observedPeaks == null) continue;
                var observedMostAbuPeak = observedPeaks[mostAbundantIsotopeIndex];
              
                var observedMass = Ion.GetMonoIsotopicMass(observedMostAbuPeak.Mz, observedCharge, mostAbundantIsotopeIndex);
                var massErrorPpm = (Math.Abs(observedMass - fragmentIonMass)/fragmentIonMass)*1e6;

                score += 1;
                var intScore = (observedMostAbuPeak.Intensity / _refIntensity) * 10;
                var corrScore = (fragmentIonMass > 1300 & envelopeCorr > 0.7) ? (envelopeCorr - 0.7) : 0;
                var distScore = (fragmentIonMass > 1300 & envelopeDist < 0.07) ? 0.3 - 3.75 * envelopeDist : 0;
                score += intScore;
                score += corrScore;
                score += distScore;

                if (_includeMassErrorScore)
                {
                    /*score += _model.GetNodeScore(Ms2Spectrum.ActivationMethod, baseIonType.IsPrefix,
                        fragmentIonMass, observedCharge,
                        envelopeCorr, envelopeDist,
                        observedMostAbuPeak.Intensity / _refIntensity, massErrorPpm);    
                     */
                    var massErrorScore = GetMassErrorScore(massErrorPpm);
                    score += massErrorScore;
                }
                else
                {
                    /*score += _model.GetNodeScoreWithoutMassError(Ms2Spectrum.ActivationMethod, baseIonType.IsPrefix,
                        fragmentIonMass, observedCharge,
                        envelopeCorr, envelopeDist,
                        observedMostAbuPeak.Intensity / _refIntensity);
                     */
                }
                //score += _model.GetScore(baseIonType, bestCorrScore, bestObsIntensity);
            }
            return score;
        }
Beispiel #12
0
        public void TestCompositionOperations()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            TestUtils.ShowStarting(methodName);

            var comp = new Composition(1, 2, 3, 4, 5);
            var massComp = new CompositionWithDeltaMass(15.995);
            var sum = comp + massComp + comp + massComp;
            Console.WriteLine("{0}\t{1}\t{2}", sum, sum.Mass, sum.NominalMass);
            Console.WriteLine(sum.GetIsotopomerEnvelope().MostAbundantIsotopeIndex);
        }
        /// <summary>
        /// The are compositions equal.
        /// </summary>
        /// <param name="A">
        /// The a.
        /// </param>
        /// <param name="B">
        /// The b.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool AreCompositionsEqual(Composition A, Composition B)
        {
            Composition remainder;
            try
            {
                remainder = A - B;
            }
            catch (Exception)
            {
                remainder = B - A;
            }

            return (remainder == null) || (remainder.Mass - 0) < 0.1;
        }
Beispiel #14
0
        public TopDownScorer(Composition proteinComposition, LcMsRun run, Tolerance tolernace, SubScoreFactory factory)
        {
            _run = run;
            _proteinCompositionPlusWater = proteinComposition + Composition.H2O;
            _tolerance = tolernace;
            _factory = factory;

            _maxIntensityIsotopeIndex = _proteinCompositionPlusWater.GetMostAbundantIsotopeZeroBasedIndex();
            var thorethicalIsotopeEnvelope = _proteinCompositionPlusWater.GetIsotopomerEnvelopeRelativeIntensities();

            

            _minIsotopeIndex = 0;
            for (var i = 0; i < thorethicalIsotopeEnvelope.Length; i++)
            {
                if (!(thorethicalIsotopeEnvelope[i] > MinIsotopeIntensity)) continue;
                _minIsotopeIndex = i;
                break;
            }

            _isotopeEnvelope = new double[Math.Min(_maxIntensityIsotopeIndex + NumberAfterMaxIsotopeIndex, thorethicalIsotopeEnvelope.Length) - _minIsotopeIndex];
            for (var k = 0; k < _isotopeEnvelope.Length; k++)
            {
                _isotopeEnvelope[k] = thorethicalIsotopeEnvelope[k + _minIsotopeIndex];
            }

            /*foreach (var iso in thorethicalIsotopeEnvelope)
            {
                Console.WriteLine(iso);
            }
            Console.WriteLine();
            foreach (var iso in _isotopeEnvelope)
            {
                Console.WriteLine(iso);
            }
            
            System.Environment.Exit(1);
            */
            _xicArray = GetXicArray();
            _smoothedXicArray = GetSmoothedXicArray();
        }
Beispiel #15
0
        public double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition, out bool prefixHit, out bool suffixHit)
        {
            var score = 0.0;
            
            prefixHit = false;
            suffixHit = false;

            foreach (var baseIonType in BaseIonTypes)
            {
                var fragmentComposition = baseIonType.IsPrefix
                              ? prefixFragmentComposition + baseIonType.OffsetComposition
                              : suffixFragmentComposition + baseIonType.OffsetComposition;

                if (fragmentComposition.Mass < Ms2Spectrum.Peaks[0].Mz) continue;

                var param = baseIonType.IsPrefix ? ScoreParam.Prefix : ScoreParam.Suffix;
                var fragmentIonMass = fragmentComposition.Mass;
                
                var mostAbundantIsotopeIndex = fragmentComposition.GetMostAbundantIsotopeZeroBasedIndex();

                foreach (var matchedPeak in FindMatchedPeaks(fragmentComposition, CorrThreshold, DistThreshold))
                {
                    var observedMostAbuPeak = matchedPeak.ObservedPeaks[mostAbundantIsotopeIndex];
                    var observedMass = Ion.GetMonoIsotopicMass(observedMostAbuPeak.Mz, matchedPeak.Charge, mostAbundantIsotopeIndex);
                    var massErrorPpm = (Math.Abs(observedMass - fragmentIonMass) / fragmentIonMass) * 1e6;
                    
                    score += param.Count;
                    score += param.Intensity * Math.Min(observedMostAbuPeak.Intensity / ReferencePeakIntensity, 1.0); // intensity-based scoring
                    score += param.Dist * matchedPeak.Dist; // Envelope distance-based scoring
                    score += param.Corr * matchedPeak.Corr; // Envelope correlation-based scoring
                    score += param.MassError * massErrorPpm; // Envelope correlation-based scoring

                    if (baseIonType.IsPrefix) prefixHit = true;
                    else suffixHit = true;
                }
            }

            if (prefixHit && suffixHit) score += ScoreParam.ComplementaryIonCount;
            return score;
        }
Beispiel #16
0
        public IcScores GetScores(ProductSpectrum spec, string seqStr, Composition composition, int charge, int ms2ScanNum)
        {
            if (spec == null) return null;
            var scorer = new CompositeScorer(spec, Tolerance, MinProductCharge, Math.Min(MaxProductCharge, charge));
            var seqGraph = SequenceGraph.CreateGraph(AminoAcidSet, AminoAcid.ProteinNTerm, seqStr, AminoAcid.ProteinCTerm);
            if (seqGraph == null) return null;

            var bestScore = double.NegativeInfinity;
            Tuple<double, string> bestScoreAndModifications = null;
            var protCompositions = seqGraph.GetSequenceCompositions();

            for (var modIndex = 0; modIndex < protCompositions.Length; modIndex++)
            {
                seqGraph.SetSink(modIndex);
                var protCompositionWithH2O = seqGraph.GetSinkSequenceCompositionWithH2O();

                if (!protCompositionWithH2O.Equals(composition)) continue;

                var curScoreAndModifications = seqGraph.GetFragmentScoreAndModifications(scorer);
                var curScore = curScoreAndModifications.Item1;

                if (!(curScore > bestScore)) continue;

                bestScoreAndModifications = curScoreAndModifications;
                bestScore = curScore;
            }

            if (bestScoreAndModifications == null) return null;

            var modifications = bestScoreAndModifications.Item2;
            var seqObj = Sequence.CreateSequence(seqStr, modifications, AminoAcidSet);

            double score;
            int nMatchedFragments;

            GetCompositeScores(seqObj, charge, ms2ScanNum, out score, out nMatchedFragments);
            return new IcScores(nMatchedFragments, score, modifications);
        }
Beispiel #17
0
        public double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition)
        {
            var score = 0.0;

            foreach (var ionType in _scorer.GetIonTypes(_charge, _sequenceMass))
            {
                var monoMz = ionType.IsPrefixIon
                    ? ionType.GetMz(prefixFragmentComposition)
                    : ionType.GetMz(suffixFragmentComposition);

                //_rankedSpec.RankIon(ionType, )
                var peak = _rankedSpec.FindPeak(monoMz, _tolerance);
                if (peak == null)
                {
                    score += _scorer.GetScore(ionType, -1, _charge, _sequenceMass);  // missing
                }
                else
                {
                    score += _scorer.GetScore(ionType, peak.Rank, _charge, _sequenceMass);
                }
            }
            return score;
        }
Beispiel #18
0
 public MsPathFinderId(int scan, char pre, string sequence, char post, string modifications,
     Composition composition, string proteinName, string proteinDesc, int proteinLength,
     int start, int end, int charge, double mostAbundantIsotopeMz, double mass,
     int numMatchedFragments, double qValue, double pepQValue)
 {
     Scan = scan;
     Pre = pre;
     Sequence = sequence;
     Post = post;
     Modifications = modifications;
     Composition = composition;
     ProteinName = proteinName;
     ProteinDesc = proteinDesc;
     ProteinLength = proteinLength;
     Start = start;
     End = end;
     Charge = charge;
     MostAbundantIsotopeMz = mostAbundantIsotopeMz;
     Mass = mass;
     NumMatchedFragments = numMatchedFragments;
     QValue = qValue;
     PepQValue = pepQValue;
 }
Beispiel #19
0
        internal ScoringGraph(AminoAcid[] aminoAcidSequence, Composition sequenceComposition, ScoringGraphNode rootNode,
                            int minPrecursorCharge, int maxPrecursorCharge)
        {
            _aminoAcidSequence = aminoAcidSequence;
            _sequenceComposition = sequenceComposition;
            _rootNode = rootNode;
            _minPrecursorCharge = minPrecursorCharge;
            _maxPrecursorCharge = maxPrecursorCharge;

            _precursorIon = new Dictionary<int, Ion>();
            for (var precursorCharge = _minPrecursorCharge; precursorCharge <= _maxPrecursorCharge; precursorCharge++)
            {
                _precursorIon[precursorCharge] = new Ion(_sequenceComposition, precursorCharge);
            }

            // store all nodes in an array
            var nodes = new HashSet<ScoringGraphNode>();

            var curNodes = new HashSet<ScoringGraphNode> { _rootNode };
            while (curNodes.Any())
            {
                var newNodes = new HashSet<ScoringGraphNode>();
                foreach (var node in curNodes)
                {
                    if (nodes.Add(node))    // if node is new
                    {
                        foreach (var nextNode in node.GetNextNodes())
                        {
                            newNodes.Add(nextNode);
                        }
                    }
                }
                curNodes = newNodes;
            }

            _nodes = nodes.ToArray();
        }
        public override double GetFragmentScore(Composition prefixFragmentComposition, Composition suffixFragmentComposition)
        {
            var score = 0.0;
            var prefixHit = false;
            var suffixHit = false;

            foreach (var baseIonType in BaseIonTypes)
            {
                var fragmentComposition = baseIonType.IsPrefix
                    ? prefixFragmentComposition + baseIonType.OffsetComposition
                    : suffixFragmentComposition + baseIonType.OffsetComposition;

                var param = baseIonType.IsPrefix ? ScoreParam.Prefix : ScoreParam.Suffix;

                var massBinNum = _comparer.GetBinNumber(fragmentComposition.Mass);
                if (massBinNum >= 0 && massBinNum < _comparer.NumberOfBins)
                {
                    DeconvolutedPeak existingPeak;
                    if (_massBinToPeakMap.TryGetValue(massBinNum, out existingPeak))
                    {
                        var massErrorPpm = 1e6 * (Math.Abs(existingPeak.Mass - fragmentComposition.Mass)/fragmentComposition.Mass);
                        score += param.Count;
                        score += param.Intensity * Math.Min(existingPeak.Intensity / ReferencePeakIntensity, 1.0); // intensity-based scoring
                        score += param.Dist * existingPeak.Dist; // Envelope distance-based scoring
                        score += param.Corr * existingPeak.Corr; // Envelope correlation-based scoring
                        score += param.MassError * massErrorPpm; // Envelope correlation-based scoring

                        if (baseIonType.IsPrefix) prefixHit = true;
                        else suffixHit = true;
                    }
                }
            }

            if (prefixHit && suffixHit) score += ScoreParam.ComplementaryIonCount;
            return score;
        }
 private CompositionWithDeltaMass(Composition composition, double deltaMass, int deltaNominalMass)
     : base(composition)
 {
     _deltaMass = deltaMass;
     _deltaNominalMass = deltaNominalMass;
 }
 /// <summary>
 /// The reduced mass.
 /// </summary>
 /// <param name="targetMz">
 /// The Target MZ.
 /// </param>
 /// <param name="bufferGas">
 /// The buffer gas composition. 
 /// Example: N2
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public static double ComputeReducedMass(double targetMz, Composition bufferGas)
 {
     double bufferGasMass = bufferGas.Mass;
     double result = (bufferGasMass * targetMz) / (bufferGasMass + targetMz);
     return result;
 }
Beispiel #23
0
        // Added by Chris
        /// <summary>
        /// Register a new modification or update existing modification.
        /// </summary>
        /// <param name="name">The name of the modification.</param>
        /// <param name="composition">The composition of the modification.</param>
        /// <returns>Registered modification.</returns>
        public static Modification UpdateAndGetModification(string name, Composition.Composition composition)
        {
            if (NameToModMap.ContainsKey(name)) NameToModMap.Remove(name);

            var massStr = string.Format("{0:N3}", composition.Mass);
            if (MassToModMap.ContainsKey(massStr)) MassToModMap.Remove(massStr);

            var modification = new Modification(-1, composition, name);
            Register(modification);

            return modification;
        }
 public IcBottomUpScores GetScores(DatabaseSequenceSpectrumMatch match, Composition composition, int charge,
     int ms2ScanNum)
 {
     return GetScores(match.Pre, match.Sequence, match.Post, match.NTerm, match.CTerm, composition, charge, ms2ScanNum);
 }
        /// <summary>
        /// The close parenthesis.
        /// </summary>
        /// <param name="stringToBeClosed">
        /// The string to be closed.
        /// </param>
        /// <param name="leftOver">
        /// The left over.
        /// </param>
        /// <param name="leftParenthesisSymbols">
        /// The left parenthesis symbols.
        /// </param>
        /// <param name="rightParenthesisSymbols">
        /// The right parenthesis symbols.
        /// </param>
        /// <returns>
        /// The <see cref="Composition"/>.
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        /// <exception cref="ArgumentException">
        /// </exception>
        private static Composition CloseParenthesis(string stringToBeClosed, out string leftOver)
        {
            int index = 0; // reset index
            string insideParenthesisFormula = "";
            bool isNumeric = false;

            int opennings = 1;
            while (index < stringToBeClosed.Length && opennings != 0)
            {
                if (IsClose(stringToBeClosed[index]))
                {
                    opennings--;
                }

                if (IsOpen(stringToBeClosed[index]))
                {
                    opennings++;
                }

                if (opennings != 0)
                {
                    insideParenthesisFormula += stringToBeClosed[index];
                    index++;
                }
            }

            index++;
            if (index < stringToBeClosed.Length)
            {
                isNumeric = Char.IsNumber(stringToBeClosed[index]);
            }

            int multiplier = isNumeric ? stringToBeClosed[index] - '0' : 1;

            Composition inside = ParseEmpiricalFormula(insideParenthesisFormula);

            Composition summedInside = new Composition(0,0,0,0,0);

            // multiply molecule the composition
            for (int i = 0; i < multiplier; i++)
            {
                summedInside += inside;
            }

            if (isNumeric)
            {
                index++;
            }

            leftOver = stringToBeClosed.Substring(index);

            return summedInside;
        }
Beispiel #26
0
 private BaseIonType(string symbol, bool isPrefix, Composition.Composition offsetComposition)
 {
     Symbol = symbol;
     IsPrefix = isPrefix;
     OffsetComposition = offsetComposition;
 }
Beispiel #27
0
 public NeutralLoss(string name, Composition.Composition composition)
 {
     Name = name;
     Composition = composition;
 }
Beispiel #28
0
 private static int GetMassIndex(Composition precursorComposition)
 {
     var m = precursorComposition.Mass;
     return m < 1200 ? 1 : (m < 2400 ? 2 : 3);
 }
        /// <summary>
        /// The compute mobility info.
        /// </summary>
        /// <param name="target">
        /// The inferred target.
        /// </param>
        /// <returns>
        /// The <see cref="double"/>.
        /// </returns>
        private MobilityInfo ComputeMobilityInfo(IImsTarget target)
        {
            // Convert the track into a Continuous XY data points.
            this.mobilityInfo.Mobility = this.driftTubeLengthInMeters * this.driftTubeLengthInMeters * 1000 / (this.FitLine.Slope);
            this.mobilityInfo.RSquared = this.FitLine.RSquared;
            this.mobilityInfo.T0 = this.FitLine.Intercept;

            Composition bufferGas = new Composition(0, 0, 2, 0, 0);
            double reducedMass = MoleculeUtil.ComputeReducedMass(target.MassWithAdduct, bufferGas);
            double meanTemperatureInKelvin = this.GetGlobalMeanTemperature();
            this.mobilityInfo.CollisionCrossSectionArea = MoleculeUtil.ComputeCrossSectionalArea(
                meanTemperatureInKelvin,
                this.mobilityInfo.Mobility,
                target.ChargeState,
                reducedMass);

            return this.mobilityInfo;
        }
Beispiel #30
0
 private static int GetLocationIndex(Composition precursorComposition, Composition cutComposition)
 {
     return (int)(cutComposition.Mass / precursorComposition.Mass * 4 + 1);
 }