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

Source Code for Module Bio.Motif.Parsers.AlignAce

 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  """Parsing AlignACE files: AlignAceParser 
 7  """ 
 8   
 9  from Bio.Motif import Motif 
10  from Bio.Alphabet import IUPAC 
11  from Bio.Seq import Seq 
12   
13   
14 -class Record(object):
15 - def __init__(self):
16 self.motifs=[] 17 self.current_motif=None 18 self.param_dict = None
19 20
21 -def read(handle):
22 """read(handle)""" 23 record = Record() 24 record.ver = next(handle) 25 record.cmd_line = next(handle) 26 for line in handle: 27 if line.strip() == "": 28 pass 29 elif line[:4]=="Para": 30 record.param_dict={} 31 elif line[0]=="#": 32 seq_name = line.split("\t")[1] 33 record.seq_dict.append(seq_name) 34 elif "=" in line: 35 par_name = line.split("=")[0].strip() 36 par_value = line.split("=")[1].strip() 37 record.param_dict[par_name]=par_value 38 elif line[:5]=="Input": 39 record.seq_dict=[] 40 elif line[:5]=="Motif": 41 record.current_motif = Motif() 42 record.motifs.append(record.current_motif) 43 record.current_motif.alphabet=IUPAC.unambiguous_dna 44 elif line[:3]=="MAP": 45 record.current_motif.score = float(line.split()[-1]) 46 elif len(line.split("\t"))==4: 47 seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna) 48 record.current_motif.add_instance(seq) 49 elif "*" in line: 50 record.current_motif.set_mask(line.strip("\n\c")) 51 else: 52 raise ValueError(line) 53 return record
54