java.lang.Object
com.compomics.util.experiment.personalization.ExperimentObject
com.compomics.util.experiment.biology.aminoacids.sequence.AminoAcidSequence
All Implemented Interfaces:
TagComponent, Serializable

public class AminoAcidSequence
extends ExperimentObject
implements TagComponent
This class represents a series of amino acids with associated modifications.
Author:
Marc Vaudel
See Also:
Serialized Form
  • Constructor Details

    • AminoAcidSequence

      public AminoAcidSequence()
      Creates a blank sequence. All maps are null.
    • AminoAcidSequence

      public AminoAcidSequence​(String sequence)
      Constructor taking a sequence of amino acids as input.
      Parameters:
      sequence - a sequence of amino acids
    • AminoAcidSequence

      public AminoAcidSequence​(String sequence, ModificationMatch[] variableModifications)
      Constructor taking a sequence of amino acids as input.
      Parameters:
      sequence - a sequence of amino acids
      variableModifications - the variable modifications of this sequence
    • AminoAcidSequence

      public AminoAcidSequence​(AminoAcidSequence sequence)
      Creates a sequence from another sequence.
      Parameters:
      sequence - the other sequence
  • Method Details

    • getSequence

      public String getSequence()
      Returns the sequence as String.
      Returns:
      the sequence as String
    • charAt

      public char charAt​(int aa)
      Returns the amino acid at the given index on the sequence in its single letter code. 0 is the first amino acid.
      Parameters:
      aa - the index on the sequence
      Returns:
      the amino acid at the given index on the sequence in its single letter code
    • getAminoAcidAt

      public AminoAcid getAminoAcidAt​(int aa)
      Returns the amino acid at the given index on the sequence. 0 is the first amino acid.
      Parameters:
      aa - the index on the sequence
      Returns:
      the amino acid at the given index on the sequence
    • setSequence

      public void setSequence​(String aminoAcidSequence)
      Sets the sequence.
      Parameters:
      aminoAcidSequence - the sequence
    • setAaAtIndex

      public void setAaAtIndex​(int index, char aa)
      replaces the amino acid at the given position by the given amino acid represented by its single letter code. 0 is the first amino acid.
      Parameters:
      index - the index where the amino acid should be set.
      aa - the amino acid to be set
    • emptyInternalCaches

      public void emptyInternalCaches()
      the sequence is kept in different formats internally. Calling this method removes them from the cache.
    • matchesIn

      public boolean matchesIn​(String aminoAcidSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether the sequence is found in the given amino acid sequence.
      Parameters:
      aminoAcidSequence - the amino acid sequence
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the sequence is found in the given amino acid sequence
    • matchesIn

      public boolean matchesIn​(AminoAcidSequence aminoAcidSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether the sequence is found in the given amino acid sequence.
      Parameters:
      aminoAcidSequence - the amino acid sequence
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the sequence is found in the given amino acid sequence
    • matches

      public boolean matches​(String aminoAcidSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether the sequence matches the given amino acid sequence in size and according to the given matching preferences.
      Parameters:
      aminoAcidSequence - the amino acid sequence
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the sequence is found in the given amino acid sequence
    • matches

      public boolean matches​(AminoAcidSequence aminoAcidSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether the sequence matches the given amino acid sequence in size and according to the given matching preferences.
      Parameters:
      aminoAcidSequence - the amino acid sequence
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the sequence is found in the given amino acid sequence
    • firstIndex

      public int firstIndex​(String aminoAcidSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Returns the first index where the amino acid sequence is found in the given sequence. -1 if not found. 0 is the first amino acid.
      Parameters:
      aminoAcidSequence - the amino acid sequence to look into
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      the first index where the amino acid sequence is found
    • length

      public int length()
      Returns the length of the sequence in amino acids.
      Returns:
      the length of the sequence in amino acids
    • appendCTerm

      public void appendCTerm​(AminoAcidSequence otherSequence)
      Appends another sequence at the end of this sequence.
      Parameters:
      otherSequence - the other sequence to append.
    • appendCTerm

      public void appendCTerm​(String otherSequence)
      Appends a series of unmodified amino acids to the sequence.
      Parameters:
      otherSequence - a series of unmodified amino acids represented by their single letter code
    • insert

      public void insert​(int offset, AminoAcidSequence otherSequence)
      Inserts another sequence in this sequence.
      Parameters:
      offset - the index where this sequence should be inserted, 0 is the first amino acid.
      otherSequence - the other sequence to insert.
    • insert

      public void insert​(int offset, String otherSequence)
      Inserts another sequence in this sequence.
      Parameters:
      offset - the index where this sequence should be inserted, 0 is the first amino acid.
      otherSequence - the other sequence to insert.
    • appendNTerm

      public void appendNTerm​(AminoAcidSequence otherSequence)
      Appends another sequence at the beginning of this sequence keeping the original order.
      Parameters:
      otherSequence - the other sequence to append.
    • appendNTerm

      public void appendNTerm​(String otherSequence)
      Appends a series of unmodified amino acids to the beginning sequence keeping the original order.
      Parameters:
      otherSequence - a series of unmodified amino acids represented by their single letter code
    • getVariableModifications

      public ModificationMatch[] getVariableModifications()
      Getter for the modifications carried by this sequence in a map: aa number > modification matches. 1 is the first amino acid.
      Returns:
      the modifications matches as found by the search engine
    • getIndexedVariableModifications

      public String[] getIndexedVariableModifications()
      Returns the variable modifications indexed by site. Modifications are indexed by site as follows: N-term modifications are at index 0, C-term at sequence length + 1, and amino acid at 1-based index on the sequence.
      Returns:
      the variable modifications indexed by site
    • addVariableModification

      public void addVariableModification​(ModificationMatch modificationMatch)
      Adds a modification to one of the amino acid sequence.
      Parameters:
      modificationMatch - the modification match
    • setVariableModifications

      public void setVariableModifications​(ModificationMatch[] variableModifications)
      Sets the variable modifications.
      Parameters:
      variableModifications - the modifications
    • getFixedModifications

      public String[] getFixedModifications​(boolean nTerm, boolean cTerm, ModificationParameters modificationParameters, SequenceMatchingParameters modificationsSequenceMatchingParameters)
      Returns the fixed modifications for this sequence based on the given modification parameters. Modifications are returned as array of modification names as they appear on the sequence. N-term modifications are at index 0, C-term at index sequence length + 1, and other modifications at amino acid index starting from 1. An error is thrown if attempting to stack modifications. Protein modifications are not taken into account.
      Parameters:
      nTerm - boolean indicating whether the sequence is located at the n-term
      cTerm - boolean indicating whether the sequence is located at the c-term
      modificationParameters - the modification parameters the modification parameters
      modificationsSequenceMatchingParameters - the sequence matching parameters to use for modifications
      Returns:
      the fixed modifications for this peptide
    • isSameAs

      public boolean isSameAs​(AminoAcidSequence anotherSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether another sequence has a matching sequence. Modifications are considered equal when of same mass. Modifications should be loaded in the PTM factory.
      Parameters:
      anotherSequence - the other AminoAcidPattern
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      true if the other AminoAcidPattern targets the same sequence
    • isSameSequenceAndModificationStatusAs

      public boolean isSameSequenceAndModificationStatusAs​(AminoAcidSequence anotherSequence, SequenceMatchingParameters sequenceMatchingPreferences)
      Indicates whether another sequence targets the same sequence without accounting for PTM localization. Modifications are considered equal when of same mass. Modifications should be loaded in the PTM factory.
      Parameters:
      anotherSequence - the other sequence
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      true if the other AminoAcidPattern targets the same sequence
    • reverse

      public AminoAcidSequence reverse()
      Returns an amino acid sequence which is a reversed version of the current pattern.
      Returns:
      an amino acid sequence which is a reversed version of the current pattern
    • hasCombination

      public static boolean hasCombination​(String sequence)
      Indicates whether the given sequence contains an amino acid which is in fact a combination of amino acids.
      Parameters:
      sequence - the sequence of interest
      Returns:
      a boolean indicating whether the given sequence contains an amino acid which is in fact a combination of amino acids
    • hasCombination

      public static boolean hasCombination​(java.util.stream.IntStream sequence)
      Indicates whether the given sequence contains an amino acid which is in fact a combination of amino acids.
      Parameters:
      sequence - the sequence of interest
      Returns:
      a boolean indicating whether the given sequence contains an amino acid which is in fact a combination of amino acids
    • hasCombination

      public static boolean hasCombination​(char[] sequence)
      Indicates whether the given sequence contains an amino acid which is in fact a combination of amino acids.
      Parameters:
      sequence - the sequence of interest
      Returns:
      a boolean indicating whether the given sequence contains an amino acid which is in fact a combination of amino acids
    • getMinMass

      public static double getMinMass​(char[] sequence)
      Returns the minimal mass that an amino acid sequence can have taking into account ambiguous amino acids.
      Parameters:
      sequence - a sequence of amino acids represented by their single letter code
      Returns:
      the minimal mass the sequence can have
    • getCombinations

      public static ArrayList<StringBuilder> getCombinations​(String sequence)
      Returns a list of all combinations which can be created from a sequence when expanding ambiguous amino acids like Xs.
      Parameters:
      sequence - the sequence of interest
      Returns:
      a list of all combinations which can be created from a sequence when expanding ambiguous amino acids like Xs
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • asSequence

      public String asSequence()
      Description copied from interface: TagComponent
      Returns the tag component as String like a peptide sequence. Note: this does not include modifications.
      Specified by:
      asSequence in interface TagComponent
      Returns:
      the tag component as String like a peptide sequence
    • getMass

      public double getMass()
      Description copied from interface: TagComponent
      Returns the mass of the tag component.
      Specified by:
      getMass in interface TagComponent
      Returns:
      the mass of the tag component
    • isSameAs

      public boolean isSameAs​(TagComponent anotherCompontent, SequenceMatchingParameters sequenceMatchingPreferences)
      Description copied from interface: TagComponent
      Indicates whether another component is the same as the component of interest.
      Specified by:
      isSameAs in interface TagComponent
      Parameters:
      anotherCompontent - another component
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the other component is the same as the one of interest
    • isSameSequenceAndModificationStatusAs

      public boolean isSameSequenceAndModificationStatusAs​(TagComponent anotherCompontent, SequenceMatchingParameters sequenceMatchingPreferences)
      Description copied from interface: TagComponent
      Indicates whether another component is the same as the component of interest.
      Specified by:
      isSameSequenceAndModificationStatusAs in interface TagComponent
      Parameters:
      anotherCompontent - another component
      sequenceMatchingPreferences - the sequence matching preferences
      Returns:
      a boolean indicating whether the other component is the same as the one of interest