# HG changeset patch
# User tyty
# Date 1429035447 14400
# Node ID 75e3711e23c481584f081ee109c239ad106f1b44
# Parent 62e8f7adf1ab2b07a1ff43e1b0c996a50d48de37
Uploaded
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._.DS_Store
Binary file predict/._.DS_Store has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._ct_to_dot.py
Binary file predict/._ct_to_dot.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._dot_convert.py
Binary file predict/._dot_convert.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._parse_dis_pac.py
Binary file predict/._parse_dis_pac.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._predict_RNAs.py
Binary file predict/._predict_RNAs.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._read_file.py
Binary file predict/._read_file.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/._rtts_plot.py
Binary file predict/._rtts_plot.py has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/ct_to_dot.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/predict/ct_to_dot.py Tue Apr 14 14:17:27 2015 -0400
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import shlex
+import os
+import subprocess
+from read_file import *
+
+ct_file = sys.argv[1]
+path = sys.argv[2]
+id_s = sys.argv[3]
+result_file = sys.argv[4]
+
+h = file(result_file, 'w')
+os.system('grep "'+id_s+'" '+ct_file+' |wc -l > '+path+'/count.txt')
+count = read_t_file(path+'/count.txt')
+comm = ''
+for i in range(int(count[0][0])):
+ command = shlex.split('ct2dot %s %s %s' % (ct_file, str(i+1), os.path.join(path, 'db_file_%s.dbnn' % str(i+1))))
+ subprocess.call(command)
+ comm = comm +' '+path+'/db_file_'+str(i+1)+'.dbnn'
+
+
+
+os.system('cat'+comm+' > '+result_file)
+for i in range(int(count[0][0])):
+ command = shlex.split('rm %s' % (os.path.join(path, 'db_file_%s.dbnn' % str(i+1))))
+ subprocess.call(command)
+command = shlex.split('rm %s' % (os.path.join(path, 'count.txt')))
+subprocess.call(command)
+
+
+
+h.close()
+
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/dot_convert.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/predict/dot_convert.py Tue Apr 14 14:17:27 2015 -0400
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+
+dot_file = sys.argv[1]
+result_file = sys.argv[2]
+
+h = file(result_file, 'w')
+f = open(dot_file)
+
+
+
+for aline in f.readlines():
+ line = aline.strip()
+ if line.find('>')!=-1:
+ id_line = line
+ idt = id_line.split('>')
+ ids = idt[1].strip()
+ else:
+ if line.find('(')!=-1:
+ structure_line = line
+ st = structure_line.split(' ')
+ structure = st[0].strip()
+ enert = st[1].strip()
+ if len(enert)>1:
+ enertt = enert.split('(')
+ enertt = enertt[1].strip()
+ else:
+ enertt = st[2].strip()
+ enerttt = enertt.split(')')
+ ener = enerttt[0].strip()
+ h.write('>ENERGY = '+ener+' '+ids+'\n')
+ h.write(seq+'\n')
+ h.write(structure+'\n')
+ else:
+ seq = line
+
+
+
+
+
+f.close()
+h.close()
+
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/parse_dis_pac.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/predict/parse_dis_pac.py Tue Apr 14 14:17:27 2015 -0400
@@ -0,0 +1,43 @@
+#parse reactivity file into a dictionary
+
+import sys
+
+def parse_dist(in_file):
+ result = []
+ distribution = {}
+ name = []
+ f = open(in_file)
+ for aline in f.readlines():
+ line = aline.strip()
+ dis = line.strip()
+ dist = dis.split('\t') #split the line and the reactivites or reads are in a list
+ if len(dist) > 0:
+ if len(dist) == 1:
+ if dist[0].strip().find('coverage')==-1:
+ name.append(line) #add the name in the name list
+ flag = 1
+ t_name = line
+ else:
+ distri = []
+ for i in range(0, len(dist)):
+ distri.append(dist[i].strip())
+ distribution[t_name] = distri #add the list of reactivities into a dictionary
+ result.append(name)
+ result.append(distribution) #Output the dictionary
+ f.close()
+ return result
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/parse_dis_pac.pyc
Binary file predict/parse_dis_pac.pyc has changed
diff -r 62e8f7adf1ab -r 75e3711e23c4 predict/predict_RNAs.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/predict/predict_RNAs.py Tue Apr 14 14:17:27 2015 -0400
@@ -0,0 +1,219 @@
+#RNA structure prediction & Output and illustrate reactivities
+
+import sys
+import shlex
+import subprocess
+import tarfile
+from parse_dis_pac import *
+from read_file import *
+from Bio import SeqIO
+import os
+from rtts_plot import *
+import random
+import string
+
+
+id_file = sys.argv[1]
+seq_file = sys.argv[2]
+predict_type = sys.argv[3]
+temperature = sys.argv[4]
+predict_program = sys.argv[5]
+output_html = sys.argv[6]
+output_directory = sys.argv[7]
+
+
+
+flag = False
+if predict_type!='silico': #input reactivity file if provided
+ if predict_program == 'rs':
+ react_file = sys.argv[8]
+ slope = sys.argv[9]
+ intercept = sys.argv[10]
+ else:
+ react_file = sys.argv[8]
+ thres_h = sys.argv[9]
+ thres_h = float(thres_h)
+ thres_l = sys.argv[10]
+ thres_l = float(thres_l)
+ gqs = sys.argv[11]
+ gqs = int(gqs)
+
+ react = parse_dist(react_file)
+ react = react[1]
+ flag = True
+else:
+ if predict_program!='rs':
+ gqs = sys.argv[8]
+ gqs = int(gqs)
+
+
+ospath = os.path.realpath(sys.argv[0])
+ost = ospath.split('/')
+syspathpt = ""
+for i in range(len(ost)-1):
+ syspathpt = syspathpt+ost[i].strip()
+ syspathpt = syspathpt+'/'
+
+
+syspath = os.getcwd()
+
+ids = read_t_file(id_file)
+sequences = SeqIO.parse(seq_file, 'fasta')
+
+
+seqs = {}
+for seq in sequences:
+ seqs[seq.id] = seq.seq.tostring()
+
+if len(ids)>100: #setup a limit of the number of sequence to be predicted
+ print("Number of sequences exceeds limitation!")
+ sys.exit(0)
+
+
+#predict RNA structures
+
+os.mkdir(output_directory)
+flag3 = 0
+
+id_predicted = set()
+for i in range(len(ids)):
+ flag2 = 0
+ id_s = ids[i][0]
+ #print(id_s)
+ #Put RNA sequence and reactivities into files
+ if id_s in seqs:
+ fh = file(os.path.join(syspath,"temp.txt"), 'w')
+ fh.write('>'+id_s)
+ fh.write('\n')
+ fh.write(seqs[id_s])
+ fh.close()
+ if not flag:
+ if predict_program == 'rs':
+ command = shlex.split('Fold %s -T %s %s' % (os.path.join(syspath, 'temp.txt'), temperature, os.path.join(output_directory, '%s.ct' % id_s)))
+ subprocess.call(command)
+ command = shlex.split('python %s %s %s %s %s' % (os.path.join(syspathpt, 'ct_to_dot.py'), os.path.join(output_directory, '%s.ct' % id_s), output_directory, id_s, os.path.join(output_directory, '%s.dbn' % id_s)))
+ subprocess.call(command)
+ else:
+ if gqs:
+ os.system('RNAfold < '+syspath+'/temp.txt -T '+str(float(temperature)-273.15)+' --noconv -g > '+output_directory+'/'+id_s+'.dbnb')
+
+ else:
+ os.system('RNAfold < '+syspath+'/temp.txt -T '+str(float(temperature)-273.15)+' --noconv --noPS > '+output_directory+'/'+id_s+'.dbnb')
+ command = shlex.split('python %s %s %s' % (os.path.join(syspathpt, 'dot_convert.py'), os.path.join(output_directory, '%s.dbnb' % id_s), os.path.join(output_directory, '%s.dbn' % id_s)))
+ subprocess.call(command)
+ if not gqs:
+ command = shlex.split('dot2ct %s %s' % (os.path.join(output_directory, '%s.dbn' % id_s), os.path.join(output_directory, '%s.ct' % id_s)))
+ else:
+ command = shlex.split('mv -f %s %s' % (os.path.join(syspath, '%s_ss.ps' % id_s), os.path.join(output_directory, '%s.ps' % id_s)))
+ subprocess.call(command)
+ command = shlex.split('rm %s' % (os.path.join(output_directory, '%s.dbnb' % id_s)))
+ subprocess.call(command)
+ else:
+ if id_s in react:
+ fh = file(os.path.join(syspath, "constraint.txt"), 'w')
+ make_plot(react[id_s], id_s, output_directory) #make a plot of the distribution of the reactivites of the input RNA
+ if predict_program == 'rs':
+ for j in range(0, (len(react[id_s]))):
+ if react[id_s][j]!='NA':
+ fh.write(str(j+1))
+ fh.write('\t')
+ fh.write(str(react[id_s][j]))
+ fh.write('\n')
+ fh.close()
+ command = shlex.split("Fold %s -sh %s -si %s -sm %s -T %s %s" % (os.path.join(syspath, "temp.txt"),
+ os.path.join(syspath, "constraint.txt"), intercept, slope, temperature,
+ os.path.join(output_directory, "%s.ct" % id_s)))
+ subprocess.call(command)
+ command = shlex.split('python %s %s %s %s %s' % (os.path.join(syspathpt, 'ct_to_dot.py'), os.path.join(output_directory, '%s.ct' % id_s), output_directory, id_s, os.path.join(output_directory, '%s.dbn' % id_s)))
+ subprocess.call(command)
+ else:
+ fh.write('>'+id_s)
+ fh.write('\n')
+ fh.write(seqs[id_s])
+ fh.write('\n')
+ for j in range(0, (len(react[id_s]))):
+ if react[id_s][j]!='NA':
+ re = float(react[id_s][j])
+ if re>thres_h:
+ fh.write('x')
+ else:
+ if re \n')
+ h.write('Click here to download the compressed file containing all prediction results.\n' % (('prediction_results.tar')))
+ #h.write('<\p>\n')
+ h.write('Results of RNA structure prediction
\n')
+
+
+ for id_p in id_predicted:
+ h.write(''+id_p+'