Package Bio :: Package Align :: Module AlignInfo :: Class SummaryInfo
[hide private]
[frames] | no frames]

Class SummaryInfo

source code

object --+
         |
        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.

Instance Methods [hide private]
 
__init__(self, alignment)
Initialize with the alignment to calculate information on.
source code
 
dumb_consensus(self, threshold=0.7, ambiguous='X', consensus_alpha=None, require_multiple=0)
Output a fast consensus sequence of the alignment.
source code
 
gap_consensus(self, threshold=0.7, ambiguous='X', consensus_alpha=None, require_multiple=0)
Same as dumb_consensus(), but allows gap on the output.
source code
 
_guess_consensus_alphabet(self, ambiguous)
Pick an (ungapped) alphabet for an alignment consesus sequence.
source code
 
replacement_dictionary(self, skip_chars=[])
Generate a replacement dictionary to plug into a substitution matrix
source code
 
_pair_replacement(self, seq1, seq2, weight1, weight2, start_dict, ignore_chars)
Compare two sequences and generate info on the replacements seen.
source code
 
_get_all_letters(self)
Returns a string containing the expected letters in the alignment.
source code
 
_get_base_replacements(self, skip_items=[])
Get a zeroed dictionary of all possible letter combinations.
source code
 
pos_specific_score_matrix(self, axis_seq=None, chars_to_ignore=[])
Create a position specific score matrix object for the alignment.
source code
 
_get_base_letters(self, letters)
Create a zeroed dictionary with all of the specified letters.
source code
 
information_content(self, start=0, end=None, e_freq_table=None, log_base=2, chars_to_ignore=[])
Calculate the information content for each residue along an alignment.
source code
 
_get_letter_freqs(self, residue_num, all_records, letters, to_ignore)
Determine the frequency of specific letters in the alignment.
source code
 
_get_column_info_content(self, obs_freq, e_freq_table, log_base, random_expected)
Calculate the information content for a column.
source code
 
get_column(self, col) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, alignment)
(Constructor)

source code 

Initialize with the alignment to calculate information on.

ic_vector attribute. A dictionary. Keys: column numbers. Values:

Overrides: object.__init__

dumb_consensus(self, threshold=0.7, ambiguous='X', consensus_alpha=None, require_multiple=0)

source code 

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

gap_consensus(self, threshold=0.7, ambiguous='X', consensus_alpha=None, require_multiple=0)

source code 

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.

_guess_consensus_alphabet(self, ambiguous)

source code 

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.

replacement_dictionary(self, skip_chars=[])

source code 

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.

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

_pair_replacement(self, seq1, seq2, weight1, weight2, start_dict, ignore_chars)

source code 

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.

_get_base_replacements(self, skip_items=[])

source code 

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

pos_specific_score_matrix(self, axis_seq=None, chars_to_ignore=[])

source code 

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

information_content(self, start=0, end=None, e_freq_table=None, log_base=2, chars_to_ignore=[])

source code 

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 characterw which should be ignored in calculating the info content.
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_letter_freqs(self, residue_num, all_records, letters, to_ignore)

source code 

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.

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.

_get_column_info_content(self, obs_freq, e_freq_table, log_base, random_expected)

source code 

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.