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