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.
Methods
|
|
|
|
__init__
|
__init__ ( self, alignment )
Initialize with the alignment to calculate information on.
ic_vector attribute. A dictionary. Keys: column numbers. Values:
|
|
_get_base_letters
|
_get_base_letters ( self, letters )
Create a zeroed dictionary with all of the specified letters.
|
|
_get_base_replacements
|
_get_base_replacements ( self, skip_items=[] )
Get a zeroed dictonary 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:
o The base dictionary created
o 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.
|
|
_get_column_info_content
|
_get_column_info_content (
self,
obs_freq,
e_freq_table,
log_base,
random_expected,
)
Calculate the information content for a column.
Arguments:
o obs_freq - The frequencies observed for each letter in the column.
o e_freq_table - An optional argument specifying the expected
frequencies for each letter. This is a SubsMat.FreqTable instance.
o log_base - The base of the logathrim to use in calculating the
info content.
Exceptions
|
|
ValueError("Expected frequency letters %s" + " do not match observed %s" %(e_freq_table.data.keys(), obs_freq.keys() - [ self.alignment._alphabet.gap_char ] ) )
|
|
|
_get_letter_freqs
|
_get_letter_freqs (
self,
residue_num,
all_records,
letters,
to_ignore,
)
Determine the frequency of specific letters in the alignment.
Arguments:
o residue_num - The number of the column we are getting frequencies
from.
o all_records - All of the SeqRecords in the alignment.
o letters - The letters we are interested in getting the frequency
for.
o 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.
Exceptions
|
|
ValueError("Residue %s not found in alphabet %s" %( record.seq [ residue_num ], self.alignment._alphabet ) )
|
|
|
_guess_consensus_alphabet
|
_guess_consensus_alphabet ( self )
Pick an alphabet for a consesus sequence of an alignment.
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.
Exceptions
|
|
ValueError( "Could not determine the type of alphabet." )
ValueError( "Non-gapped alphabet found in alignment object." )
|
|
|
_pair_replacement
|
_pair_replacement (
self,
seq1,
seq2,
weight1,
weight2,
start_dict,
ignore_chars,
)
Compare two sequences and generate info on the replacements seen.
Arguments:
o seq1, seq2 - The two sequences to compare.
o weight1, weight2 - The relative weights of seq1 and seq2.
o start_dict - The dictionary containing the starting replacement
info that we will modify.
o ignore_chars - A list of characters to ignore when calculating
replacements (ie. - ).
Returns:
o A replacment dictionary which is modified from initial_dict with
the information from the sequence comparison.
Exceptions
|
|
ValueError("Residues %s, %s not found in alphabet %s" %( residue1, residue2, self.alignment._alphabet ) )
|
|
|
dumb_consensus
|
dumb_consensus (
self,
threshold=.7,
ambiguous="N",
consensus_alpha=None,
require_multiple=0,
)
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:
o threshold - The threshold value that is required to add a particular
atom.
o ambiguous - The ambiguous character to be added when the threshold is
not reached.
o consensus_alpha - The alphabet to return for the consensus sequence.
If this is None, then we will try to guess the alphabet.
o 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).
|
|
get_column
|
get_column ( self, col )
|
|
information_content
|
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.
Arguments:
o 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.
o e_freq_table - A FreqTable object specifying the expected frequencies
for each letter in the alphabet we are using (ie. {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.
o log_base - The base of the logathrim to use in calculating the
information content. This defaults to 2 so the info is in bits.
o chars_to_ignore - A listing of characterw which should be ignored
in calculating the info content.
Returns:
o A number representing the info content for the specified region.
Please see the Biopython manual for more information on how information
content is calculated.
Exceptions
|
|
ValueError("Start (%s) and end (%s) are not in the range %s to %s" %(start, end, 0, len( self.alignment._records [ 0 ].seq ) ) )
ValueError, errstr
|
|
|
pos_specific_score_matrix
|
pos_specific_score_matrix (
self,
axis_seq=None,
chars_to_ignore=[],
)
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:
o chars_to_ignore - A listing of all characters not to include in
the pssm. By default, gap characters will be excluded.
o 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:
o A PSSM (position specific score matrix) object.
Exceptions
|
|
ValueError("Residue %s not found in alphabet %s" %( this_residue, self.alignment._alphabet ) )
|
|
|
replacement_dictionary
|
replacement_dictionary ( self, skip_chars=[] )
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 alignments:
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:
o 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.
|
|