Trees | Indices | Help |
---|
|
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 29113 114 make_builder = BuildSeqRecord 11532 Dispatch.Dispatcher.__init__(self) 33 self.acquire(StdHandler.Handle_dbid(self.add_dbid), 34 prefix = Std.NS) 35 self.acquire(StdHandler.Handle_dbxref(self.add_dbxref_dbids), 36 prefix = Std.NS) 37 self.acquire(StdHandler.Handle_description(self.add_description), 38 prefix = Std.NS) 39 self.acquire(StdHandler.Handle_sequence(self.add_sequence), 40 prefix = Std.NS) 41 self.acquire(StdHandler.Handle_features(self.add_features), 42 prefix = Std.NS) 43 self.acquire(StdHandler.Handle_dbxref(self.add_dbxref), 44 prefix = Std.NS)4547 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 = []5557 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 = text6466 """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 = dbid80 81 8486 alphabet = alphabet_table.get(alphabet, 87 Alphabet.single_letter_alphabet) 88 self.seq = Seq.Seq(seq, alphabet)8991 """Store all id cross references. 92 """ 93 self.dbxrefs.append(DBXRef.from_parser(dbname_style, dbname, idtype, 94 dbid, negate))9597 # 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
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Sep 15 09:23:01 2008 | http://epydoc.sourceforge.net |