Package Bio :: Package builders :: Package SeqRecord :: Module sequence
[hide private]
[frames] | no frames]

Source Code for Module Bio.builders.SeqRecord.sequence

  1  from xml.sax import handler 
  2   
  3  from Martel import Dispatch 
  4   
  5  from Bio import SeqRecord, StdHandler, Std, DBXRef, Seq 
  6  from Bio import Alphabet, SeqFeature 
  7  from Bio.Alphabet import IUPAC 
  8   
  9  alphabet_table = { 
 10      "iupac-protein": IUPAC.protein, 
 11      "iupac-dna": IUPAC.unambiguous_dna, 
 12      "iupac-rna": IUPAC.unambiguous_rna, 
 13      "iupac-extended-protein": IUPAC.extended_protein, 
 14      "iupac-ambiguous-dna": IUPAC.ambiguous_dna, 
 15      "iupac-ambiguous-rna": IUPAC.ambiguous_rna, 
 16      "protein": Alphabet.generic_protein, 
 17      "dna": Alphabet.generic_dna, 
 18      "rna": Alphabet.generic_rna, 
 19      "unknown": Alphabet.single_letter_alphabet, 
 20      } 
 21   
 22   
 23  # Convert from the internal Feature data structure used by the parser 
 24  # into the standard Biopytho form 
25 -def convert_std_feature(feature):
26 f = SeqFeature.SeqFeature() 27 loc = feature.location 28 return feature
29
30 -class BuildSeqRecord(Dispatch.Dispatcher):
31 - def __init__(self):
45
46 - def start_record(self, tag, attrs):
47 self.dbname = None 48 self.id_text = None 49 self.name_text = '<unknown name>' 50 self.description = None 51 self.alphabet = None 52 self.seq = None 53 self.features = None 54 self.dbxrefs = []
55
56 - def add_dbid(self, text, attrs):
57 if attrs.get("type") == "primary": 58 self.dbname = attrs.get("dbname", "unknown") 59 self.id_text = text 60 # use the first accession/secondary id as the name 61 # this should be equivalent to what Biopython does 62 elif attrs.get("type") in ["accession", "secondary"]: 63 self.name_text = text
64
65 - def add_dbxref_dbids(self, dbname_style, dbname, idtype, dbid, negate):
66 """Handle setting name and id attributes from the dbxref ids. 67 68 Likely we'll either have a dbid or dbxref dbids to use. We default 69 to using the dbid if it exists. 70 """ 71 # first deal with the primary id: SeqFeature.id 72 # set the id if we haven't yet set an id (take the first id we get) 73 # and if we have a primary id 74 if (self.id_text is None and idtype == "primary"): 75 self.id_text = dbid 76 77 # now deal with secondary ids: SeqFeature.name 78 if idtype == "secondary": 79 self.name_text = dbid
80 81
82 - def add_description(self, text):
83 self.description = text
84
85 - def add_sequence(self, (alphabet, seq, gapchar, stopchar)):
89
90 - def add_dbxref(self, dbname_style, dbname, idtype, dbid, negate):
91 """Store all id cross references. 92 """ 93 self.dbxrefs.append(DBXRef.from_parser(dbname_style, dbname, idtype, 94 dbid, negate))
95
96 - def add_features(self, features):
97 # Brad -- I can't understand this assertion -- there is no 98 # self.features on the first call to add features and then you'll 99 # expect to have some on future calls 100 # assert self.features is None 101 #print [feature.location for feature in features] 102 self.features = map(convert_std_feature, features)
103
104 - def end_record(self, tag):
105 self.document = SeqRecord.SeqRecord( 106 seq = self.seq, 107 id = self.id_text, 108 name = self.name_text, 109 description = self.description, 110 dbxrefs = self.dbxrefs, 111 features = self.features, 112 )
113 114 make_builder = BuildSeqRecord 115