X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=binaries%2Fsrc%2Fglobplot%2Fbiopython-1.50%2FBio%2FSeqIO%2FSwissIO.py;fp=binaries%2Fsrc%2Fglobplot%2Fbiopython-1.50%2FBio%2FSeqIO%2FSwissIO.py;h=a55c0fe9ad54ce26d741d2772610281f071f6c23;hb=119df1cedad3d4760e6fd458713da2488eff79cc;hp=0000000000000000000000000000000000000000;hpb=d3806a66f002b93f6dc03447b6628f943a3ba90c;p=jabaws.git diff --git a/binaries/src/globplot/biopython-1.50/Bio/SeqIO/SwissIO.py b/binaries/src/globplot/biopython-1.50/Bio/SeqIO/SwissIO.py new file mode 100644 index 0000000..a55c0fe --- /dev/null +++ b/binaries/src/globplot/biopython-1.50/Bio/SeqIO/SwissIO.py @@ -0,0 +1,65 @@ +# Copyright 2006 by Peter Cock. All rights reserved. +# +# This code is part of the Biopython distribution and governed by its +# license. Please see the LICENSE file that should have been included +# as part of this package. + +"""Bio.SeqIO support for the "swiss" (aka SwissProt/UniProt) file format. + +You are expected to use this module via the Bio.SeqIO functions. +See also the Bio.SwissProt module which offers more than just accessing +the sequences as SeqRecord objects.""" + +from Bio.SwissProt import SProt +import cStringIO + +#This is a generator function! +def SwissIterator(handle) : + """Breaks up a Swiss-Prot/UniProt file into SeqRecord objects. + + Every section from the ID line to the terminating // becomes + a single SeqRecord with associated annotation and features. + + This parser is for the flat file "swiss" format as used by: + * Swiss-Prot aka SwissProt + * TrEMBL + * UniProtKB aka UniProt Knowledgebase + + It does NOT read their new XML file format. + http://www.expasy.org/sprot/ + + For consistency with BioPerl and EMBOSS we call this the "swiss" + format. + """ + parser = SProt.SequenceParser() + lines = [] + for line in handle: + lines.append(line) + if line[:2]=='//': + handle = cStringIO.StringIO("".join(lines)) + record = parser.parse(handle) + lines = [] + yield record + #If there are more lines, it could only be a partial record. + #Should we try and parse them anyway? + + +if __name__ == "__main__" : + print "Quick self test..." + + example_filename = "../../Tests/SwissProt/sp008" + + import os + if not os.path.isfile(example_filename): + print "Missing test file %s" % example_filename + else : + #Try parsing it! + handle = open(example_filename) + records = SwissIterator(handle) + for record in records: + print record.name + print record.id + print record.annotations['keywords'] + print repr(record.annotations['organism']) + print record.seq.tostring()[:20] + "..." + handle.close()