comparison cofold.py @ 0:65fff071414e draft

Uploaded
author rnateam
date Wed, 14 Jan 2015 08:56:58 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:65fff071414e
1 #!/usr/bin/env python
2
3 import sys, os
4 import argparse
5 import shlex
6 import subprocess
7
8 parser = argparse.ArgumentParser()
9 parser.add_argument('-i', '--input', help='Input file name')
10 parser.add_argument('-o1','--output1', help='tabular output file')
11 parser.add_argument('-s', '--parameters', help='arguments')
12 args=parser.parse_args()
13
14 myinput = open(args.input)
15
16 parameters = args.parameters
17
18 # we assume that the param files are located next to the python dir
19 script_dir = os.path.dirname(os.path.realpath(__file__))
20 parameters = args.parameters.replace('-P ', '-P %s/' % script_dir)
21 p = subprocess.check_output(shlex.split('CoFold '+ parameters), stdin=myinput)
22
23 lines=p.split('\n')
24 # FASTA header
25 o=lines[0].replace('\t',' ')
26
27 for x in range(1, len(lines)):
28 if x % 3 == 2:
29 [seq,st]=lines[x].split(' ',1)
30 st=st.strip().lstrip('(').rstrip(')')
31 o+='\t' + seq + '\t' + st
32 if x % 3 == 1:
33 o+='\t'+lines[x]
34 if x % 3 == 0:
35 o+='\n'+lines[x].replace('\t',' ')
36 out=open(args.output1,'w')
37 out.write(o)
38 out.close()
39
40
41
42
43