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