Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions | Private Attributes
Bio.Align.Generic.Alignment Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def __repr__
def format
def __format__
def get_all_seqs
def __iter__
def get_seq_by_num
def __len__
def get_alignment_length
def add_sequence
def get_column
def __getitem__

Private Member Functions

def _str_line

Private Attributes

 _alphabet
 _records

Detailed Description

Represent a set of alignments (DEPRECATED).

This is a base class to represent alignments, which can be subclassed
to deal with an alignment in a specific format.

With the introduction of the MultipleSeqAlignment class in Bio.Align,
this base class is deprecated and is likely to be removed in future
releases of Biopython.

Definition at line 22 of file Generic.py.


Constructor & Destructor Documentation

def Bio.Align.Generic.Alignment.__init__ (   self,
  alphabet 
)
Initialize a new Alignment object.

Arguments:
 - alphabet - The alphabet to use for the sequence objects that are
      created. This alphabet must be a gapped type.

e.g.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> print align
Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
ACTGCTAGCTAG Alpha
ACT-CTAGCTAG Beta
ACTGCTAGATAG Gamma

Definition at line 32 of file Generic.py.

00032 
00033     def __init__(self, alphabet):
00034         """Initialize a new Alignment object.
00035 
00036         Arguments:
00037          - alphabet - The alphabet to use for the sequence objects that are
00038                       created. This alphabet must be a gapped type.
00039 
00040         e.g.
00041 
00042         >>> from Bio.Alphabet import IUPAC, Gapped
00043         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00044         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00045         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00046         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00047         >>> print align
00048         Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
00049         ACTGCTAGCTAG Alpha
00050         ACT-CTAGCTAG Beta
00051         ACTGCTAGATAG Gamma
00052         """
00053         import warnings
00054         import Bio
00055         warnings.warn("With the introduction of the MultipleSeqAlignment class in Bio.Align, this base class is deprecated and is likely to be removed in a future release of Biopython.", Bio.BiopythonDeprecationWarning)
00056         if not (isinstance(alphabet, Alphabet.Alphabet) \
00057         or isinstance(alphabet, Alphabet.AlphabetEncoder)):
00058             raise ValueError("Invalid alphabet argument")
00059         self._alphabet = alphabet
00060         # hold everything at a list of SeqRecord objects
00061         self._records = []

Here is the caller graph for this function:


Member Function Documentation

def Bio.Align.Generic.Alignment.__format__ (   self,
  format_spec 
)
Returns the alignment as a string in the specified file format.

This method supports the python format() function added in
Python 2.6/3.0.  The format_spec should be a lower case
string supported by Bio.AlignIO as an output file format.
See also the alignment's format() method.

Definition at line 165 of file Generic.py.

00165 
00166     def __format__(self, format_spec):
00167         """Returns the alignment as a string in the specified file format.
00168 
00169         This method supports the python format() function added in
00170         Python 2.6/3.0.  The format_spec should be a lower case
00171         string supported by Bio.AlignIO as an output file format.
00172         See also the alignment's format() method."""
00173         if format_spec:
00174             from StringIO import StringIO
00175             from Bio import AlignIO
00176             handle = StringIO()
00177             AlignIO.write([self], handle, format_spec)
00178             return handle.getvalue()
00179         else:
00180             #Follow python convention and default to using __str__
00181             return str(self)    

Here is the caller graph for this function:

def Bio.Align.Generic.Alignment.__getitem__ (   self,
  index 
)
Access part of the alignment.

We'll use the following example alignment here for illustration:

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha",  "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",   "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma",  "ACTGCTAGATAG")
>>> align.add_sequence("Delta",  "ACTGCTTGCTAG")
>>> align.add_sequence("Epsilon","ACTGCTTGATAG")

You can access a row of the alignment as a SeqRecord using an integer
index (think of the alignment as a list of SeqRecord objects here):

>>> first_record = align[0]
>>> print first_record.id, first_record.seq
Alpha ACTGCTAGCTAG
>>> last_record = align[-1]
>>> print last_record.id, last_record.seq
Epsilon ACTGCTTGATAG

You can also access use python's slice notation to create a sub-alignment
containing only some of the SeqRecord objects:

>>> sub_alignment = align[2:5]
>>> print sub_alignment
Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
ACTGCTAGATAG Gamma
ACTGCTTGCTAG Delta
ACTGCTTGATAG Epsilon

This includes support for a step, i.e. align[start:end:step], which
can be used to select every second sequence:

>>> sub_alignment = align[::2]
>>> print sub_alignment
Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
ACTGCTAGCTAG Alpha
ACTGCTAGATAG Gamma
ACTGCTTGATAG Epsilon

Or to get a copy of the alignment with the rows in reverse order:

>>> rev_alignment = align[::-1]
>>> print rev_alignment
Gapped(IUPACUnambiguousDNA(), '-') alignment with 5 rows and 12 columns
ACTGCTTGATAG Epsilon
ACTGCTTGCTAG Delta
ACTGCTAGATAG Gamma
ACT-CTAGCTAG Beta
ACTGCTAGCTAG Alpha

Right now, these are the ONLY indexing operations supported.  The use of
a second column based index is under discussion for a future update.

Definition at line 355 of file Generic.py.

00355 
00356     def __getitem__(self, index):
00357         """Access part of the alignment.
00358 
00359         We'll use the following example alignment here for illustration:
00360 
00361         >>> from Bio.Alphabet import IUPAC, Gapped
00362         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00363         >>> align.add_sequence("Alpha",  "ACTGCTAGCTAG")
00364         >>> align.add_sequence("Beta",   "ACT-CTAGCTAG")
00365         >>> align.add_sequence("Gamma",  "ACTGCTAGATAG")
00366         >>> align.add_sequence("Delta",  "ACTGCTTGCTAG")
00367         >>> align.add_sequence("Epsilon","ACTGCTTGATAG")
00368         
00369         You can access a row of the alignment as a SeqRecord using an integer
00370         index (think of the alignment as a list of SeqRecord objects here):
00371 
00372         >>> first_record = align[0]
00373         >>> print first_record.id, first_record.seq
00374         Alpha ACTGCTAGCTAG
00375         >>> last_record = align[-1]
00376         >>> print last_record.id, last_record.seq
00377         Epsilon ACTGCTTGATAG
00378 
00379         You can also access use python's slice notation to create a sub-alignment
00380         containing only some of the SeqRecord objects:
00381 
00382         >>> sub_alignment = align[2:5]
00383         >>> print sub_alignment
00384         Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
00385         ACTGCTAGATAG Gamma
00386         ACTGCTTGCTAG Delta
00387         ACTGCTTGATAG Epsilon
00388 
00389         This includes support for a step, i.e. align[start:end:step], which
00390         can be used to select every second sequence:
00391 
00392         >>> sub_alignment = align[::2]
00393         >>> print sub_alignment
00394         Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
00395         ACTGCTAGCTAG Alpha
00396         ACTGCTAGATAG Gamma
00397         ACTGCTTGATAG Epsilon
00398 
00399         Or to get a copy of the alignment with the rows in reverse order:
00400 
00401         >>> rev_alignment = align[::-1]
00402         >>> print rev_alignment
00403         Gapped(IUPACUnambiguousDNA(), '-') alignment with 5 rows and 12 columns
00404         ACTGCTTGATAG Epsilon
00405         ACTGCTTGCTAG Delta
00406         ACTGCTAGATAG Gamma
00407         ACT-CTAGCTAG Beta
00408         ACTGCTAGCTAG Alpha
00409 
00410         Right now, these are the ONLY indexing operations supported.  The use of
00411         a second column based index is under discussion for a future update.
00412         """
00413         if isinstance(index, int):
00414             #e.g. result = align[x]
00415             #Return a SeqRecord
00416             return self._records[index]
00417         elif isinstance(index, slice):
00418             #e.g. sub_aling = align[i:j:k]
00419             #Return a new Alignment using only the specified records.
00420             #TODO - See Bug 2554 for changing the __init__ method
00421             #to allow us to do this more cleanly.
00422             sub_align = Alignment(self._alphabet)
00423             sub_align._records = self._records[index]
00424             return sub_align
00425         elif len(index)==2:
00426             raise TypeError("Row and Column indexing is not currently supported,"\
00427                             +"but may be in future.")
00428         else:
00429             raise TypeError("Invalid index type.")

Here is the caller graph for this function:

Iterate over alignment rows as SeqRecord objects.

e.g.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> for record in align:
...    print record.id
...    print record.seq
Alpha
ACTGCTAGCTAG
Beta
ACT-CTAGCTAG
Gamma
ACTGCTAGATAG

Definition at line 200 of file Generic.py.

00200 
00201     def __iter__(self):
00202         """Iterate over alignment rows as SeqRecord objects.
00203 
00204         e.g.
00205 
00206         >>> from Bio.Alphabet import IUPAC, Gapped
00207         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00208         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00209         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00210         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00211         >>> for record in align:
00212         ...    print record.id
00213         ...    print record.seq
00214         Alpha
00215         ACTGCTAGCTAG
00216         Beta
00217         ACT-CTAGCTAG
00218         Gamma
00219         ACTGCTAGATAG
00220         """
00221         return iter(self._records) 

Here is the caller graph for this function:

Returns the number of sequences in the alignment.

Use len(alignment) to get the number of sequences (i.e. the number of
rows), and alignment.get_alignment_length() to get the length of the
longest sequence (i.e. the number of columns).

This is easy to remember if you think of the alignment as being like a
list of SeqRecord objects.

Definition at line 240 of file Generic.py.

00240 
00241     def __len__(self):
00242         """Returns the number of sequences in the alignment.
00243 
00244         Use len(alignment) to get the number of sequences (i.e. the number of
00245         rows), and alignment.get_alignment_length() to get the length of the
00246         longest sequence (i.e. the number of columns).
00247 
00248         This is easy to remember if you think of the alignment as being like a
00249         list of SeqRecord objects.
00250         """
00251         return len(self._records)
    
Returns a representation of the object for debugging.

The representation cannot be used with eval() to recreate the object,
which is usually possible with simple python ojects.  For example:

<Bio.Align.Generic.Alignment instance (2 records of length 14,
SingleLetterAlphabet()) at a3c184c>

The hex string is the memory address of the object, see help(id).
This provides a simple way to visually distinguish alignments of
the same size.

Definition at line 105 of file Generic.py.

00105 
00106     def __repr__(self):
00107         """Returns a representation of the object for debugging.
00108 
00109         The representation cannot be used with eval() to recreate the object,
00110         which is usually possible with simple python ojects.  For example:
00111 
00112         <Bio.Align.Generic.Alignment instance (2 records of length 14,
00113         SingleLetterAlphabet()) at a3c184c>
00114 
00115         The hex string is the memory address of the object, see help(id).
00116         This provides a simple way to visually distinguish alignments of
00117         the same size.
00118         """
00119         #A doctest for __repr__ would be nice, but __class__ comes out differently
00120         #if run via the __main__ trick.
00121         return "<%s instance (%i records of length %i, %s) at %x>" % \
00122                (self.__class__, len(self._records),
00123                 self.get_alignment_length(), repr(self._alphabet), id(self))
00124         #This version is useful for doing eval(repr(alignment)),
00125         #but it can be VERY long:
00126         #return "%s(%s, %s)" \
00127         #       % (self.__class__, repr(self._records), repr(self._alphabet))

Here is the call graph for this function:

Returns a multi-line string summary of the alignment.

This output is intended to be readable, but large alignments are
shown truncated.  A maximum of 20 rows (sequences) and 50 columns
are shown, with the record identifiers.  This should fit nicely on a
single screen.  e.g.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> print align
Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
ACTGCTAGCTAG Alpha
ACT-CTAGCTAG Beta
ACTGCTAGATAG Gamma

See also the alignment's format method.

Definition at line 73 of file Generic.py.

00073 
00074     def __str__(self):
00075         """Returns a multi-line string summary of the alignment.
00076 
00077         This output is intended to be readable, but large alignments are
00078         shown truncated.  A maximum of 20 rows (sequences) and 50 columns
00079         are shown, with the record identifiers.  This should fit nicely on a
00080         single screen.  e.g.
00081 
00082         >>> from Bio.Alphabet import IUPAC, Gapped
00083         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00084         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00085         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00086         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00087         >>> print align
00088         Gapped(IUPACUnambiguousDNA(), '-') alignment with 3 rows and 12 columns
00089         ACTGCTAGCTAG Alpha
00090         ACT-CTAGCTAG Beta
00091         ACTGCTAGATAG Gamma
00092 
00093         See also the alignment's format method.
00094         """
00095         rows = len(self._records)
00096         lines = ["%s alignment with %i rows and %i columns" \
00097                  % (str(self._alphabet), rows, self.get_alignment_length())]
00098         if rows <= 20:
00099             lines.extend([self._str_line(rec) for rec in self._records])
00100         else:
00101             lines.extend([self._str_line(rec) for rec in self._records[:18]])
00102             lines.append("...")
00103             lines.append(self._str_line(self._records[-1]))
00104         return "\n".join(lines)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Align.Generic.Alignment._str_line (   self,
  record 
) [private]
Returns a truncated string representation of a SeqRecord (PRIVATE).

This is a PRIVATE function used by the __str__ method.

Definition at line 62 of file Generic.py.

00062 
00063     def _str_line(self, record):
00064         """Returns a truncated string representation of a SeqRecord (PRIVATE).
00065 
00066         This is a PRIVATE function used by the __str__ method.
00067         """
00068         if len(record.seq) <= 50:
00069             return "%s %s" % (record.seq, record.id)
00070         else:
00071             return "%s...%s %s" \
00072                    % (record.seq[:44], record.seq[-3:], record.id)

Here is the caller graph for this function:

def Bio.Align.Generic.Alignment.add_sequence (   self,
  descriptor,
  sequence,
  start = None,
  end = None,
  weight = 1.0 
)
Add a sequence to the alignment.

This doesn't do any kind of alignment, it just adds in the sequence
object, which is assumed to be prealigned with the existing
sequences.

Arguments:
 - descriptor - The descriptive id of the sequence being added.
       This will be used as the resulting SeqRecord's
       .id property (and, for historical compatibility,
       also the .description property)
 - sequence - A string with sequence info.
 - start - You can explicitly set the start point of the sequence.
   This is useful (at least) for BLAST alignments, which can
   just be partial alignments of sequences.
 - end - Specify the end of the sequence, which is important
 for the same reason as the start.
 - weight - The weight to place on the sequence in the alignment.
    By default, all sequences have the same weight. (0.0 =>
    no weight, 1.0 => highest weight)

Definition at line 283 of file Generic.py.

00283 
00284                      weight = 1.0):
00285         """Add a sequence to the alignment.
00286 
00287         This doesn't do any kind of alignment, it just adds in the sequence
00288         object, which is assumed to be prealigned with the existing
00289         sequences.
00290 
00291         Arguments:
00292          - descriptor - The descriptive id of the sequence being added.
00293                        This will be used as the resulting SeqRecord's
00294                        .id property (and, for historical compatibility,
00295                        also the .description property)
00296          - sequence - A string with sequence info.
00297          - start - You can explicitly set the start point of the sequence.
00298                    This is useful (at least) for BLAST alignments, which can
00299                    just be partial alignments of sequences.
00300          - end - Specify the end of the sequence, which is important
00301                  for the same reason as the start.
00302          - weight - The weight to place on the sequence in the alignment.
00303                     By default, all sequences have the same weight. (0.0 =>
00304                     no weight, 1.0 => highest weight)
00305         """
00306         new_seq = Seq(sequence, self._alphabet)
00307 
00308         #We are now effectively using the SeqRecord's .id as
00309         #the primary identifier (e.g. in Bio.SeqIO) so we should
00310         #populate it with the descriptor.
00311         #For backwards compatibility, also store this in the
00312         #SeqRecord's description property.
00313         new_record = SeqRecord(new_seq,
00314                                id = descriptor,
00315                                description = descriptor)
00316 
00317         # hack! We really need to work out how to deal with annotations
00318         # and features in biopython. Right now, I'll just use the
00319         # generic annotations dictionary we've got to store the start
00320         # and end, but we should think up something better. I don't know
00321         # if I'm really a big fan of the LocatableSeq thing they've got
00322         # in BioPerl, but I'm not positive what the best thing to do on
00323         # this is...
00324         if start:
00325             new_record.annotations['start'] = start
00326         if end:
00327             new_record.annotations['end'] = end
00328 
00329         # another hack to add weight information to the sequence
00330         new_record.annotations['weight'] = weight
00331 
00332         self._records.append(new_record)
        

Here is the caller graph for this function:

def Bio.Align.Generic.Alignment.format (   self,
  format 
)
Returns the alignment as a string in the specified file format.

The format should be a lower case string supported as an output
format by Bio.AlignIO (such as "fasta", "clustal", "phylip",
"stockholm", etc), which is used to turn the alignment into a
string.

e.g.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> print align.format("fasta")
>Alpha
ACTGCTAGCTAG
>Beta
ACT-CTAGCTAG
>Gamma
ACTGCTAGATAG
<BLANKLINE>
>>> print align.format("phylip")
 3 12
Alpha      ACTGCTAGCT AG
Beta       ACT-CTAGCT AG
Gamma      ACTGCTAGAT AG
<BLANKLINE>

For Python 2.6, 3.0 or later see also the built in format() function.

Definition at line 128 of file Generic.py.

00128 
00129     def format(self, format):
00130         """Returns the alignment as a string in the specified file format.
00131 
00132         The format should be a lower case string supported as an output
00133         format by Bio.AlignIO (such as "fasta", "clustal", "phylip",
00134         "stockholm", etc), which is used to turn the alignment into a
00135         string.
00136 
00137         e.g.
00138 
00139         >>> from Bio.Alphabet import IUPAC, Gapped
00140         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00141         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00142         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00143         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00144         >>> print align.format("fasta")
00145         >Alpha
00146         ACTGCTAGCTAG
00147         >Beta
00148         ACT-CTAGCTAG
00149         >Gamma
00150         ACTGCTAGATAG
00151         <BLANKLINE>
00152         >>> print align.format("phylip")
00153          3 12
00154         Alpha      ACTGCTAGCT AG
00155         Beta       ACT-CTAGCT AG
00156         Gamma      ACTGCTAGAT AG
00157         <BLANKLINE>
00158 
00159         For Python 2.6, 3.0 or later see also the built in format() function.
00160         """
00161         #See also the __format__ added for Python 2.6 / 3.0, PEP 3101
00162         #See also the SeqRecord class and its format() method using Bio.SeqIO
00163         return self.__format__(format)
00164 

Here is the call graph for this function:

Here is the caller graph for this function:

Return the maximum length of the alignment.

All objects in the alignment should (hopefully) have the same
length. This function will go through and find this length
by finding the maximum length of sequences in the alignment.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> align.get_alignment_length()
12

If you want to know the number of sequences in the alignment,
use len(align) instead:

>>> len(align)
3

Definition at line 252 of file Generic.py.

00252 
00253     def get_alignment_length(self):
00254         """Return the maximum length of the alignment.
00255 
00256         All objects in the alignment should (hopefully) have the same
00257         length. This function will go through and find this length
00258         by finding the maximum length of sequences in the alignment.
00259 
00260         >>> from Bio.Alphabet import IUPAC, Gapped
00261         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00262         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00263         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00264         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00265         >>> align.get_alignment_length()
00266         12
00267 
00268         If you want to know the number of sequences in the alignment,
00269         use len(align) instead:
00270 
00271         >>> len(align)
00272         3
00273         
00274         """
00275         max_length = 0
00276 
00277         for record in self._records:
00278             if len(record.seq) > max_length:
00279                 max_length = len(record.seq)
00280 
00281         return max_length

Here is the call graph for this function:

Here is the caller graph for this function:

Return all of the sequences involved in the alignment (DEPRECATED).

The return value is a list of SeqRecord objects.

This method is deprecated, as the Alignment object itself now offers
much of the functionality of a list of SeqRecord objects (e.g.
iteration or slicing to create a sub-alignment). Instead use the
Python builtin function list, i.e. my_list = list(my_align)

Definition at line 182 of file Generic.py.

00182 
00183     def get_all_seqs(self):
00184         """Return all of the sequences involved in the alignment (DEPRECATED).
00185 
00186         The return value is a list of SeqRecord objects.
00187 
00188         This method is deprecated, as the Alignment object itself now offers
00189         much of the functionality of a list of SeqRecord objects (e.g.
00190         iteration or slicing to create a sub-alignment). Instead use the
00191         Python builtin function list, i.e. my_list = list(my_align)
00192         """
00193         import warnings
00194         import Bio
00195         warnings.warn("This method is deprecated, since the alignment object"
00196                       "now acts more like a list. Instead of calling "
00197                       "align.get_all_seqs() you can use list(align)",
00198                       Bio.BiopythonDeprecationWarning)
00199         return self._records

def Bio.Align.Generic.Alignment.get_column (   self,
  col 
)
Returns a string containing a given column.

e.g.

>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")
>>> align.get_column(0)
'AAA'
>>> align.get_column(3)
'G-G'

Definition at line 333 of file Generic.py.

00333 
00334     def get_column(self,col):
00335         """Returns a string containing a given column.
00336 
00337         e.g.
00338 
00339         >>> from Bio.Alphabet import IUPAC, Gapped
00340         >>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
00341         >>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
00342         >>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
00343         >>> align.add_sequence("Gamma", "ACTGCTAGATAG")
00344         >>> align.get_column(0)
00345         'AAA'
00346         >>> align.get_column(3)
00347         'G-G'
00348         """
00349         #TODO - Support negative indices?
00350         col_str = ''
00351         assert col >= 0 and col <= self.get_alignment_length()
00352         for rec in self._records:
00353             col_str += rec.seq[col]
00354         return col_str

Here is the call graph for this function:

def Bio.Align.Generic.Alignment.get_seq_by_num (   self,
  number 
)
Retrieve a sequence by row number (DEPRECATED).

Returns:
 - A Seq object for the requested sequence.

Raises:
 - IndexError - If the specified number is out of range.

NOTE: This is a legacy method.  In new code where you need to access
the rows of the alignment (i.e. the sequences) consider iterating
over them or accessing them as SeqRecord objects.

Definition at line 222 of file Generic.py.

00222 
00223     def get_seq_by_num(self, number):
00224         """Retrieve a sequence by row number (DEPRECATED).
00225 
00226         Returns:
00227          - A Seq object for the requested sequence.
00228 
00229         Raises:
00230          - IndexError - If the specified number is out of range.
00231 
00232         NOTE: This is a legacy method.  In new code where you need to access
00233         the rows of the alignment (i.e. the sequences) consider iterating
00234         over them or accessing them as SeqRecord objects.
00235         """
00236         import warnings
00237         import Bio
00238         warnings.warn("This is a legacy method and is likely to be removed in a future release of Biopython. In new code where you need to access the rows of the alignment (i.e. the sequences) consider iterating over them or accessing them as SeqRecord objects.", Bio.BiopythonDeprecationWarning)
00239         return self._records[number].seq


Member Data Documentation

Definition at line 58 of file Generic.py.

Definition at line 60 of file Generic.py.


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