Package Bio :: Package AlignAce :: Module Parser
[hide private]
[frames] | no frames]

Source Code for Module Bio.AlignAce.Parser

  1  # Copyright 2003 by Bartek Wilczynski.  All rights reserved. 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package. 
  5  """ 
  6  Classes for parsing AlignAce and CompareACE files. 
  7   
  8  This module is OBSOLETE; please use Bio.Motif.Parsers.AlignAce instead. 
  9  """ 
 10   
 11  from Bio.ParserSupport import * 
 12  from Scanner import AlignAceScanner,CompareAceScanner 
 13  from Motif import Motif 
 14  from Bio.Alphabet import IUPAC 
 15  from Bio.Seq import Seq 
 16   
 17   
18 -class AlignAceConsumer:
19 """ 20 The general purpose consumer for the AlignAceScanner. 21 22 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. 23 """
24 - def __init__(self):
25 self.motifs=[] 26 self.current_motif=None 27 self.param_dict = None
28
29 - def parameters(self,line):
30 self.param_dict={}
31
32 - def parameter(self,line):
33 par_name = line.split("=")[0].strip() 34 par_value = line.split("=")[1].strip() 35 self.param_dict[par_name]=par_value
36
37 - def sequences(self,line):
38 self.seq_dict=[]
39
40 - def sequence(self,line):
41 seq_name = line.split("\t")[1] 42 self.seq_dict.append(seq_name)
43
44 - def motif(self,line):
45 self.current_motif = Motif() 46 self.motifs.append(self.current_motif) 47 self.current_motif.alphabet=IUPAC.unambiguous_dna
48
49 - def motif_hit(self,line):
50 seq = Seq(line.split("\t")[0],IUPAC.unambiguous_dna) 51 self.current_motif.add_instance(seq)
52
53 - def motif_score(self,line):
54 self.current_motif.score = float(line.split()[-1])
55
56 - def motif_mask(self,line):
57 self.current_motif.set_mask(line.strip("\n\c"))
58
59 - def noevent(self,line):
60 pass
61
62 - def version(self,line):
63 self.ver = line
64
65 - def command_line(self,line):
66 self.cmd_line = line
67
68 -class AlignAceParser(AbstractParser):
69 """Parses AlignAce data into a sequence of Motifs. 70 """
71 - def __init__(self):
72 """__init__(self)""" 73 self._scanner = AlignAceScanner() 74 self._consumer = AlignAceConsumer()
75
76 - def parse(self, handle):
77 """parse(self, handle)""" 78 self._scanner.feed(handle, self._consumer) 79 return self._consumer.motifs
80 81
82 -class CompareAceConsumer:
83 """ 84 The general purpose consumer for the CompareAceScanner. 85 86 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. 87 """
88 - def __init__(self):
89 pass
90 - def motif_score(self,line):
91 self.data = float(line.split()[-1])
92
93 -class CompareAceParser(AbstractParser):
94 """Parses CompareAce output to usable form 95 96 ### so far only in a very limited way 97 """
98 - def __init__(self):
99 """__init__(self)""" 100 self._scanner = CompareAceScanner() 101 self._consumer = CompareAceConsumer()
102
103 - def parse(self, handle):
104 """parse(self, handle)""" 105 self._scanner.feed(handle, self._consumer) 106 return self._consumer.data
107