biopython v1.71.0 Bio.Align.AlignInfo.SummaryInfo

Calculate summary info about the alignment.

This class should be used to caclculate information summarizing the results of an alignment. This may either be straight consensus info or more complicated things.

Link to this section Summary

Functions

Initialize with the alignment to calculate information on

Return a string containing the expected letters in the alignment

Create a zeroed dictionary with all of the specified letters (PRIVATE)

Get a zeroed dictionary of all possible letter combinations

Calculate the information content for a column

Return the gap character used in the alignment (PRIVATE)

Determine the frequency of specific letters in the alignment

Pick an (ungapped) alphabet for an alignment consesus sequence

Compare two sequences and generate info on the replacements seen

Output a fast consensus sequence of the alignment

Output a fast consensus sequence of the alignment, allowing gaps

Calculate the information content for each residue along an alignment

Create a position specific score matrix object for the alignment

Generate a replacement dictionary to plug into a substitution matrix

Link to this section Functions

Initialize with the alignment to calculate information on.

ic_vector attribute. A list of ic content for each column number.

Link to this function _get_all_letters()

Return a string containing the expected letters in the alignment.

Link to this function _get_base_letters()

Create a zeroed dictionary with all of the specified letters (PRIVATE).

Link to this function _get_base_replacements()

Get a zeroed dictionary of all possible letter combinations.

This looks at the type of alphabet and gets the letters for it. It then creates a dictionary with all possible combinations of these letters as keys (ie. (‘A’, ‘G’)) and sets the values as zero.

Returns:

  • The base dictionary created
  • A list of alphabet items to skip when filling the dictionary. (Right now the only thing I can imagine in this list is gap characters, but maybe X’s or something else might be useful later. This will also include any characters that are specified to be skipped.) Defaults to an empty list.
Link to this function _get_column_info_content()

Calculate the information content for a column.

Arguments:

  • obs_freq - The frequencies observed for each letter in the column.
  • e_freq_table - An optional argument specifying the expected frequencies for each letter. This is a SubsMat.FreqTable instance.
  • log_base - The base of the logathrim to use in calculating the info content.
Link to this function _get_gap_char()

Return the gap character used in the alignment (PRIVATE).

Link to this function _get_letter_freqs()

Determine the frequency of specific letters in the alignment.

Arguments:

  • residue_num - The number of the column we are getting frequencies from.
  • all_records - All of the SeqRecords in the alignment.
  • letters - The letters we are interested in getting the frequency for.
  • to_ignore - Letters we are specifically supposed to ignore.
  • pseudo_count - Optional argument specifying the Pseudo count (k) to add in order to prevent a frequency of 0 for a letter.
  • e_freq_table - An optional argument specifying the expected frequencies for each letter. This is a SubsMat.FreqTable instance.
  • random_expected - Optional argument that specify the frequency to use when e_freq_table is not defined.

This will calculate the frequencies of each of the specified letters in the alignment at the given frequency, and return this as a dictionary where the keys are the letters and the values are the frequencies. Pseudo count can be added to prevent a null frequency

Link to this function _guess_consensus_alphabet()

Pick an (ungapped) alphabet for an alignment consesus sequence.

This just looks at the sequences we have, checks their type, and returns as appropriate type which seems to make sense with the sequences we’ve got.

Link to this function _pair_replacement()

Compare two sequences and generate info on the replacements seen.

Arguments:

  • seq1, seq2 - The two sequences to compare.
  • weight1, weight2 - The relative weights of seq1 and seq2.
  • start_dict - The dictionary containing the starting replacement info that we will modify.
  • ignore_chars - A list of characters to ignore when calculating replacements (ie. ‘-‘).

Returns:

  • A replacment dictionary which is modified from initial_dict with the information from the sequence comparison.
Link to this function dumb_consensus()

Output a fast consensus sequence of the alignment.

This doesn’t do anything fancy at all. It will just go through the sequence residue by residue and count up the number of each type of residue (ie. A or G or T or C for DNA) in all sequences in the alignment. If the percentage of the most common residue type is greater then the passed threshold, then we will add that residue type, otherwise an ambiguous character will be added.

This could be made a lot fancier (ie. to take a substitution matrix into account), but it just meant for a quick and dirty consensus.

Arguments:

  • threshold - The threshold value that is required to add a particular atom.
  • ambiguous - The ambiguous character to be added when the threshold is not reached.
  • consensus_alpha - The alphabet to return for the consensus sequence. If this is None, then we will try to guess the alphabet.
  • require_multiple - If set as 1, this will require that more than 1 sequence be part of an alignment to put it in the consensus (ie. not just 1 sequence and gaps).
Link to this function gap_consensus()

Output a fast consensus sequence of the alignment, allowing gaps.

Same as dumb_consensus(), but allows gap on the output.

Things to do:

  • Let the user define that with only one gap, the result character in consensus is gap.
  • Let the user select gap character, now it takes the same as input.
Link to this function information_content()

Calculate the information content for each residue along an alignment.

Arguments:

  • start, end - The starting an ending points to calculate the information content. These points should be relative to the first sequence in the alignment, starting at zero (ie. even if the ‘real’ first position in the seq is 203 in the initial sequence, for the info content, we need to use zero). This defaults to the entire length of the first sequence.
  • e_freq_table - A FreqTable object specifying the expected frequencies for each letter in the alphabet we are using (e.g. {‘G’ : 0.4, ‘C’ : 0.4, ‘T’ : 0.1, ‘A’ : 0.1}). Gap characters should not be included, since these should not have expected frequencies.
  • log_base - The base of the logathrim to use in calculating the information content. This defaults to 2 so the info is in bits.
  • chars_to_ignore - A listing of characters which should be ignored in calculating the info content. Defaults to none.

Returns:

  • A number representing the info content for the specified region.

Please see the Biopython manual for more information on how information content is calculated.

Link to this function pos_specific_score_matrix()

Create a position specific score matrix object for the alignment.

This creates a position specific score matrix (pssm) which is an alternative method to look at a consensus sequence.

Arguments:

  • chars_to_ignore - A list of all characters not to include in the pssm. If the alignment alphabet declares a gap character, then it will be excluded automatically.
  • axis_seq - An optional argument specifying the sequence to put on the axis of the PSSM. This should be a Seq object. If nothing is specified, the consensus sequence, calculated with default parameters, will be used.

Returns:

  • A PSSM (position specific score matrix) object.
Link to this function replacement_dictionary()

Generate a replacement dictionary to plug into a substitution matrix.

This should look at an alignment, and be able to generate the number of substitutions of different residues for each other in the aligned object.

Will then return a dictionary with this information::

{('A', 'C') : 10, ('C', 'A') : 12, ('G', 'C') : 15 ....}

This also treats weighted sequences. The following example shows how we calculate the replacement dictionary. Given the following multiple sequence alignment::

GTATC  0.5
AT--C  0.8
CTGTC  1.0

For the first column we have::

('A', 'G') : 0.5 * 0.8 = 0.4
('C', 'G') : 0.5 * 1.0 = 0.5
('A', 'C') : 0.8 * 1.0 = 0.8

We then continue this for all of the columns in the alignment, summing the information for each substitution in each column, until we end up with the replacement dictionary.

Arguments:

  • skip_chars - A list of characters to skip when creating the dictionary. This defaults to an empty list.

For instance, you might have Xs (screened stuff) or Ns, and not want to include the ambiguity characters in the dictionary.