annotate upload/predict/predict_RNAs.py @ 34:d74ed492efdd draft

Uploaded
author tyty
date Mon, 20 Oct 2014 14:55:16 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
d74ed492efdd Uploaded
tyty
parents:
diff changeset
1 #RNA structure prediction & Output and illustrate reactivities
d74ed492efdd Uploaded
tyty
parents:
diff changeset
2
d74ed492efdd Uploaded
tyty
parents:
diff changeset
3 import sys
d74ed492efdd Uploaded
tyty
parents:
diff changeset
4 from parse_dis_pac import *
d74ed492efdd Uploaded
tyty
parents:
diff changeset
5 from read_file import *
d74ed492efdd Uploaded
tyty
parents:
diff changeset
6 from Bio import SeqIO
d74ed492efdd Uploaded
tyty
parents:
diff changeset
7 import os
d74ed492efdd Uploaded
tyty
parents:
diff changeset
8 from rtts_plot import *
d74ed492efdd Uploaded
tyty
parents:
diff changeset
9
d74ed492efdd Uploaded
tyty
parents:
diff changeset
10
d74ed492efdd Uploaded
tyty
parents:
diff changeset
11 id_file = sys.argv[1]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
12 seq_file = sys.argv[2]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
13 output_file = sys.argv[4]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
14
d74ed492efdd Uploaded
tyty
parents:
diff changeset
15
d74ed492efdd Uploaded
tyty
parents:
diff changeset
16 flag = 0
d74ed492efdd Uploaded
tyty
parents:
diff changeset
17 if sys.argv[3]!='None': #input reactivity file if provided
d74ed492efdd Uploaded
tyty
parents:
diff changeset
18 react_file = sys.argv[3]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
19 react = parse_dist(react_file)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
20 react = react[1]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
21 flag = 1
d74ed492efdd Uploaded
tyty
parents:
diff changeset
22
d74ed492efdd Uploaded
tyty
parents:
diff changeset
23 ospath = os.path.realpath(sys.argv[0])
d74ed492efdd Uploaded
tyty
parents:
diff changeset
24 ost = ospath.split('/')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
25 syspath = ""
d74ed492efdd Uploaded
tyty
parents:
diff changeset
26 for i in range(len(ost)-1):
d74ed492efdd Uploaded
tyty
parents:
diff changeset
27 syspath = syspath+ost[i].strip()
d74ed492efdd Uploaded
tyty
parents:
diff changeset
28 syspath = syspath+'/'
d74ed492efdd Uploaded
tyty
parents:
diff changeset
29
d74ed492efdd Uploaded
tyty
parents:
diff changeset
30 ids = read_t_file(id_file)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
31 sequences = SeqIO.parse(seq_file, 'fasta')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
32
d74ed492efdd Uploaded
tyty
parents:
diff changeset
33
d74ed492efdd Uploaded
tyty
parents:
diff changeset
34 seqs = {}
d74ed492efdd Uploaded
tyty
parents:
diff changeset
35 for seq in sequences:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
36 seqs[seq.id] = seq.seq.tostring()
d74ed492efdd Uploaded
tyty
parents:
diff changeset
37
d74ed492efdd Uploaded
tyty
parents:
diff changeset
38 if len(ids)>10: #setup a limit of the number of sequence to be predicted
d74ed492efdd Uploaded
tyty
parents:
diff changeset
39 print("Number of sequences exceeds limitation!")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
40 sys.exit(0)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
41
d74ed492efdd Uploaded
tyty
parents:
diff changeset
42
d74ed492efdd Uploaded
tyty
parents:
diff changeset
43 #predict RNA structures
d74ed492efdd Uploaded
tyty
parents:
diff changeset
44 os.system("mkdir "+syspath+"output_f")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
45 for i in range(len(ids)):
d74ed492efdd Uploaded
tyty
parents:
diff changeset
46 id_s = ids[i][0]
d74ed492efdd Uploaded
tyty
parents:
diff changeset
47 print(id_s)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
48 #Put RNA sequence and reactivities into files
d74ed492efdd Uploaded
tyty
parents:
diff changeset
49 if id_s in seqs:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
50 f = file(syspath+"temp.txt", 'w')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
51 f.write('>'+id_s)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
52 f.write('\n')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
53 f.write(seqs[id_s])
d74ed492efdd Uploaded
tyty
parents:
diff changeset
54 f.close()
d74ed492efdd Uploaded
tyty
parents:
diff changeset
55 if flag == 0:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
56 os.system("Fold "+syspath+"temp.txt"+" "+syspath+"output_f/"+id_s+".ct")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
57 if flag == 1:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
58 if id_s in react:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
59 f = file(syspath+"constraint.txt",'w')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
60 make_plot(react[id_s],id_s,(syspath+"output_f/")) #make a plot of the distribution of the reactivites of the input RNA
d74ed492efdd Uploaded
tyty
parents:
diff changeset
61 #h = file(syspath+"output_f/transcript_reactivities.txt", 'w')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
62 #h.write(id_s)
d74ed492efdd Uploaded
tyty
parents:
diff changeset
63 #h.write('\n')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
64 for j in range(0, (len(react[id_s]))):
d74ed492efdd Uploaded
tyty
parents:
diff changeset
65 if react[id_s][j]!='NA':
d74ed492efdd Uploaded
tyty
parents:
diff changeset
66 f.write(str(j+1))
d74ed492efdd Uploaded
tyty
parents:
diff changeset
67 f.write('\t')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
68 f.write(str(react[id_s][j]))
d74ed492efdd Uploaded
tyty
parents:
diff changeset
69 f.write('\n')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
70 #h.write(str(react[id_s][j])) #Output the reactivities
d74ed492efdd Uploaded
tyty
parents:
diff changeset
71 #h.write('\t')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
72 f.close()
d74ed492efdd Uploaded
tyty
parents:
diff changeset
73 #h.write('\n')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
74 #h.write('\n')
d74ed492efdd Uploaded
tyty
parents:
diff changeset
75 os.system("Fold "+syspath+"temp.txt"+" -sh"+" "+syspath+"constraint.txt"+" "+syspath+"output_f/"+id_s+".ct")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
76 else:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
77 print(id_s+" not in the data of react!")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
78 os.system("draw "+syspath+"output_f/"+id_s+".ct "+syspath+"output_f/"+id_s+".ps")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
79 else:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
80 print(id_s+" not in the data of sequences!")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
81
d74ed492efdd Uploaded
tyty
parents:
diff changeset
82 #Remove the unnecessary files
d74ed492efdd Uploaded
tyty
parents:
diff changeset
83 os.system("tar -zcvPf "+output_file+" "+syspath+"output_f/"+"*.* 2>"+syspath+"log.txt")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
84 os.system("rm -f "+syspath+"temp.txt")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
85 os.system("rm -r "+syspath+"output_f")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
86 if flag == 1:
d74ed492efdd Uploaded
tyty
parents:
diff changeset
87 os.system("rm -f "+syspath+"constraint.txt")
d74ed492efdd Uploaded
tyty
parents:
diff changeset
88 # h.close()
d74ed492efdd Uploaded
tyty
parents:
diff changeset
89
d74ed492efdd Uploaded
tyty
parents:
diff changeset
90
d74ed492efdd Uploaded
tyty
parents:
diff changeset
91
d74ed492efdd Uploaded
tyty
parents:
diff changeset
92
d74ed492efdd Uploaded
tyty
parents:
diff changeset
93