/usr/share/pyshared/cogent/parse/rnaalifold.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 | #!/usr/bin/env python
from string import strip,split,atof
from cogent.struct.rna2d import ViennaStructure,Pairs
__author__ = "Shandy Wikman"
__copyright__ = "Copyright 2007-2011, The Cogent Project"
__contributors__ = ["Shandy Wikman","Jeremy Widmann"]
__license__ = "GPL"
__version__ = "1.5.1"
__maintainer__ = "Shandy Wikman"
__email__ = "ens01svn@cs.umu.se"
__status__ = "Development"
def MinimalRnaalifoldParser(lines):
"""MinimalRnaalifoldParser.
returns lists of sequence, structure_string, energy
"""
res = []
if lines:
for i in range(0,len(lines),2):
seq = lines[i].strip()
struct,energy = lines[i+1].split(" (")
energy = float(energy.split('=')[0].strip(' \n)'))
res.append([seq,struct,energy])
return res
def rnaalifold_parser(lines=None):
"""Parser for rnaalifold stdout output
Returns a list containing: sequence,structure(pairs object) and energy
Ex: [seq,[struct],energy]
"""
result = line_parser(lines)
return result
def line_parser(lines=None):
"""Parses RNAalifold output line for line """
s = False
seq = ''
energy = ''
pairs = ''
result = []
for line in lines:
if len(line)>1 and s==False:
seq = line.strip()
s = True
elif s == True:
s=False
struct = line.split(None,2)[0].strip('\n')
energy = atof(line.split(' (',1)[1].split(None,1)[0].strip())
pairs = to_pairs(struct)
pairs.sort()
result.append([seq,pairs,energy])
return result
def to_pairs(struct=None):
"""
Converts a vienna structure into a pairs object
Returns pairs object
pairs functions tested in test for rna2d.py
"""
struct = ViennaStructure(struct)
pairs = struct.toPairs()
return pairs
|