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); }
protected FeatureNode(IsotopomerFeatures isotopomerFeatures, IonType ionType, Feature precursorFeature, GroupParameter groupParameter) { _isotopomerFeatures = isotopomerFeatures; FragmentIonClassBase = ionType; PrecursorFeature = precursorFeature; GroupParameter = groupParameter; GetCorrelations(); }
public IdentifiedSequenceTag(Sequence seq, int c1, int c2, IonType[] iontypes) { CleavageIndex1 = c1; CleavageIndex2 = c2; DerivedFromPrefix = iontypes[0].IsPrefixIon; IonTypeArray = iontypes; _sequence = seq; }
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(); } }
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)); }
/// <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}; }
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)))); } }
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(); }
public FragmentOffsetFrequency(IonType ionType, float frequency) { IonType = ionType; Frequency = frequency; }
public double[] GetBinEdges(IonType ionType) { return _massError[ionType].BinEdges; }
public static float GetKLDivergence(IonType fragmentIonClassBase, IonType fragmentIonClassBaseType1, int ratio, float lcCorrelation, float imsCorrelation, FragmentParameter parameter) { throw new System.NotImplementedException(); }
//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); }
public void AddIon(IonType ionType, double found) { if (!IonFrequencies.ContainsKey(ionType)) IonFrequencies.Add(ionType, 0.0); IonFrequencies[ionType] += found; }
/// <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); }
internal static float GetIMSCorrelationScore(IonType fragmentIonClassBaseType1, IonType fragmentIonClassBaseType2, float imsCorr, FragmentParameter fragmentParameter) { throw new System.NotImplementedException(); }
public void WriteToFile(StreamWriter file, IonType[] selectedIonTypes) { }
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); }
//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); }
public FragmentFeatureNode(IsotopomerFeatures isotopomerFeatures, IonType fragmentIonClassBase, Feature precursorFeature, GroupParameter parameter, SubScoreFactory scoringParams) : base(isotopomerFeatures, fragmentIonClassBase, precursorFeature, parameter) { _scoringParams = scoringParams; }
internal double GetRatioScore(IonType ionType1, IonType ionType2, int ratio, GroupParameter parameter) { return GetScoreFromDictionary(_ratioScoreDictionary, ionType1, ionType2, ratio, parameter, LowScoreForIsotopeScore); }
internal static float GetRatioScore(IonType fragmentIonClassBaseType1, IonType fragmentIonClassBaseType2, int ratio, FragmentParameter fragmentParameter) { throw new System.NotImplementedException(); }
internal double GetRatioScore(IonType ionType, int ratio, GroupParameter parameter) // between precursor and frag ion { return GetRatioScore(ionType, ionType, ratio, parameter); }
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); }
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); } } } }
internal double GetKLDivergence(IonType ionType, int ratio, GroupParameter groupParameter) { return GetKLDivergence(ionType, ionType, ratio, groupParameter); }
public List<Ion> GetCleavageIons(IonType ionType) { var compositions = ionType.BaseIonType.IsPrefix ? Prefixes : Suffixes; return compositions.Select(ionType.GetIon).ToList(); }
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]; }
/// <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)); }
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; }