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

Source Code for Module Bio.SeqRecord

 1  # Stores data about the sequence 
 2   
 3  # NEEDS TO BE SYNCH WITH THE REST OF BIOPYTHON AND BIOPERL 
 4   
5 -class SeqRecord:
6 """A SeqRecord object holds a sequence and information about it. 7 8 Main attributes: 9 id - Identifier such as a locus tag (string) 10 seq - The sequence itself (Seq object) 11 12 Additional attributes: 13 name - Sequence name, e.g. gene name (string) 14 description - Additional text (string) 15 dbxrefs - List of database cross references (list of strings) 16 features - Any (sub)features defined (list of SeqFeature objects) 17 annotations - Further information about the whole sequence (dictionary) 18 """
19 - def __init__(self, seq, id = "<unknown id>", name = "<unknown name>", 20 description = "<unknown description>", dbxrefs = None, 21 features = None):
22 """Create a SeqRecord 23 24 Arguments: 25 seq - Sequence, required (Seq object) 26 id - Sequence identifier, recommended (string) 27 name - Seqeuence name, optional (string) 28 description - Seqeuence description, optional (string) 29 dbxrefs - Database cross references, optional (list of strings) 30 features - Any (sub)features, optional (list of SeqFeature objects) 31 32 Note that while an id is optional, we strongly recommend you supply a 33 unique id string for each record. This is especially important 34 if you wish to write your sequences to a file. 35 36 You can create a 'blank' SeqRecord object can then populated the 37 attributes later. Note that currently the annotations dictionary 38 cannot be specified when creating the SeqRecord.""" 39 self.seq = seq 40 self.id = id 41 self.name = name 42 self.description = description 43 if dbxrefs is None: 44 dbxrefs = [] 45 self.dbxrefs = dbxrefs 46 # annotations about the whole sequence 47 self.annotations = {} 48 49 # annotations about parts of the sequence 50 if features is None: 51 features = [] 52 self.features = features
53
54 - def __str__(self) :
55 lines = [] 56 if self.id : lines.append("ID: %s" % self.id) 57 if self.name : lines.append("Name: %s" % self.name) 58 if self.description : lines.append("Desription: %s" % self.description) 59 if self.dbxrefs : lines.append("Database cross-references: " \ 60 + ", ".join(self.dbxrefs)) 61 for a in self.annotations: 62 lines.append("/%s=%s" % (a, str(self.annotations[a]))) 63 lines.append(str(self.seq)) 64 return "\n".join(lines)
65
66 - def __repr__(self) :
67 return "SeqRecord(seq=%s, id=%s, name=%s, description=%s, dbxrefs=%s)" \ 68 % tuple(map(repr, (self.seq, self.id, self.name, 69 self.description, self.dbxrefs)))
70 71 if __name__ == "__main__" : 72 #The following is a very quick example of how to create a SeqRecord object 73 from Bio.Seq import Seq 74 from Bio.Alphabet import generic_protein 75 record = SeqRecord(Seq("MASRGVNKVILVGNLGQDPEVRYMPNGGAVANITLATSESWRDKAT" \ 76 +"GEMKEQTEWHRVVLFGKLAEVASEYLRKGSQVYIEGQLRTRKWTDQ" \ 77 +"SGQDRYTTEVVVNVGGTMQMLGGRQGGGAPAGGNIGGGQPQGGWGQ" \ 78 +"PQQPQGGNQFSGGAQSRPQQSAPAAPSNEPPMDFDDDIPF", 79 generic_protein), 80 id="NP_418483.1", name="b4059", 81 description="ssDNA-binding protein", 82 dbxrefs=["ASAP:13298", "GI:16131885", "GeneID:948570"]) 83 84 #Note that annotations must be added AFTER creating the record 85 record.annotations["note"] = "This annotation was added later" 86 87 print record 88 89 #One way to create a minimal record. 90 record2 = SeqRecord(Seq("")) 91