Bio.Align.AlignInfo module

Extract information from alignment objects.

In order to try and avoid huge alignment objects with tons of functions, functions which return summary type information about alignments should be put into classes in this module.

class Bio.Align.AlignInfo.SummaryInfo(alignment)

Bases: object

Calculate summary info about the alignment.

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

__init__(alignment)

Initialize with the alignment to calculate information on.

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

dumb_consensus(threshold=0.7, ambiguous='X', require_multiple=False)

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.

  • require_multiple - If set as True, 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).

gap_consensus(threshold=0.7, ambiguous='X', require_multiple=False)

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.

replacement_dictionary(skip_chars=None, letters=None)

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 - Not used; setting it to anything other than None will raise a ValueError

  • letters - An iterable (e.g. a string or list of characters to include.

pos_specific_score_matrix(axis_seq=None, chars_to_ignore=None)

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.

  • 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.

information_content(start=0, end=None, e_freq_table=None, log_base=2, chars_to_ignore=None, pseudo_count=0)

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 dictionary specifying the expected frequencies for each letter (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 logarithm 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.

get_column(col)

Return column of alignment.

class Bio.Align.AlignInfo.PSSM(pssm)

Bases: object

Represent a position specific score matrix.

This class is meant to make it easy to access the info within a PSSM and also make it easy to print out the information in a nice table.

Let’s say you had an alignment like this:

GTATC
AT--C
CTGTC

The position specific score matrix (when printed) looks like:

  G A T C
G 1 1 0 1
T 0 0 3 0
A 1 1 0 0
T 0 0 2 0
C 0 0 0 3

You can access a single element of the PSSM using the following:

your_pssm[sequence_number][residue_count_name]

For instance, to get the ‘T’ residue for the second element in the above alignment you would need to do:

your_pssm[1][‘T’]

__init__(pssm)

Initialize with pssm data to represent.

The pssm passed should be a list with the following structure:

list[0] - The letter of the residue being represented (for instance, from the example above, the first few list[0]s would be GTAT… list[1] - A dictionary with the letter substitutions and counts.

__getitem__(pos)
__str__()

Return str(self).

get_residue(pos)

Return the residue letter at the specified position.

Bio.Align.AlignInfo.print_info_content(summary_info, fout=None, rep_record=0)

3 column output: position, aa in representative sequence, ic_vector value.