/usr/share/pyshared/cogent/app/dynalign.py is in python-cogent 1.5.3-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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | #!/usr/bin/env python
from cogent.app.util import CommandLineApplication,\
CommandLineAppResult, ResultPath, ApplicationError
from cogent.app.parameters import Parameter, FlagParameter, ValuedParameter,\
MixedParameter,Parameters
from sys import platform
from os import remove,system,mkdir,getcwd,close
__author__ = "Shandy Wikman"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__contributors__ = ["Shandy Wikman", "Daniel McDonald"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Shandy Wikman"
__email__ = "ens01svn@cs.umu.se"
__status__ = "Development"
class Dynalign(CommandLineApplication):
"""Application controller for Dynalign
Input: Sequences for input in Dynalign are assumed to be in the
following format: ;(first line of file) Comments must start
with a ;semicolon ;There can be any number of comments A
single line title must immediately follow:
AAA GCGG UUTGTT UTCUTaaTCTXXXXUCAGG1 where the terminal 1
is required at the end.
pknotsRG is a tool for thermodynamic folding of RNA secondary
structures, including the class of canonical simple recursive
pseudoknots.
-alignment The alignment file that will be created
-M Maximum seperation parameter (larger then diff in length
of seq)
-gap_cost 0.4 good value
-max_precent_diff maximum % diff in free energy in suboptimal struct.
20 good starting point
-bp_window specifies how different the suboptimal structures must
be from each other. 2 good starting point
-align_window specifies how different alignments must be, 1 good starting
point.
-single_bp_inserts specifies whether single base pair inserts are allowed;
0 = no; 1 = yes.
-[savefile] optional
"""
_parameters = {
'-alignment':ValuedParameter(Prefix='',Name='',Value='align',Delimiter=' '),
'-M':ValuedParameter(Prefix='',Name='',Value=10,Delimiter=' '),
'-gap_cost':ValuedParameter(Prefix='',Name='',Value=0.4,Delimiter=' '),
'-max_structures':ValuedParameter(Prefix='',Name='',Value=8,Delimiter=' '),
'-max_percent_diff':ValuedParameter(Prefix='',Name='',Value=20,\
Delimiter=' '),
'-bp_window':ValuedParameter(Prefix='',Name='',Value=2,Delimiter=' '),
'-align_window':ValuedParameter(Prefix='',Name='',Value=1,Delimiter=' '),
'-single_bp_inserts':ValuedParameter(Prefix='',Name='',Value=1,\
Delimiter=' '),}
_command = 'dynalign'
_input_handler = '_input_as_string'
def _input_as_string(self,data):
"""Return data as a string
Data = list with two file paths
ex: data = ['path1,'path2'']"""
inputFiles = ''
self._input_filename = []
for i in data:
self._input_filename.append(i)
inputFiles = ' '.join([inputFiles,i])
outputFile = ' '.join(['ct1', 'ct2'])
inputFiles = ' '.join([inputFiles,outputFile])
return inputFiles
def _input_as_lines(self,data):
""" Write a seq of lines to a temp file and return the filename string
data: a sequence to be written to a file, each element of the
sequence will compose a line in the file.
ex. data = [file1,file2], file1 and 2 is lists of lines ->
[[List],[List]]
Note: '\n' will be stripped off the end of each sequence element
before writing to a file in order to avoid multiple new lines
accidentally be written to a file
"""
inputFiles = ''
self._input_filename = []
for el in data:
filename = self.getTmpFilename(self.WorkingDir)
self._input_filename.append(filename)
data_file = open(filename,'w')
data_to_file = '\n'.join([str(d).strip('\n') for d in el])
data_file.write(data_to_file)
data_file.close()
inputFiles = ' '.join([inputFiles,filename])
outputFiles = ' '.join(['ct1', 'ct2'])
inputFiles = ' '.join([inputFiles,outputFiles])
return inputFiles
def _get_result_paths(self,data):
"""
data: the data the instance of the application is called on
"""
result = {}
result['seq_1_ct'] =\
ResultPath(Path=(self.WorkingDir+'ct1'))
result['seq_2_ct'] =\
ResultPath(Path=(self.WorkingDir+'ct2'))
result['alignment'] =\
ResultPath(Path=(self.WorkingDir+'align'))
return result
#Below from Cogent/app/util.py modified to accommodate dynalign
def __call__(self,data=None):
"""Run the application with the specified kwargs on data
Overides the __call__ function in util.py becasue of the special
circumstance surrounding the command line input.
data: anything that can be cast into a string or written out to
a file. Usually either a list of things or a single string or
number. input_handler will be called on this data before it
is passed as part of the command-line argument, so by creating
your own input handlers you can customize what kind of data
you want you application to accept
"""
input_handler = self.InputHandler
suppress_stdout = self.SuppressStdout
suppress_stderr = self.SuppressStderr
if suppress_stdout:
outfile = '/dev/null'
else:
outfile = self.getTmpFilename(self.WorkingDir)
if suppress_stderr:
errfile = '/dev/null'
else:
errfile = self.getTmpFilename(self.WorkingDir)
if data is None:
input_arg = ''
else:
input_arg = getattr(self,input_handler)(data)
# Build up the command, consisting of a BaseCommand followed by
# input and output (file) specifications
first,second=self.BaseCommand
command = self._command_delimiter.join(filter(None,\
[first,input_arg,second,'>',outfile,'2>',errfile]))
if self.HaltExec:
raise AssertionError, "Halted exec with command:\n" + command
# The return value of system is a 16-bit number containing the signal
# number that killed the process, and then the exit status.
# We only want to keep the exit status so do a right bitwise shift to
# get rid of the signal number byte
exit_status = system(command) >> 8
# Determine if error should be raised due to exit status of
# appliciation
if not self._accept_exit_status(exit_status):
raise ApplicationError, \
'Unacceptable application exit status: %s, command: %s'\
% (str(exit_status),command)
# open the stdout and stderr if not being suppressed
out = None
if not suppress_stdout:
out = open(outfile,"r")
err = None
if not suppress_stderr:
err = open(errfile,"r")
result = CommandLineAppResult(out,err,exit_status,\
result_paths=self._get_result_paths(data))
# Clean up the input file if one was created
if self._input_filename:
for f in self._input_filename:
remove(f)
self._input_filename = None
return result
def _get_base_command(self):
""" Returns the full command string
Overides the __call__ function in util.py becasue of the special
circumstance surrounding the command line input.
input_arg: the argument to the command which represents the input
to the program, this will be a string, either
representing input or a filename to get input from
"""
command_part1 = []
command_part2 = []
# Append a change directory to the beginning of the command to change
# to self.WorkingDir before running the command
cd_command = ''.join(['cd ',self.WorkingDir,';'])
if self._command is None:
raise ApplicationError, '_command has not been set.'
command = self._command
command_part1.append(cd_command)
command_part1.append(command)
lista = [self.Parameters['-alignment'],\
self.Parameters['-M'],\
self.Parameters['-gap_cost'],\
self.Parameters['-max_structures'],\
self.Parameters['-max_percent_diff'],\
self.Parameters['-bp_window'],\
self.Parameters['-align_window'],\
self.Parameters['-single_bp_inserts']]
command_part2.append(self._command_delimiter.join(filter(\
None,(map(str,lista)))))
return self._command_delimiter.join(command_part1).strip(),\
self._command_delimiter.join(command_part2).strip()
BaseCommand = property(_get_base_command)
|