/usr/share/pyshared/cogent/parse/cove.py is in python-cogent 1.5.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #!/usr/bin/env python
from string import split,strip
from cogent.util.transform import make_trans
from cogent.struct.rna2d import ViennaStructure,wuss_to_vienna
__author__ = "Shandy Wikman"
__copyright__ = "Copyright 2007-2011, The Cogent Project"
__contributors__ = ["Shandy Wikman"]
__license__ = "GPL"
__version__ = "1.5.1"
__maintainer__ = "Shandy Wikman"
__email__ = "ens01svn@cs.umu.se"
__status__ = "Development"
def coves_parser(data=None):
""" Parser for coves output using option -m
Takes lines as input.
Returns a list of lists(containing structure and pairs data)
ex: [[seq1,pairs1],[seq2,pairs2],...]
"""
c = 1
count = 0
tmp_seq = ''
tmp_struct = ''
seq = ''
struct = ''
result = []
seqNames = NameList(data)
for name in seqNames: #parse each sequence in turn
name = '%s ' % (name) #add blank to differ ex seq1 from seq10
count+=1
if count != 1:
struct, seq = remove_gaps(struct,seq)
pairs = convert_to_vienna(struct)
result.append([seq,pairs])
seq = ''
struct = ''
for line in data:
line = str(line)
line = line.strip()
sline = line.split(None,1)
if c==1: #sequence line (every other line)
if line.startswith(name):
c=0
tmp_seq = sline[-1]
seq = ''.join([seq,tmp_seq])
elif c==0: #struct line (every other line)
if line.startswith(name):
c=1
tmp_struct = sline[-1]
struct = ''.join([struct,tmp_struct])
struct,seq = remove_gaps(struct,seq)
pairs = convert_to_vienna(struct)
result.append([seq,pairs])
return result
cove_to_vienna_table = make_trans('><','()')
def remove_gaps(struct,seq):
"""Remove gaps function
Some results comes with gaps that need to be removed
"""
seq = seq.replace('-','')
tmp_struct = struct.split() #removes gaps
tmp = ''
for i in range(len(tmp_struct)):
tmp = ''.join([tmp,tmp_struct[i]]) #put struct parts together
struct = tmp
if len(struct) != len(seq): #check so that struct and seq match in length
raise ValueError, 'Sequence length don\'t match structure length'
return struct,seq
def NameList(data=None):
"""
Takes coves results and retrieves the sequence names for further parsing
"""
nameList = []
if not isinstance(data,list):
data = open(data).readlines()
for line in data:
if line.__contains__('bits'): #every unique sequense begins with 'bits'
line = line.split()
nameList.append(line[-1])
return nameList
def convert_to_vienna(data):
"""
Converts into vienna dot bracket format, >< to ()
"""
try:
return toPairs(ViennaStructure(data.translate(cove_to_vienna_table)))
except IndexError:
return ''
def toPairs(vienna):
"""
Converts a vienna structure to a pairs obejct
"""
pairs = vienna.toPairs()
return pairs
|