1
2
3
4
5
6 """Parsing AlignACE and CompareACE files: AlignAceParser,CompareAceParser
7 """
8
9 from Bio.Motif import Motif
10 from Bio.Alphabet import IUPAC
11 from Bio.Seq import Seq
12
13
16 self.motifs=[]
17 self.current_motif=None
18 self.param_dict = None
19
20
54
55
56
57
58 from Bio.ParserSupport import *
59
60
62 """
63 The general purpose consumer for the AlignAceScanner.
64
65 Should be passed as the consumer to the feed method of the AlignAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.
66 """
68 self.motifs=[]
69 self.current_motif=None
70 self.param_dict = None
71
74
76 par_name = line.split("=")[0].strip()
77 par_value = line.split("=")[1].strip()
78 self.param_dict[par_name]=par_value
79
82
84 seq_name = line.split("\t")[1]
85 self.seq_dict.append(seq_name)
86
91
95
97 self.current_motif.score = float(line.split()[-1])
98
101
104
107
110
112 """Parses AlignAce data into a sequence of Motifs.
113 """
118
119 - def parse(self, handle):
120 """parse(self, handle)"""
121 self._scanner.feed(handle, self._consumer)
122 return self._consumer
123
125 """Scannner for AlignACE output
126
127 Methods:
128 feed Feed data into the scanner.
129
130 The scanner generates (and calls the consumer) the following types of events:
131
132 noevent - blank line
133
134 version - AlignACE version number
135 command_line - AlignACE command line string
136 parameters - the begining of the parameters
137 parameter - the line containing a parameter
138 sequences - the begining of the sequences list
139 sequence - line containing the name of the input sequence (and a respective number)
140 motif - the begining of the motif (contains the number)
141 motif_hit - one hit for a motif
142 motif_mask - mask of the motif (space - gap, asterisk - significant position)
143 motif_score - MAP score of the motif - approx. N * log R, where R == (num. of actual occur.) / (num. of occur. expected by random.)
144
145 """
146 - def feed(self, handle, consumer):
147 """S.feed(handle, consumer)
148
149 Feed in a AlignACE report for scanning. handle is a file-like
150 object that contains the AlignACE report. consumer is a Consumer
151 object that will receive events as the report is scanned.
152 """
153 consumer.version(handle.readline())
154 consumer.command_line(handle.readline())
155 for line in handle:
156 if line.strip() == "":
157 consumer.noevent(line)
158 elif line[:4]=="Para":
159 consumer.parameters(line)
160 elif line[0]=="#":
161 consumer.sequence(line)
162 elif "=" in line:
163 consumer.parameter(line)
164 elif line[:5]=="Input":
165 consumer.sequences(line)
166 elif line[:5]=="Motif":
167 consumer.motif(line)
168 elif line[:3]=="MAP":
169 consumer.motif_score(line)
170 elif len(line.split("\t"))==4:
171 consumer.motif_hit(line)
172 elif "*" in line:
173 consumer.motif_mask(line)
174 else:
175 raise ValueError(line)
176
178 """Scannner for CompareACE output
179
180 Methods:
181 feed Feed data into the scanner.
182
183 The scanner generates (and calls the consumer) the following types of events:
184
185 motif_score - CompareACE score of motifs
186
187 ###### TO DO #############3
188 extend the scanner to include other, more complex outputs.
189 """
190 - def feed(self, handle, consumer):
191 """S.feed(handle, consumer)
192
193 Feed in a CompareACE report for scanning. handle is a file-like
194 object that contains the CompareACE report. consumer is a Consumer
195 object that will receive events as the report is scanned.
196 """
197 consumer.motif_score(handle.readline())
198
199
201 """
202 The general purpose consumer for the CompareAceScanner.
203
204 Should be passed as the consumer to the feed method of the CompareAceScanner. After 'consuming' the file, it has the list of motifs in the motifs property.
205 """
210
212 """Parses CompareAce output to usable form
213
214 ### so far only in a very limited way
215 """
217 """__init__(self)"""
218 import warnings
219 warnings.warn("CompareAceParser and ComparAceConsumer are" \
220 +" deprecated, and will be removed in a future release of"\
221 +" Biopython. If you want to continue to use this code,"\
222 +" please get in contact with the Biopython developers via"\
223 +" the mailing lists to avoid its permanent removal from"\
224 +" Biopython. See also the Python built in set datatype.", \
225 DeprecationWarning)
226 self._scanner = CompareAceScanner()
227 self._consumer = CompareAceConsumer()
228
229 - def parse(self, handle):
230 """parse(self, handle)"""
231 self._scanner.feed(handle, self._consumer)
232 return self._consumer.data
233