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); }
public ShiftedSequenceGraph(AminoAcidSet aminoAcidSet, double shiftedMass, bool isForward, int maxSequenceLength, double maxSequenceMass = 50000.0) { _aminoAcidSet = aminoAcidSet; _modificationParams = aminoAcidSet.GetModificationParams(); _isForward = isForward; _index = 0; _maxSeqIndex = maxSequenceLength + 2; // shift + Term + length _maxSequenceMass = maxSequenceMass; _aminoAcidSequence = new AminoAcid[_maxSeqIndex]; var shiftAa = new AminoAcid('\0', "Shift", new CompositionWithDeltaMass(shiftedMass)); _aminoAcidSequence[0] = shiftAa; ShiftMass = shiftedMass; _fragmentComposition = new Composition.Composition[_maxSeqIndex]; _fragmentComposition[0] = shiftAa.Composition; _graph = new Node[_maxSeqIndex][]; _graph[0] = new[] { new Node(0) }; _nodeComposition = new Composition.Composition[_maxSeqIndex][]; _compNodeComposition = new Composition.Composition[_maxSeqIndex][]; for (var i = 0; i < _maxSeqIndex; i++) { _compNodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; _nodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; } IsValid = true; }
public SequenceTagGenerator(LcMsRun run, Tolerance tolerance, int minTagLength = 5, int maxTagLength = 8, AminoAcid[] aminoAcidsArray = null) { _run = run; _tolerance = tolerance; _minTagLen = minTagLength; _maxTagLen = maxTagLength; _aminoAcids = aminoAcidsArray ?? AminoAcid.StandardAminoAcidArr; _ms2ScanToTagMap = new Dictionary<int, IList<SequenceTag>>(); }
public ModifiedAminoAcid(AminoAcid aa, Modification modification) : base(aa.Residue, aa.Name + "+" + modification.Name, aa.Composition + modification.Composition) { var modAa = aa as ModifiedAminoAcid; if (modAa == null) { _modification = modification; // aa is not modified } else // aa is already modified { _modification = Modification.RegisterAndGetModification(modAa.Modification.Name + "+" + modification.Name, Composition); } }
/// <summary> /// Generate a sequence graph for the provided data /// </summary> /// <param name="aminoAcidSet"></param> /// <param name="nTerm"></param> /// <param name="sequence"></param> /// <param name="cTerm"></param> protected SequenceGraph(AminoAcidSet aminoAcidSet, AminoAcid nTerm, string sequence, AminoAcid cTerm) { _aminoAcidSet = aminoAcidSet; _sequence = sequence; _nTerm = nTerm; _modificationParams = aminoAcidSet.GetModificationParams(); _maxSeqIndex = sequence.Length + 3; // init + C-term + sequence length + N-term _index = 0; _aminoAcidSequence = new AminoAcid[_maxSeqIndex]; _aminoAcidSequence[0] = AminoAcid.Empty; _suffixComposition = new Composition.Composition[_maxSeqIndex]; _suffixComposition[0] = Composition.Composition.Zero; _graph = new Node[_maxSeqIndex][]; _graph[0] = new[] { new Node(0) }; _nodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations]; _compNodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations]; for (var i = 0; i < _maxSeqIndex; i++) { _compNodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; _nodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; } NumNTermCleavages = 0; IsValid = true; SetNTerminalAminoAcid(nTerm); AddAminoAcid(cTerm.Residue); for (var i = sequence.Length - 1; i >= 0; i--) { if (AddAminoAcid(sequence[i]) == false) { IsValid = false; break; } } if (IsValid) { AddAminoAcid(nTerm.Residue); } }
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(); }
private void SetNTerminalAminoAcid(AminoAcid nTerm) { _aminoAcidSequence[_aminoAcidSequence.Length - 1 - NumNTermCleavages] = nTerm; }
/// <summary> /// Create a graph representing the sequence. Sequence is reversed. /// </summary> /// <param name="aaSet">amino acid set</param> /// <param name="nTerm">N-term amino acid</param> /// <param name="sequence">sequence</param> /// <param name="cTerm">C-term amino acid</param> /// <returns>sequence graph</returns> public static SequenceGraph CreateGraph(AminoAcidSet aaSet, AminoAcid nTerm, string sequence, AminoAcid cTerm) { var seqGraph = new SequenceGraph(aaSet, nTerm, sequence, cTerm); return(seqGraph.IsValid ? seqGraph : null); }
public void AddMatchedAminoAcid(AminoAcid aa, double massError) { AminoAcidList.Add(aa); }
internal ScoringGraph(AminoAcid[] aminoAcidSequence, Composition sequenceComposition, ScoringGraphNode rootNode) : this(aminoAcidSequence, sequenceComposition, rootNode, DefaultMinPrecursorCharge, DefaultMaxPrecursorCharge) { }
public ModifiedAminoAcid(AminoAcid aa, Modification modification) : base(aa.Residue, aa.Name+"+"+modification.Name, aa.Composition+modification.Composition) { var modAa = aa as ModifiedAminoAcid; if(modAa == null) _modification = modification; // aa is not modified else // aa is already modified { _modification = Modification.RegisterAndGetModification(modAa.Modification.Name+"+"+modification.Name, Composition); } }
public IcScores GetScores(AminoAcid nTerm, string seqStr, AminoAcid cTerm, Composition composition, int charge, int ms2ScanNum) { var spec = Run.GetSpectrum(ms2ScanNum) as ProductSpectrum; if (spec == null) return null; return GetScores(spec, seqStr, composition, charge, ms2ScanNum); }
/// <summary> /// Create a graph representing the sequence. Sequence is reversed. /// </summary> /// <param name="aaSet">amino acid set</param> /// <param name="nTerm">N-term amino acid</param> /// <param name="sequence">sequence</param> /// <param name="cTerm">C-term amino acid</param> /// <returns>sequence graph</returns> public static SequenceGraph CreateGraph(AminoAcidSet aaSet, AminoAcid nTerm, string sequence, AminoAcid cTerm) { var seqGraph = new SequenceGraph(aaSet, nTerm, sequence, cTerm); return seqGraph.IsValid ? seqGraph : null; }
protected SequenceGraph(AminoAcidSet aminoAcidSet, AminoAcid nTerm, string sequence, AminoAcid cTerm) { _aminoAcidSet = aminoAcidSet; _sequence = sequence; _nTerm = nTerm; _modificationParams = aminoAcidSet.GetModificationParams(); _maxSeqIndex = sequence.Length + 3; // init + C-term + sequence length + N-term _index = 0; _aminoAcidSequence = new AminoAcid[_maxSeqIndex]; _aminoAcidSequence[0] = AminoAcid.Empty; _suffixComposition = new Composition.Composition[_maxSeqIndex]; _suffixComposition[0] = Composition.Composition.Zero; _graph = new Node[_maxSeqIndex][]; _graph[0] = new[] { new Node(0) }; _nodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations]; _compNodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations]; for (var i = 0; i < _maxSeqIndex; i++) { _compNodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; _nodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations]; } NumNTermCleavages = 0; IsValid = true; SetNTerminalAminoAcid(nTerm); AddAminoAcid(cTerm.Residue); for (var i = sequence.Length - 1; i >= 0; i--) { if (AddAminoAcid(sequence[i]) == false) { IsValid = false; break; } } if (IsValid) AddAminoAcid(nTerm.Residue); }