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 (OBSOLETE).
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
67 This class is OBSOLETE; please use the read() function in this module
68 instead.
69 """
71 self.motifs=[]
72 self.current_motif=None
73 self.param_dict = None
74
77
79 par_name = line.split("=")[0].strip()
80 par_value = line.split("=")[1].strip()
81 self.param_dict[par_name]=par_value
82
85
87 seq_name = line.split("\t")[1]
88 self.seq_dict.append(seq_name)
89
94
98
100 self.current_motif.score = float(line.split()[-1])
101
104
107
110
113
115 """Parses AlignAce data into a sequence of Motifs (OBSOLETE)
116
117 This class is OBSOLETE; please use the read() function in this module
118 instead.
119 """
124
125 - def parse(self, handle):
126 """parse(self, handle)"""
127 self._scanner.feed(handle, self._consumer)
128 return self._consumer
129
131 """Scannner for AlignACE output (OBSOLETE).
132
133 Methods:
134 feed Feed data into the scanner.
135
136 The scanner generates (and calls the consumer) the following types of events:
137
138 noevent - blank line
139
140 version - AlignACE version number
141 command_line - AlignACE command line string
142 parameters - the begining of the parameters
143 parameter - the line containing a parameter
144 sequences - the begining of the sequences list
145 sequence - line containing the name of the input sequence (and a respective number)
146 motif - the begining of the motif (contains the number)
147 motif_hit - one hit for a motif
148 motif_mask - mask of the motif (space - gap, asterisk - significant position)
149 motif_score - MAP score of the motif - approx. N * log R, where R == (num. of actual occur.) / (num. of occur. expected by random.)
150
151 This class is OBSOLETE; please use the read() function in this module
152 instead.
153 """
154 - def feed(self, handle, consumer):
155 """S.feed(handle, consumer)
156
157 Feed in a AlignACE report for scanning. handle is a file-like
158 object that contains the AlignACE report. consumer is a Consumer
159 object that will receive events as the report is scanned.
160 """
161 consumer.version(handle.readline())
162 consumer.command_line(handle.readline())
163 for line in handle:
164 if line.strip() == "":
165 consumer.noevent(line)
166 elif line[:4]=="Para":
167 consumer.parameters(line)
168 elif line[0]=="#":
169 consumer.sequence(line)
170 elif "=" in line:
171 consumer.parameter(line)
172 elif line[:5]=="Input":
173 consumer.sequences(line)
174 elif line[:5]=="Motif":
175 consumer.motif(line)
176 elif line[:3]=="MAP":
177 consumer.motif_score(line)
178 elif len(line.split("\t"))==4:
179 consumer.motif_hit(line)
180 elif "*" in line:
181 consumer.motif_mask(line)
182 else:
183 raise ValueError(line)
184
186 """Scannner for CompareACE output (OBSOLETE).
187
188 Methods:
189 feed Feed data into the scanner.
190
191 The scanner generates (and calls the consumer) the following types of events:
192
193 motif_score - CompareACE score of motifs
194
195 ###### TO DO #############3
196 extend the scanner to include other, more complex outputs.
197 """
198 - def feed(self, handle, consumer):
199 """S.feed(handle, consumer)
200
201 Feed in a CompareACE report for scanning. handle is a file-like
202 object that contains the CompareACE report. consumer is a Consumer
203 object that will receive events as the report is scanned.
204 """
205 consumer.motif_score(handle.readline())
206
207
209 """
210 The general purpose consumer for the CompareAceScanner (OBSOLETE).
211
212 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.
213 """
218
220 """Parses CompareAce output to usable form
221
222 ### so far only in a very limited way
223 """
225 """__init__(self)"""
226 import warnings
227 warnings.warn("CompareAceParser and ComparAceConsumer are" \
228 +" deprecated, and will be removed in a future release of"\
229 +" Biopython. If you want to continue to use this code,"\
230 +" please get in contact with the Biopython developers via"\
231 +" the mailing lists to avoid its permanent removal from"\
232 +" Biopython. See also the Python built in set datatype.", \
233 DeprecationWarning)
234 self._scanner = CompareAceScanner()
235 self._consumer = CompareAceConsumer()
236
237 - def parse(self, handle):
238 """parse(self, handle)"""
239 self._scanner.feed(handle, self._consumer)
240 return self._consumer.data
241