Trees | Indices | Help |
---|
|
1 # Copyright 2007 by Michiel de Hoon. All rights reserved. 2 # This code is part of the Biopython distribution and governed by its 3 # license. Please see the LICENSE file that should have been included 4 # as part of this package. 5 """Parsers for file formats from the SwissProt database. 6 """ 7 8 # The parse(), read() functions can probably be simplified if we don't 9 # use the "parser = RecordParser(); parser.parse(handle)" approach.11 from SProt import RecordParser 12 import cStringIO 13 parser = RecordParser() 14 text = "" 15 for line in handle: 16 text += line 17 if line[:2]=='//': 18 handle = cStringIO.StringIO(text) 19 record = parser.parse(handle) 20 text = "" 21 yield record2224 from SProt import RecordParser 25 parser = RecordParser() 26 try: 27 record = parser.parse(handle) 28 except ValueError, error: 29 if error.message.startswith("Line does not start with 'ID':"): 30 raise ValueError, "No SwissProt record found" 31 else: 32 raise error 33 # We should have reached the end of the record by now 34 remainder = handle.read() 35 if remainder: 36 raise ValueError, "More than one SwissProt record found" 37 return record38 39 40 if __name__ == "__main__" : 41 print "Quick self test..." 42 43 example_filename = "../../Tests/SwissProt/sp008" 44 45 import os 46 if not os.path.isfile(example_filename): 47 print "Missing test file %s" % example_filename 48 else : 49 #Try parsing it! 50 51 handle = open(example_filename) 52 records = parse(handle) 53 for record in records: 54 print record.entry_name 55 print ",".join(record.accessions) 56 print record.keywords 57 print repr(record.organism) 58 print record.sequence[:20] + "..." 59 handle.close() 60
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Sep 15 09:28:13 2008 | http://epydoc.sourceforge.net |