1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/usr/bin/env python
from string import split
from cogent.struct.rna2d import Pairs,ViennaStructure
from cogent.struct.pairs_util import adjust_base
from cogent.parse.column import column_parser
__author__ = "Shandy Wikman"
__copyright__ = "Copyright 2007-2009, The Cogent Project"
__contributors__ = ["Shandy Wikman"]
__license__ = "GPL"
__version__ = "1.5.0"
__maintainer__ = "Shandy Wikman"
__email__ = "ens01svn@cs.umu.se"
__status__ = "Development"
def foldalign_parser(lines,col=True):
"""Parser foldalign output"""
data = lines
if col:
return column_parser(data)
else:
return find_struct(data)
def find_struct(lines):
"""Finds structures in output data"""
struct = ''
name1 = ''
name2 = ''
seq1 = ''
seq2 = ''
result = []
for line in lines:
if line.startswith('; ========'):
break
if line.startswith('; ALIGNING'):
line = line.split()
name1 = line[2]
name2 = line[4]
continue
if line.startswith('; ALIGN %s' % name1):
line = line.split()[3:]
line = ''.join(line)
seq1 = ''.join([seq1,line])
continue
if line.startswith('; ALIGN %s' % name2):
line = line.split()[3:]
line = ''.join(line)
seq2 = ''.join([seq2,line])
continue
if line.startswith('; ALIGN Structure'):
line = line.split()[3:]
line = ''.join(line)
struct = ''.join([struct,line])
continue
struct = ViennaStructure(struct).toPairs()
struct.sort()
result.append([struct,seq1,seq2])
return result
|