1
2
3
4
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
16 self.parameters = None
17
18
20 """read(handle)"""
21 record = Record()
22 line = handle.next()
23 record.version = line.strip()
24 line = handle.next()
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