Ejemplo n.º 1
0
 public Probability<double> GetMassErrorProbability(double massError, IonType ionType)
 {
     var index = _massError[ionType].GetBinIndex(massError);
     if (index < 0) return new Probability<double>(massError, 0, _massError[ionType].Total);
     var found = _massError[ionType].Bins[index].Count;
     var total = _massError[ionType].Total;
     return new Probability<double>(massError, found, total);
 }
Ejemplo n.º 2
0
 protected FeatureNode(IsotopomerFeatures isotopomerFeatures, IonType ionType, Feature precursorFeature, GroupParameter groupParameter)
 {
     _isotopomerFeatures = isotopomerFeatures;
     FragmentIonClassBase = ionType;
     PrecursorFeature = precursorFeature;
     GroupParameter = groupParameter;
     GetCorrelations();
 }
Ejemplo n.º 3
0
 public IdentifiedSequenceTag(Sequence seq, int c1, int c2, IonType[] iontypes)
 {
     CleavageIndex1 = c1;
     CleavageIndex2 = c2;
     DerivedFromPrefix = iontypes[0].IsPrefixIon;
     IonTypeArray = iontypes;
     _sequence = seq;
 }
Ejemplo n.º 4
0
        public void AddMatches(List<SpectrumMatch> matches, IonType[] ionTypes, Tolerance tolerance, double relativeIntensityThreshold, bool reduceCharges=true)
        {
            foreach (var match in matches)
            {
                var spectrum = match.Spectrum;

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

                StreamWriter debugFile = File.AppendText(@"C:\Users\wilk011\Documents\DataFiles\TestFolder\bCID.txt");

                for (int i = 0; i < prefixes.Count; i++)
                {
                    var ionTypeScores = new Dictionary<string, FitScoreList>();
                    foreach (var ionType in ionTypes)
                    {
                        var cleavagePoints = ionType.BaseIonType.IsPrefix ? prefixes : suffixes;

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

                        var mostIntensePeak = GetHighestPeak(ion, spectrum, tolerance, relativeIntensityThreshold);
                        double score = GetScore(ion, spectrum, tolerance, relativeIntensityThreshold);

                        double intensity = -1.0;

                        if (mostIntensePeak != null)
                            intensity = mostIntensePeak.Intensity;

                        var name = ionType.Name;
                        if (reduceCharges)
                            name = ReducedChargeName(ionType);

                        if (!ionTypeScores.ContainsKey(name))
                            ionTypeScores.Add(name, new FitScoreList());

                        ionTypeScores[name].Add(new FitScore(intensity, score));
                    }
                    var bestScores = SelectBestScores(ionTypeScores);
                    foreach (var bestscore in bestScores)
                    {
                        var score = bestscore.Score;
                        if (_method == ScoreMethod.FitScore)
                            score = 1 - score;
                        WorstScore.Total++;
                        if (score.Equals(0))
                            WorstScore.Found++;
                        
                        debugFile.WriteLine("{0}\t{1}", bestscore.Intensity, score);
                    }
                    _intensityHistogram.AddData(bestScores);
                }
                debugFile.Close();
            }
        }
Ejemplo n.º 5
0
        public double GetScore(IonType ionType, int rankNum, int charge, double mass)
        {
            var targetRankTable = _trainingParameters.GetRankTable(charge, mass, false);
            var decoyRankTable = _trainingParameters.GetRankTable(charge, mass, true);
            var prob = targetRankTable.GetRankProbability(rankNum, ionType).Found;
            var decoyProb = decoyRankTable.GetRankProbability(rankNum, ionType).Found;

            //if (prob == 0) Console.WriteLine("*** Target: {0} {1}", ionType.Name, rankNum);
            //if (decoyProb == 0) Console.WriteLine("*** Decoy: {0} {1}", ionType.Name, rankNum);
            if (Math.Abs(prob) < 1e-10 || Math.Abs(decoyProb) < 1e-10) return 0;
            return (Math.Log(prob) - Math.Log(decoyProb));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Filter out all peaks in a spectrum that are not explained by certain ion types.
 /// </summary>
 /// <param name="sequence">Sequence to calculate ions from.</param>
 /// <param name="spectrum">Spectrum to filter.</param>
 /// <param name="ionTypes">Ion types to find peaks for.</param>
 /// <param name="tolerance"></param>
 /// <returns>Filtered Peptide Spectrum Match</returns>
 public static Spectrum FilterIonPeaks(Sequence sequence, Spectrum spectrum, IonType[] ionTypes, Tolerance tolerance)
 {
     var filteredPeaks = new List<Peak>();
     var specMatch = new SpectrumMatch(sequence, spectrum);
     foreach (var ionType in ionTypes)
     {
         var ions = specMatch.GetCleavageIons(ionType);
         foreach (var ion in ions)
         {
             var peak = spectrum.FindPeak(ion.GetMonoIsotopicMz(), tolerance);
             if (peak != null) filteredPeaks.Add(peak);
         }
     }
     filteredPeaks.Sort();
     return new Spectrum(filteredPeaks, spectrum.ScanNum) {MsLevel = 2};
 }
Ejemplo n.º 7
0
 public MassErrorTable(IonType[] ionTypes, Tolerance tolerance, double width=0.2, double binWidth=0.01, double offset=0.0)
 {
     _ionTypes = ionTypes;
     _totalPairs = 0;
     _tolerance = tolerance;
     _width = width;
     _binWidth = binWidth;
     _offset = offset;
     _massError = new Dictionary<IonType, Histogram<double>>();
     _ionPairFrequency = new Dictionary<IonType, Histogram<IonPairFound>>();
     var binEdges = GenerateEdges();
     foreach (var ionType in _ionTypes)
     {
         _massError.Add(ionType, new Histogram<double>(binEdges));
         _ionPairFrequency.Add(ionType, new Histogram<IonPairFound>((IonPairFound[])Enum.GetValues(typeof(IonPairFound))));
     }
 }
Ejemplo n.º 8
0
 public Probability<double>[] GetProbabilities(IonType ionType)
 {
     var bins = _massError[ionType].Bins;
     var binEdges = _massError[ionType].GetAlignedBinEdges(BinEdgeAlignment.Center, _binWidth);
     return binEdges.Select((t, i) => new Probability<double>(t, bins[i].Count, _totalPairs)).ToArray();
 }
Ejemplo n.º 9
0
 public FragmentOffsetFrequency(IonType ionType, float frequency)
 {
     IonType = ionType;
     Frequency = frequency;
 }
Ejemplo n.º 10
0
 public double[] GetBinEdges(IonType ionType)
 {
     return _massError[ionType].BinEdges;
 }
Ejemplo n.º 11
0
 public static float GetKLDivergence(IonType fragmentIonClassBase, IonType fragmentIonClassBaseType1, int ratio, float lcCorrelation, float imsCorrelation, FragmentParameter parameter)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 12
0
        //public override bool Equals(object obj)
        //{
        //    var type = obj as IonType;
        //    if (type != null)
        //    {
        //        var other = type;
        //        return other.IsPrefixIon.Equals(IsPrefixIon) && other.OffsetComposition.Equals(OffsetComposition) &&
        //               other.Charge == Charge;
        //    }
        //    return false;
        //}

        //public override int GetHashCode()
        //{
        //    //return IsPrefixIon.GetHashCode() + OffsetComposition.GetHashCode() + Charge.GetHashCode();

        /// <summary>
        /// Check for equality
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        protected bool Equals(IonType other)
        {
            return(Charge == other.Charge && Equals(OffsetComposition, other.OffsetComposition) && IsPrefixIon == other.IsPrefixIon);
        }
Ejemplo n.º 13
0
 public void AddIon(IonType ionType, double found)
 {
     if (!IonFrequencies.ContainsKey(ionType))
         IonFrequencies.Add(ionType, 0.0);
     IonFrequencies[ionType] += found;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Get the number of peaks found for a given rank and ion type.
 /// </summary>
 /// <param name="rankNum"></param>
 /// <param name="ionType"></param>
 /// <returns></returns>
 public Probability<IonType> GetRankProbability(int rankNum, IonType ionType)
 {
     var rankIndex = GetRankIndex(rankNum);
     var prob = _rankTable[ionType][rankIndex];
     var total = _rankTotals[rankIndex];
     return new Probability<IonType>(ionType, prob, total);
 }
Ejemplo n.º 15
0
 internal static float GetIMSCorrelationScore(IonType fragmentIonClassBaseType1, IonType fragmentIonClassBaseType2, float imsCorr, FragmentParameter fragmentParameter)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 16
0
        public void WriteToFile(StreamWriter file, IonType[] selectedIonTypes)
        {

        }
Ejemplo n.º 17
0
 private IonType ReducedChargeIonType(IonType ionType)
 {
     string name = ionType.Name;
     if (ionType.Charge > 1 && ionType.Charge < 10)
         name = name.Remove(1, 1);
     if (ionType.Charge >= 10)
         name = name.Remove(1, 2);
     return _ionTypeFactory.GetIonType(name);
 }
Ejemplo n.º 18
0
        //public override bool Equals(object obj)
        //{
        //    var type = obj as IonType;
        //    if (type != null)
        //    {
        //        var other = type;
        //        return other.IsPrefixIon.Equals(IsPrefixIon) && other.OffsetComposition.Equals(OffsetComposition) &&
        //               other.Charge == Charge;
        //    }
        //    return false;
        //}

        //public override int GetHashCode()
        //{
        //    //return IsPrefixIon.GetHashCode() + OffsetComposition.GetHashCode() + Charge.GetHashCode();

        /// <summary>
        /// Check for equality
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        protected bool Equals(IonType other)
        {
            return /*string.Equals(this.Name, other.Name) &&*/ (Charge == other.Charge && Equals(this.OffsetComposition, other.OffsetComposition) && this.IsPrefixIon == other.IsPrefixIon);
        }
Ejemplo n.º 19
0
 public FragmentFeatureNode(IsotopomerFeatures isotopomerFeatures, IonType fragmentIonClassBase, Feature precursorFeature,
     GroupParameter parameter, SubScoreFactory scoringParams)
     : base(isotopomerFeatures, fragmentIonClassBase, precursorFeature, parameter)
 {
     _scoringParams = scoringParams;
 }
Ejemplo n.º 20
0
 internal double GetRatioScore(IonType ionType1, IonType ionType2, int ratio, GroupParameter parameter)
 {
     return GetScoreFromDictionary(_ratioScoreDictionary, ionType1, ionType2, ratio, parameter, LowScoreForIsotopeScore);
 }
Ejemplo n.º 21
0
 internal static float GetRatioScore(IonType fragmentIonClassBaseType1, IonType fragmentIonClassBaseType2, int ratio, FragmentParameter fragmentParameter)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 22
0
 internal double GetRatioScore(IonType ionType, int ratio, GroupParameter parameter)  // between precursor and frag ion
 {
     return GetRatioScore(ionType, ionType, ratio, parameter);
 }
Ejemplo n.º 23
0
 internal double GetKLDivergence(IonType ionType, IonType ionType1, int ratio, GroupParameter groupParameter)
 {
     double prob1 = 1, prob2 = 1;
     var si = _ionTypeIndexDictionary[groupParameter];
     var ionTypeIndices = new Tuple<int, int> ( si[ionType], si[ionType1]); 
     if(_ratioTargetProbDictionary.ContainsKey(groupParameter))
     {
         prob1 = prob1 * _ratioTargetProbDictionary[groupParameter][ionTypeIndices][ratio];
         prob2 = prob2 * _ratioDecoyProbDictionary[groupParameter][ionTypeIndices][ratio];
     }
    
     return GetKLDivergence(prob1, prob2);
 }
Ejemplo n.º 24
0
        private void GenerateAllKnownIonTypes()
        {
            _ionTypeMap = new Dictionary<string, IonType>();

            for (int charge = 1; charge <= _maxCharge; charge++)
            {
                var chargeStr = charge == 1 ? "" : Convert.ToString(charge);
                foreach (var baseIonType in _baseIons)
                {
                    foreach (var neutralLoss in _neutralLosses)
                    {
                        var name = baseIonType.Symbol + chargeStr + neutralLoss.Name;
                        var offsetComposition = baseIonType.OffsetComposition -
                                                        neutralLoss.Composition;
                        _ionTypeMap[name] = new IonType(name, offsetComposition, charge, baseIonType, neutralLoss);
                    }
                }
            }
        }
Ejemplo n.º 25
0
 internal double GetKLDivergence(IonType ionType, int ratio, GroupParameter groupParameter)
 {
     return GetKLDivergence(ionType, ionType, ratio, groupParameter);
 }
Ejemplo n.º 26
0
 public List<Ion> GetCleavageIons(IonType ionType)
 {
     var compositions = ionType.BaseIonType.IsPrefix ? Prefixes : Suffixes;
     return compositions.Select(ionType.GetIon).ToList();
 }
Ejemplo n.º 27
0
 private double GetScoreFromDictionary(Dictionary<GroupParameter, Dictionary<Tuple<int, int>, Dictionary<int, double>>> scoreDictionary, IonType ionType1, IonType ionType2, int rawScore, GroupParameter groupParameter, double lowScore)
 {
     if (!scoreDictionary.ContainsKey(groupParameter)) return lowScore;
     var l1 = scoreDictionary[groupParameter];
     var si = _ionTypeIndexDictionary[groupParameter];
     var key = new Tuple<int, int> ( si[ionType1], si[ionType2] );
     if (!l1.ContainsKey(key)) return lowScore;
     var l2 = l1[key];
     return !l2.ContainsKey(rawScore) ? lowScore : l2[rawScore];
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Write RankTable to training parameter file.
 /// </summary>
 /// <param name="file">Open file to write RankTable to.</param>
 /// <param name="selectedIonTypes">The ion types to show in the file.
 /// All other ion types are averaged and displayed as "unexplained"</param>
 public void WriteToFile(StreamWriter file, IonType[] selectedIonTypes)
 {
     file.WriteLine("MaxRanks\t" + MaxRanks);
     var unselectedIonTypes = IonTypes.Except(selectedIonTypes).ToList();
     foreach (var ionType in selectedIonTypes)
     {
         file.Write(ionType.Name + "\t");
         for (int i = 0; i < MaxRanks+1; i++)
         {
             file.Write(Math.Round(_rankTable[ionType][i], 2) + "\t");
         }
         file.WriteLine();
     }
     var total = new double[MaxRanks+1];
     var count = new double[MaxRanks+1];
     var prob = new double[MaxRanks+1];
     for (int i = 0; i < MaxRanks+1; i++)
     {
         total[i] = 0.0;
         count[i] = 0.0;
         prob[i] = 0.0;
     }
     foreach (var ionType in unselectedIonTypes)
     {
         for (int i = 0; i < MaxRanks+1; i++)
         {
             total[i] += _rankTable[ionType][i];
             count[i]++;
         }
     }
     for (int i = 0; i < MaxRanks+1; i++) prob[i] = Math.Round(total[i] / count[i], 2);
     file.WriteLine("Unexplained\t" + string.Join("\t", prob));
     file.WriteLine("Total\t" + string.Join("\t", _rankTotals));
 }
Ejemplo n.º 29
0
 private static string ReducedChargeName(IonType ionType)
 {
     string name = ionType.Name;
     if (ionType.Charge > 1 && ionType.Charge < 10)
         name = name.Remove(1, 1);
     if (ionType.Charge >= 10)
         name = name.Remove(1, 2);
     return name;
 }