Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
Bio.Phylo.PhyloXML.Sequence Class Reference
Inheritance diagram for Bio.Phylo.PhyloXML.Sequence:
Inheritance graph
[legend]
Collaboration diagram for Bio.Phylo.PhyloXML.Sequence:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def from_seqrecord
def to_seqrecord
def get_alphabet
def __repr__

Public Attributes

 type
 id_ref
 id_source
 symbol
 accession
 name
 location
 mol_seq
 uri
 domain_architecture
 annotations
 other

Static Public Attributes

dictionary alphabets
tuple re_symbol = re.compile(r'\S{1,10}')

Detailed Description

A molecular sequence (Protein, DNA, RNA) associated with a node.

One intended use for ``id_ref`` is to link a sequence to a taxonomy (via the
taxonomy's ``id_source``) in case of multiple sequences and taxonomies per
node.

:Parameters:
    type : {'dna', 'rna', 'protein'}
        type of molecule this sequence represents
    id_ref : string
        reference to another resource
    id_source : string
        source for the reference
    symbol : string
        short symbol of the sequence, e.g. 'ACTM' (max. 10 chars)
    accession : Accession
        accession code for this sequence.
    name : string
        full name of the sequence, e.g. 'muscle Actin'
    location
        location of a sequence on a genome/chromosome.
    mol_seq : MolSeq
        the molecular sequence itself
    uri : Uri
        link
    annotations : list of Annotation objects
        annotations on this sequence
    domain_architecture : DomainArchitecture
        protein domains on this sequence
    other : list of Other objects
        non-phyloXML elements

Definition at line 979 of file PhyloXML.py.


Constructor & Destructor Documentation

def Bio.Phylo.PhyloXML.Sequence.__init__ (   self,
  type = None,
  id_ref = None,
  id_source = None,
  symbol = None,
  accession = None,
  name = None,
  location = None,
  mol_seq = None,
  uri = None,
  domain_architecture = None,
  annotations = None,
  other = None 
)

Definition at line 1025 of file PhyloXML.py.

01025 
01026             ):
01027         _check_str(type, self.alphabets.__contains__)
01028         _check_str(symbol, self.re_symbol.match)
01029         self.type = type
01030         self.id_ref = id_ref
01031         self.id_source = id_source
01032         self.symbol = symbol
01033         self.accession = accession
01034         self.name = name
01035         self.location = location
01036         self.mol_seq = mol_seq
01037         self.uri = uri
01038         self.domain_architecture = domain_architecture
01039         self.annotations = annotations or []
01040         self.other = other or []

Here is the call graph for this function:


Member Function Documentation

def Bio.Phylo.BaseTree.TreeElement.__repr__ (   self) [inherited]
Show this object's constructor with its primitive arguments.

Definition at line 216 of file BaseTree.py.

00216 
00217     def __repr__(self):
00218         """Show this object's constructor with its primitive arguments."""
00219         def pair_as_kwarg_string(key, val):
00220             if isinstance(val, basestring):
00221                 return "%s='%s'" % (key, _sugar.trim_str(unicode(val)))
00222             return "%s=%s" % (key, val)
00223         return u'%s(%s)' % (self.__class__.__name__,
00224                             ', '.join(pair_as_kwarg_string(key, val)
00225                                   for key, val in self.__dict__.iteritems()
00226                                   if val is not None and
00227                                   type(val) in (str, int, float, bool, unicode)
00228                                   ))

def Bio.Phylo.PhyloXML.Sequence.from_seqrecord (   cls,
  record,
  is_aligned = None 
)
Create a new PhyloXML Sequence from a SeqRecord object.

Definition at line 1042 of file PhyloXML.py.

01042 
01043     def from_seqrecord(cls, record, is_aligned=None):
01044         """Create a new PhyloXML Sequence from a SeqRecord object."""
01045         if is_aligned == None:
01046             is_aligned = isinstance(record.seq.alphabet, Alphabet.Gapped)
01047         params = {
01048                 'accession': Accession(record.id, ''),
01049                 'symbol': record.name,
01050                 'name': record.description,
01051                 'mol_seq': MolSeq(str(record.seq), is_aligned),
01052                 }
01053         if isinstance(record.seq.alphabet, Alphabet.DNAAlphabet):
01054             params['type'] = 'dna'
01055         elif isinstance(record.seq.alphabet, Alphabet.RNAAlphabet):
01056             params['type'] = 'rna'
01057         elif isinstance(record.seq.alphabet, Alphabet.ProteinAlphabet):
01058             params['type'] = 'protein'
01059 
01060         # Unpack record.annotations
01061         for key in ('id_ref', 'id_source', 'location'):
01062             if key in record.annotations:
01063                 params[key] = record.annotations[key]
01064         if isinstance(record.annotations.get('uri'), dict):
01065             params['uri'] = Uri(**record.annotations['uri'])
01066         # Build a Sequence.annotation object
01067         if record.annotations.get('annotations'):
01068             params['annotations'] = []
01069             for annot in record.annotations['annotations']:
01070                 ann_args = {}
01071                 for key in ('ref', 'source', 'evidence', 'type', 'desc'):
01072                     if key in annot:
01073                         ann_args[key] = annot[key]
01074                 if isinstance(annot.get('confidence'), list):
01075                     ann_args['confidence'] = Confidence(
01076                                         *annot['confidence'])
01077                 if isinstance(annot.get('properties'), list):
01078                     ann_args['properties'] = [Property(**prop)
01079                                         for prop in annot['properties']
01080                                         if isinstance(prop, dict)]
01081                 params['annotations'].append(Annotation(**ann_args))
01082 
01083         # Unpack record.features
01084         if record.features:
01085             params['domain_architecture'] = DomainArchitecture(
01086                     length=len(record.seq),
01087                     domains=[ProteinDomain.from_seqfeature(feat)
01088                              for feat in record.features])
01089 
01090         return Sequence(**params)

Definition at line 1166 of file PhyloXML.py.

01166 
01167     def get_alphabet(self):
01168         alph = self.alphabets.get(self.type, Alphabet.generic_alphabet)
01169         if self.mol_seq and self.mol_seq.is_aligned:
01170             return Alphabet.Gapped(alph)
01171         return alph
01172 

Here is the caller graph for this function:

Create a SeqRecord object from this Sequence instance.

The seqrecord.annotations dictionary is packed like so::

    { # Sequence attributes with no SeqRecord equivalent:
      'id_ref':     self.id_ref,
      'id_source':  self.id_source,
      'location':   self.location,
      'uri':        { 'value': self.uri.value,
              'desc': self.uri.desc,
              'type': self.uri.type },
      # Sequence.annotations attribute (list of Annotations)
      'annotations': [{ 'ref':      ann.ref,
                'source':   ann.source,
                'evidence': ann.evidence,
                'type':     ann.type,
                'confidence': [ ann.confidence.value,
                                ann.confidence.type ],
                'properties': [{ 'value': prop.value,
                                 'ref': prop.ref,
                                 'applies_to': prop.applies_to,
                                 'datatype':   prop.datatype,
                                 'unit':       prop.unit,
                                 'id_ref':     prop.id_ref }
                               for prop in ann.properties],
              } for ann in self.annotations],
    }

Definition at line 1091 of file PhyloXML.py.

01091 
01092     def to_seqrecord(self):
01093         """Create a SeqRecord object from this Sequence instance.
01094         
01095         The seqrecord.annotations dictionary is packed like so::
01096 
01097             { # Sequence attributes with no SeqRecord equivalent:
01098               'id_ref':     self.id_ref,
01099               'id_source':  self.id_source,
01100               'location':   self.location,
01101               'uri':        { 'value': self.uri.value,
01102                               'desc': self.uri.desc,
01103                               'type': self.uri.type },
01104               # Sequence.annotations attribute (list of Annotations)
01105               'annotations': [{ 'ref':      ann.ref,
01106                                 'source':   ann.source,
01107                                 'evidence': ann.evidence,
01108                                 'type':     ann.type,
01109                                 'confidence': [ ann.confidence.value,
01110                                                 ann.confidence.type ],
01111                                 'properties': [{ 'value': prop.value,
01112                                                  'ref': prop.ref,
01113                                                  'applies_to': prop.applies_to,
01114                                                  'datatype':   prop.datatype,
01115                                                  'unit':       prop.unit,
01116                                                  'id_ref':     prop.id_ref }
01117                                                for prop in ann.properties],
01118                               } for ann in self.annotations],
01119             }
01120         """
01121         def clean_dict(dct):
01122             """Remove None-valued items from a dictionary."""
01123             return dict((key, val) for key, val in dct.iteritems()
01124                         if val is not None)
01125 
01126         seqrec = SeqRecord(Seq(self.mol_seq.value, self.get_alphabet()),
01127                            **clean_dict({
01128                                'id':    str(self.accession),
01129                                'name':  self.symbol,
01130                                'description': self.name,
01131                                # 'dbxrefs': None,
01132                                }))
01133         if self.domain_architecture:
01134             seqrec.features = [dom.to_seqfeature()
01135                                for dom in self.domain_architecture.domains]
01136         # Sequence attributes with no SeqRecord equivalent
01137         seqrec.annotations = clean_dict({
01138                 'id_ref':       self.id_ref,
01139                 'id_source':    self.id_source,
01140                 'location':     self.location,
01141                 'uri':          self.uri and clean_dict({
01142                                     'value': self.uri.value,
01143                                     'desc': self.uri.desc,
01144                                     'type': self.uri.type,
01145                                     }),
01146                 'annotations':  self.annotations and [
01147                     clean_dict({
01148                         'ref':          ann.ref,
01149                         'source':       ann.source,
01150                         'evidence':     ann.evidence,
01151                         'type':         ann.type,
01152                         'confidence':   ann.confidence and [
01153                                             ann.confidence.value,
01154                                             ann.confidence.type],
01155                         'properties':   [clean_dict({
01156                                             'value':      prop.value,
01157                                             'ref':        prop.ref,
01158                                             'applies_to': prop.applies_to,
01159                                             'datatype':   prop.datatype,
01160                                             'unit':       prop.unit,
01161                                             'id_ref':     prop.id_ref })
01162                                          for prop in ann.properties],
01163                         }) for ann in self.annotations],
01164                 })
01165         return seqrec

Here is the call graph for this function:


Member Data Documentation

Definition at line 1032 of file PhyloXML.py.

Initial value:
{'dna':     Alphabet.generic_dna,
                 'rna':     Alphabet.generic_rna,
                 'protein': Alphabet.generic_protein}

Definition at line 1012 of file PhyloXML.py.

Definition at line 1038 of file PhyloXML.py.

Definition at line 1037 of file PhyloXML.py.

Definition at line 1029 of file PhyloXML.py.

Definition at line 1030 of file PhyloXML.py.

Definition at line 1034 of file PhyloXML.py.

Definition at line 1035 of file PhyloXML.py.

Definition at line 1033 of file PhyloXML.py.

Definition at line 1039 of file PhyloXML.py.

tuple Bio.Phylo.PhyloXML.Sequence.re_symbol = re.compile(r'\S{1,10}') [static]

Definition at line 1015 of file PhyloXML.py.

Definition at line 1031 of file PhyloXML.py.

Definition at line 1028 of file PhyloXML.py.

Definition at line 1036 of file PhyloXML.py.


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