Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
Bio.pairwise2.align.alignment_function Class Reference

List of all members.

Public Member Functions

def __init__
def decode
def __call__

Public Attributes

 function_name
 align_type
 param_names

Static Public Attributes

dictionary match2args
dictionary penalty2args

Private Attributes

 __name__
 __doc__

Detailed Description

This class is callable impersonates an alignment function.
The constructor takes the name of the function.  This class
will decode the name of the function to figure out how to
interpret the parameters.

Definition at line 157 of file pairwise2.py.


Constructor & Destructor Documentation

Definition at line 192 of file pairwise2.py.

00192 
00193         def __init__(self, name):
00194             # Check to make sure the name of the function is
00195             # reasonable.
00196             if name.startswith("global"):
00197                 if len(name) != 8:
00198                     raise AttributeError("function should be globalXX")
00199             elif name.startswith("local"):
00200                 if len(name) != 7:
00201                     raise AttributeError("function should be localXX")
00202             else:
00203                 raise AttributeError(name)
00204             align_type, match_type, penalty_type = \
00205                         name[:-2], name[-2], name[-1]
00206             try:
00207                 match_args, match_doc = self.match2args[match_type]
00208             except KeyError, x:
00209                 raise AttributeError("unknown match type %r" % match_type)
00210             try:
00211                 penalty_args, penalty_doc = self.penalty2args[penalty_type]
00212             except KeyError, x:
00213                 raise AttributeError("unknown penalty type %r" % penalty_type)
00214 
00215             # Now get the names of the parameters to this function.
00216             param_names = ['sequenceA', 'sequenceB']
00217             param_names.extend(match_args)
00218             param_names.extend(penalty_args)
00219             self.function_name = name
00220             self.align_type = align_type
00221             self.param_names = param_names
00222 
00223             self.__name__ = self.function_name
00224             # Set the doc string.
00225             doc = "%s(%s) -> alignments\n" % (
00226                 self.__name__, ', '.join(self.param_names))
00227             if match_doc:
00228                 doc += "\n%s\n" % match_doc
00229             if penalty_doc:
00230                 doc += "\n%s\n" % penalty_doc
00231             doc += (
00232 """\nalignments is a list of tuples (seqA, seqB, score, begin, end).
00233 seqA and seqB are strings showing the alignment between the
00234 sequences.  score is the score of the alignment.  begin and end
00235 are indexes into seqA and seqB that indicate the where the
00236 alignment occurs.
00237 """)
00238             self.__doc__ = doc


Member Function Documentation

def Bio.pairwise2.align.alignment_function.__call__ (   self,
  args,
  keywds 
)

Definition at line 299 of file pairwise2.py.

00299 
00300         def __call__(self, *args, **keywds):
00301             keywds = self.decode(*args, **keywds)
00302             return _align(**keywds)
00303         
    def __getattr__(self, attr):

Here is the call graph for this function:

def Bio.pairwise2.align.alignment_function.decode (   self,
  args,
  keywds 
)

Definition at line 239 of file pairwise2.py.

00239 
00240         def decode(self, *args, **keywds):
00241             # Decode the arguments for the _align function.  keywds
00242             # will get passed to it, so translate the arguments to
00243             # this function into forms appropriate for _align.
00244             keywds = keywds.copy()
00245             if len(args) != len(self.param_names):
00246                 raise TypeError("%s takes exactly %d argument (%d given)" \
00247                     % (self.function_name, len(self.param_names), len(args)))
00248             i = 0
00249             while i < len(self.param_names):
00250                 if self.param_names[i] in [
00251                     'sequenceA', 'sequenceB',
00252                     'gap_A_fn', 'gap_B_fn', 'match_fn']:
00253                     keywds[self.param_names[i]] = args[i]
00254                     i += 1
00255                 elif self.param_names[i] == 'match':
00256                     assert self.param_names[i+1] == 'mismatch'
00257                     match, mismatch = args[i], args[i+1]
00258                     keywds['match_fn'] = identity_match(match, mismatch)
00259                     i += 2
00260                 elif self.param_names[i] == 'match_dict':
00261                     keywds['match_fn'] = dictionary_match(args[i])
00262                     i += 1
00263                 elif self.param_names[i] == 'open':
00264                     assert self.param_names[i+1] == 'extend'
00265                     open, extend = args[i], args[i+1]
00266                     pe = keywds.get('penalize_extend_when_opening', 0)
00267                     keywds['gap_A_fn'] = affine_penalty(open, extend, pe)
00268                     keywds['gap_B_fn'] = affine_penalty(open, extend, pe)
00269                     i += 2
00270                 elif self.param_names[i] == 'openA':
00271                     assert self.param_names[i+3] == 'extendB'
00272                     openA, extendA, openB, extendB = args[i:i+4]
00273                     pe = keywds.get('penalize_extend_when_opening', 0)
00274                     keywds['gap_A_fn'] = affine_penalty(openA, extendA, pe)
00275                     keywds['gap_B_fn'] = affine_penalty(openB, extendB, pe)
00276                     i += 4
00277                 else:
00278                     raise ValueError("unknown parameter %r" \
00279                                      % self.param_names[i])
00280 
00281             # Here are the default parameters for _align.  Assign
00282             # these to keywds, unless already specified.
00283             pe = keywds.get('penalize_extend_when_opening', 0)
00284             default_params = [
00285                 ('match_fn', identity_match(1, 0)),
00286                 ('gap_A_fn', affine_penalty(0, 0, pe)),
00287                 ('gap_B_fn', affine_penalty(0, 0, pe)),
00288                 ('penalize_extend_when_opening', 0),
00289                 ('penalize_end_gaps', self.align_type == 'global'),
00290                 ('align_globally', self.align_type == 'global'),
00291                 ('gap_char', '-'),
00292                 ('force_generic', 0),
00293                 ('score_only', 0),
00294                 ('one_alignment_only', 0)
00295                 ]
00296             for name, default in default_params:
00297                 keywds[name] = keywds.get(name, default)
00298             return keywds
            

Here is the caller graph for this function:


Member Data Documentation

Definition at line 237 of file pairwise2.py.

Definition at line 222 of file pairwise2.py.

Definition at line 219 of file pairwise2.py.

Definition at line 218 of file pairwise2.py.

Initial value:
{
            'x' : ([], ''),
            'm' : (['match', 'mismatch'],
"""match is the score to given to identical characters.  mismatch isthe score given to non-identical ones."""),
            'd' : (['match_dict'],
"""match_dict is a dictionary where the keys are tuples of pairs ofcharacters and the values are the scores, e.g. ("A", "C") : 2.5."""),
            'c' : (['match_fn'],
"""match_fn is a callback function that takes two characters andreturns the score between them."""),
            }

Definition at line 165 of file pairwise2.py.

Definition at line 220 of file pairwise2.py.

Initial value:
{
            'x' : ([], ''),
            's' : (['open', 'extend'],
"""open and extend are the gap penalties when a gap is opened andextended.  They should be negative."""),
            'd' : (['openA', 'extendA', 'openB', 'extendB'],
"""openA and extendA are the gap penalties for sequenceA, and openBand extendB for sequeneB.  The penalties should be negative."""),
            'c' : (['gap_A_fn', 'gap_B_fn'],
"""gap_A_fn and gap_B_fn are callback functions that takes 1) theindex where the gap is opened, and 2) the length of the gap.  Theyshould return a gap penalty."""),
            }

Definition at line 178 of file pairwise2.py.


The documentation for this class was generated from the following file: