Permalink
Browse files

Define annotations attribute for MultipleSeqAlignment object

  • Loading branch information...
1 parent 47b6fd7 commit ba3f758bf7f2008e0da35b8f7df5e4e7cda232e5 @peterjc peterjc committed Dec 30, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 Bio/Align/__init__.py
View
@@ -106,7 +106,8 @@ class MultipleSeqAlignment(_Alignment):
reference sequence with special status.
"""
- def __init__(self, records, alphabet=None):
+ def __init__(self, records, alphabet=None,
+ annotations=None):
"""Initialize a new MultipleSeqAlignment object.
Arguments:
@@ -117,6 +118,7 @@ def __init__(self, records, alphabet=None):
alphabet, which should be a super-set of the individual
record alphabets. If omitted, a consensus alphabet is
used.
+ - annotations - Information about the whole alignment (dictionary).
You would normally load a MSA from a file using Bio.AlignIO, but you
can do this from a list of SeqRecord objects too:
@@ -127,12 +129,14 @@ def __init__(self, records, alphabet=None):
>>> a = SeqRecord(Seq("AAAACGT", generic_dna), id="Alpha")
>>> b = SeqRecord(Seq("AAA-CGT", generic_dna), id="Beta")
>>> c = SeqRecord(Seq("AAAAGGT", generic_dna), id="Gamma")
- >>> align = MultipleSeqAlignment([a, b, c])
+ >>> align = MultipleSeqAlignment([a, b, c], annotations={"tool": "demo"})
>>> print align
DNAAlphabet() alignment with 3 rows and 7 columns
AAAACGT Alpha
AAA-CGT Beta
AAAAGGT Gamma
+ >>> align.annotations
+ {'tool': 'demo'}
NOTE - The older Bio.Align.Generic.Alignment class only accepted a
single argument, an alphabet. This is still supported via a backwards
@@ -174,6 +178,13 @@ def __init__(self, records, alphabet=None):
rec in self._records
if rec.seq is not None)
+ # Annotations about the whole alignment
+ if annotations is None:
+ annotations = {}
+ elif not isinstance(annotations, dict):
+ raise TypeError("annotations argument should be a dict")
+ self.annotations = annotations
+
def extend(self, records):
"""Add more SeqRecord objects to the alignment as rows.

0 comments on commit ba3f758

Please sign in to comment.