/// <summary> /// Add an amino acid residue to this generator. /// </summary> /// <param name="index">index to add the amino acid. 0 is C-term. 1 is the C-term amino acid.</param> /// <param name="residue">amino acid residue to add.</param> /// <param name="loc">location of the residue</param> /// <returns>true if residue is a valid amino acid; false otherwise.</returns> private bool PutAminoAcid(int index, char residue, SequenceLocation loc) { _index = index + 1; var aminoAcid = AminoAcidSet.GetAminoAcid(residue, loc); if (aminoAcid == null) // residue is not valid { return(false); } var fragmentComposition = _fragmentComposition[_index - 1] + aminoAcid.Composition; if (fragmentComposition.Mass > _maxSequenceMass) { return(false); } _aminoAcidSequence[_index] = aminoAcid; _fragmentComposition[_index] = fragmentComposition; var modIndices = AminoAcidSet.GetModificationIndices(residue, loc); if (!modIndices.Any()) // No modification { _graph[_index] = new Node[_graph[_index - 1].Length]; for (var i = 0; i < _graph[_index - 1].Length; i++) { _graph[_index][i] = new Node(_graph[_index - 1][i].ModificationCombinationIndex, i); } } else { var modCombIndexToNodeMap = new Dictionary <int, Node>(); for (var i = 0; i < _graph[_index - 1].Length; i++) { var prevNodeIndex = i; var prevNode = _graph[_index - 1][i]; var prevModCombIndex = prevNode.ModificationCombinationIndex; // unmodified edge if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out var unmodifiedEdgeNode)) { unmodifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex); } else { modCombIndexToNodeMap.Add(prevModCombIndex, new Node(prevModCombIndex, prevNodeIndex)); } // modified edge foreach (var modIndex in modIndices) { var modCombIndex = ModificationParams.GetModificationCombinationIndex( prevNode.ModificationCombinationIndex, modIndex); if (modCombIndex < 0) // too many modifications { continue; } if (modCombIndexToNodeMap.TryGetValue(modCombIndex, out var modifiedEdgeNode)) { modifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex); } else { modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex)); } } _graph[_index] = modCombIndexToNodeMap.Values.ToArray(); } } return(true); }
/// <summary> /// Add an amino acid residue to this generator. /// </summary> /// <param name="index">index to add the amino acid. 0 is C-term. 1 is the C-term amino acid.</param> /// <param name="residue">amino acid residue to add.</param> /// <returns>true if residue is a valid amino acid; false otherwise.</returns> private bool PutAminoAcid(int index, char residue) { _index = index + 1; SequenceLocation?location = null; if (_index == 1) // C-term residue { if (residue == AminoAcid.PeptideCTerm.Residue) { location = SequenceLocation.PeptideCTerm; } else if (residue == AminoAcid.ProteinCTerm.Residue) { location = SequenceLocation.ProteinCTerm; } } else if (_index == _aminoAcidSequence.Length - 1 - NumNTermCleavages) // N-term residue { if (residue == AminoAcid.PeptideNTerm.Residue) { location = SequenceLocation.PeptideNTerm; } else if (residue == AminoAcid.ProteinNTerm.Residue) { location = SequenceLocation.ProteinNTerm; } } else if (_index == 2) // Amino acid at the C-term { if (_aminoAcidSequence[1] == AminoAcid.PeptideCTerm) { location = SequenceLocation.PeptideCTerm; } else if (_aminoAcidSequence[1] == AminoAcid.ProteinCTerm) { location = SequenceLocation.ProteinCTerm; } } else if (_index == _aminoAcidSequence.Length - 2 - NumNTermCleavages) // Amino acid at the N-term { if (_aminoAcidSequence[_aminoAcidSequence.Length - 1] == AminoAcid.PeptideNTerm) { location = SequenceLocation.PeptideNTerm; } else if (_aminoAcidSequence[_aminoAcidSequence.Length - 1] == AminoAcid.ProteinNTerm) { location = SequenceLocation.ProteinNTerm; } } else { location = SequenceLocation.Everywhere; } if (location == null) { return(false); } var loc = (SequenceLocation)location; var aminoAcid = AminoAcidSet.GetAminoAcid(residue, loc); if (aminoAcid == null) // residue is not valid { return(false); } _aminoAcidSequence[_index] = aminoAcid; _suffixComposition[_index] = _suffixComposition[_index - 1] + aminoAcid.Composition; var modIndices = AminoAcidSet.GetModificationIndices(residue, loc); if (!modIndices.Any()) // No modification { _graph[_index] = new Node[_graph[_index - 1].Length]; for (var i = 0; i < _graph[_index - 1].Length; i++) { _graph[_index][i] = new Node(_graph[_index - 1][i].ModificationCombinationIndex, i); } } else { var modCombIndexToNodeMap = new Dictionary <int, Node>(); for (var i = 0; i < _graph[_index - 1].Length; i++) { var prevNodeIndex = i; var prevNode = _graph[_index - 1][i]; var prevModCombIndex = prevNode.ModificationCombinationIndex; // unmodified edge if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out var unmodifiedEdgeNode)) { unmodifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex); } else { modCombIndexToNodeMap.Add(prevModCombIndex, new Node(prevModCombIndex, prevNodeIndex)); } // modified edge foreach (var modIndex in modIndices) { var modCombIndex = ModificationParams.GetModificationCombinationIndex( prevNode.ModificationCombinationIndex, modIndex); if (modCombIndex < 0) // too many modifications { continue; } if (modCombIndexToNodeMap.TryGetValue(modCombIndex, out var modifiedEdgeNode)) { modifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex); } else { modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex)); } } _graph[_index] = modCombIndexToNodeMap.Values.ToArray(); } } return(true); }
public void TestModificationParams() { var methodName = MethodBase.GetCurrentMethod().Name; ShowStarting(methodName); var modifications = new[] { Modification.Acetylation, Modification.Phosphorylation, Modification.Oxidation}; //, Modification.PyroGluQ }; var modParams = new ModificationParams(modifications, 3); int numCombinations = modParams.NumModificationCombinations; for (int modCombIndex = 0; modCombIndex < numCombinations; modCombIndex++) { var modCombination = modParams.GetModificationCombination(modCombIndex); Console.WriteLine("{0}: {1} {2} {3}", modCombIndex, modCombination, modCombination.Composition, modCombination.Composition.Mass); } Console.WriteLine(modParams.GetModificationCombinationIndex(8, 0)); Console.WriteLine(modParams.GetModificationCombinationIndex(19, 1)); }