1 # Copyright 2006 by Peter Cock. All rights reserved.
3 # This code is part of the Biopython distribution and governed by its
4 # license. Please see the LICENSE file that should have been included
5 # as part of this package.
7 """Bio.SeqIO support for the "swiss" (aka SwissProt/UniProt) file format.
9 You are expected to use this module via the Bio.SeqIO functions.
10 See also the Bio.SwissProt module which offers more than just accessing
11 the sequences as SeqRecord objects."""
13 from Bio.SwissProt import SProt
16 #This is a generator function!
17 def SwissIterator(handle) :
18 """Breaks up a Swiss-Prot/UniProt file into SeqRecord objects.
20 Every section from the ID line to the terminating // becomes
21 a single SeqRecord with associated annotation and features.
23 This parser is for the flat file "swiss" format as used by:
24 * Swiss-Prot aka SwissProt
26 * UniProtKB aka UniProt Knowledgebase
28 It does NOT read their new XML file format.
29 http://www.expasy.org/sprot/
31 For consistency with BioPerl and EMBOSS we call this the "swiss"
34 parser = SProt.SequenceParser()
39 handle = cStringIO.StringIO("".join(lines))
40 record = parser.parse(handle)
43 #If there are more lines, it could only be a partial record.
44 #Should we try and parse them anyway?
47 if __name__ == "__main__" :
48 print "Quick self test..."
50 example_filename = "../../Tests/SwissProt/sp008"
53 if not os.path.isfile(example_filename):
54 print "Missing test file %s" % example_filename
57 handle = open(example_filename)
58 records = SwissIterator(handle)
59 for record in records:
62 print record.annotations['keywords']
63 print repr(record.annotations['organism'])
64 print record.seq.tostring()[:20] + "..."