1 """Part of an old unused and undocumented sequence writing framework (DEPRECATED)."""
2 # Not clear on the distinction, if any, between 'embl' and 'embl/65'. This
3 # code might apply to either or both.
5 # See 'http://www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html' for a
6 # definition of this file format.
8 # This code only makes a best effort--the output may not be strictly valid.
9 # So, for example, the EMBL ID is supposed to be alphanumeric, starting with a
10 # letter, but we don't check for this, etc.
14 # ID AA03518 standard; DNA; FUN; 237 BP.
18 # DE Aspergillus awamori internal transcribed spacer 1 (ITS1) and 18S
19 # DE rRNA and 5.8S rRNA genes, partial sequence.
21 # SQ Sequence 237 BP; 41 A; 77 C; 67 G; 52 T; 0 other;
22 # aacctgcgga aggatcatta ccgagtgcgg gtcctttggg cccaacctcc catccgtgtc 60
23 # tattgtaccc tgttgcttcg gcgggcccgc cgcttgtcgg ccgccggggg ggcgcctctg 120
24 # ccccccgggc ccgtgcccgc cggagacccc aacacgaaca ctgtctgaaa gcgtgcagtc 180
25 # tgagttgatt gaatgcaatc agttaaaact ttcaacaatg gatctcttgg ttccggc 237
31 from Bio import Alphabet
32 from Bio import Writer
34 class WriteEmbl(Writer.Writer):
35 def __init__(self, outfile):
36 Writer.Writer.__init__(self, outfile)
38 def write(self, record):
40 assert seq.alphabet.size == 1, "cannot handle alphabet of size %d" % \
43 upperdata = data.upper()
45 # It'd be nice if the alphabet was usefully set, but for many interesting
46 # cases (e.g., reading from FASTA files), it's not.
48 if isinstance(seq.alphabet, Alphabet.RNAAlphabet):
50 letters = ['A', 'C', 'G', 'U']
53 letters = ['A', 'C', 'G', 'T']
55 division = 'UNC' # unknown
57 self.outfile.write("ID %s standard; %s; %s; %d BP.\n"
58 % (record.id, molecule, division, len(data)))
60 desclist = textwrap.wrap(record.description, 74)
62 self.outfile.write("DE %s\n" % l)
64 counts = [ upperdata.count(l) for l in letters ]
65 othercount = len(upperdata) - sum(counts)
67 countstring = ''.join([ " %d %s;" % p for p in zip(counts, letters) ])
69 self.outfile.write("SQ Sequence %s BP;%s %d other;\n"
70 % (len(data), countstring, othercount))
74 for i in xrange(0, len(data), rowlength):
75 self.outfile.write(" " * 5)
76 row = data[i:i+rowlength]
77 for b in xrange(0, rowlength, blocklength):
78 block = row[b:b+blocklength]
79 self.outfile.write("%-*s" % (blocklength+1, block))
80 self.outfile.write("%9d\n" % min(i+rowlength, len(data)))
82 self.outfile.write("//\n")
85 make_writer = WriteEmbl