Package Bio :: Package motifs :: Module alignace
[hide private]
[frames] | no frames]

Source Code for Module Bio.motifs.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 output files 
 7  """ 
 8   
 9  from Bio.motifs import Motif, Instances 
10  from Bio.Alphabet import IUPAC 
11  from Bio.Seq import Seq 
12   
13   
14 -class Record(list):
15 - def __init__(self):
16 self.parameters = None
17 18
19 -def read(handle):
20 """read(handle)""" 21 record = Record() 22 line = next(handle) 23 record.version = line.strip() 24 line = next(handle) 25 record.command = line.strip() 26 for line in handle: 27 line = line.strip() 28 if line=="": 29 pass 30 elif line[:4]=="Para": 31 record.parameters={} 32 elif line[0]=="#": 33 seq_name = line.split("\t")[1] 34 record.sequences.append(seq_name) 35 elif "=" in line: 36 par_name, par_value = line.split("=") 37 par_name = par_name.strip() 38 par_value = par_value.strip() 39 record.parameters[par_name]=par_value 40 elif line[:5]=="Input": 41 record.sequences=[] 42 elif line[:5]=="Motif": 43 words = line.split() 44 assert words[0]=="Motif" 45 number = int(words[1]) 46 instances = [] 47 elif line[:3]=="MAP": 48 alphabet = IUPAC.unambiguous_dna 49 instances = Instances(instances, alphabet) 50 motif = Motif(alphabet, instances) 51 motif.score = float(line.split()[-1]) 52 motif.number = number 53 motif.mask = mask 54 record.append(motif) 55 elif len(line.split("\t"))==4: 56 seq = Seq(line.split("\t")[0], IUPAC.unambiguous_dna) 57 instances.append(seq) 58 elif "*" in line: 59 mask = line.strip("\r\n") 60 else: 61 raise ValueError(line) 62 return record
63