/// <summary> /// Get the scores of the nodes in the GeneratingFunction scoring graph. /// </summary> /// <param name="scorer">The FLIP scoring model to use.</param> /// <param name="proteinMass">The precursor mass.</param> private double?[][] InitNodeScores(FlipScorer <DeconvolutedSpectrum> scorer, double proteinMass) { var numNodes = this.massBins.GetBinNumber(proteinMass) + 1; var nodeScores = new double?[2][]; var nTerminalFragScores = nodeScores[0] = new double?[numNodes]; var cTerminalFragScores = nodeScores[1] = new double?[numNodes]; var deconvPeaks = (DeconvolutedPeak[])scorer.ProductSpectrum.Peaks; // transform all peaks into being nterminal ions foreach (var peak in deconvPeaks) { foreach (var ionType in scorer.SelectedIonTypes) { var scores = ionType.IsPrefix ? nTerminalFragScores : cTerminalFragScores; double ionMass = peak.Mass; double fragmentMass = ionMass - ionType.OffsetComposition.Mass; var binMass = ionType.IsPrefix ? fragmentMass : proteinMass - fragmentMass; var binIndex = this.massBins.GetBinNumber(binMass); if (binIndex >= 0 && binIndex < numNodes) { var score = scorer.GetFragmentScore(peak, ionType); // Error score will come from the edge weight if (scores[binIndex] == null || score >= scores[binIndex]) { scores[binIndex] = score; } } } } return(nodeScores); }
/// <summary> /// Create a scoring graph that uses the FLIP scoring model. /// </summary> /// <param name="flipScorer">The FLIP scoring model to use.</param> /// <param name="proteinMass">The maximum mass of the scoring graph.</param> /// <returns>The scoring graph that uses the FLIP scoring model.</returns> public FlipScoringGraph GetScoringGraph(FlipScorer <DeconvolutedSpectrum> flipScorer, double proteinMass) { var proteinMassBin = this.massBins.GetBinNumber(proteinMass); // Precalculate scores for all nodes var nodeScores = this.InitNodeScores(flipScorer, proteinMass); // Filter the edges for the scoring graph. var graphEdges = this.edges.Where(edge => edge.SinkNodeIndex <= proteinMassBin) .Select(edge => new FlipScoringGraphEdge(edge.PrevNodeIndex, edge.SinkNodeIndex, edge.Weight, edge.Label, flipScorer)) .GroupBy(edge => edge.SinkNodeIndex) .ToDictionary(edgeGroup => edgeGroup.Key, edgeGroup => edgeGroup.ToList()); return(new FlipScoringGraph(this.massBins, nodeScores[0], nodeScores[1], graphEdges)); }
/// <summary> /// Get the scorer by scan number. /// </summary> /// <param name="scanNum">The scan number to get the scorer for.</param> /// <param name="precursorMass">The precursor mass to get the scorer for.</param> /// <param name="precursorCharge">The precursor charge to get the scorer for.</param> /// <param name="activationMethod">The activation method to get the scorer for.</param> /// <returns>The scorer selected based on the arguments.</returns> public IScorer GetScorer(int scanNum, double precursorMass = 0, int precursorCharge = 1, ActivationMethod activationMethod = ActivationMethod.Unknown) { IScorer scorer; if (this.scorerHash.ContainsKey(scanNum)) { scorer = this.scorerHash[scanNum]; } else { var parameters = this.scoringParameterSet.GetScoringParameters(activationMethod, precursorMass); scorer = new FlipScorer <DeconvolutedSpectrum>(parameters, this.lcmsRun.GetSpectrum(scanNum) as DeconvolutedSpectrum); this.scorerHash.Add(scanNum, scorer); } return(scorer); }