1
2
3
4
5 import warnings
6 warnings.warn("Bio.SeqIO.FASTA is deprecated." \
7 + " We hope the new code in Bio.SeqIO will be suitable for" \
8 + " most users. Please get in touch on the mailing lists if" \
9 + " this (or its removal) causes any problems for you.",
10 DeprecationWarning)
11
12 import os, string
13 import Bio.Alphabet
14
15 from Bio.Seq import Seq
16 from Bio.SeqRecord import SeqRecord
17
18
19
20
23 self.infile = infile
24 self.alphabet = alphabet
25
26
27 line = infile.readline()
28 while line and line[0] != ">":
29 line = infile.readline()
30 self._lookahead = line
31
32 self._n = 0
33
35 self._n = self._n + 1
36
37 line = self._lookahead
38 if not line:
39 return None
40
41
42
43
44 x = string.split(line[1:].rstrip(), None, 1)
45 if len(x) == 1:
46 id = x[0]
47 desc = ""
48 else:
49 id, desc = x
50
51 lines = []
52 line = self.infile.readline()
53 while line:
54 if line[0] == ">":
55 break
56 lines.append(line.rstrip())
57 line = self.infile.readline()
58
59 self._lookahead = line
60
61
62 return SeqRecord(Seq(string.join(lines, ""), self.alphabet),
63 id = id, name = id, description = desc)
64
66
67 assert i == self._n
68 x = self.next()
69 if x is None:
70 raise IndexError, i
71 return x
72
75 self.outfile = outfile
76
89
90
95
97 return self.outfile.close()
98
100 return self.outfile.flush()
101