annotate predict/rtts_plot.py @ 112:87ec0ecdc2af draft

Uploaded
author tyty
date Sun, 12 Apr 2015 14:28:30 -0400
parents f1eb39775b93
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
1 #!/usr/bin/env python
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
2 #Make a plot of reactivity distribution
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
3
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
4 import sys
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
5 import os
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
6 import numpy as np
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
7 import matplotlib
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
8 from pylab import *
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
9 import math
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
10
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
11 #Convert the reactivities (Make NA to 0)
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
12 def convert_react(a):
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
13 r = []
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
14 for i in range(len(a)):
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
15 if a[i]!='NA':
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
16 r.append(float(a[i]))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
17 else:
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
18 r.append(float(0))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
19 return r
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
20
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
21
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
22 #Make a plot of the distribution
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
23 def make_plot(ar,id_s,path):
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
24 font = {'family' : 'normal',
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
25 'weight' : 'bold',
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
26 'size' : 16}
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
27 matplotlib.rc('font', **font)
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
28 N = len(ar)
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
29 a = convert_react(ar)
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
30 w = 1
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
31 ind = np.arange(N)
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
32
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
33 fig = figure()
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
34 fig, ax = subplots()
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
35 ax.bar(ind+w, a, width = w, color = 'black',edgecolor = 'black')
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
36 ax.set_ylabel('Final Structural Reactivity (FSR)')
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
37 ax.set_xlabel('Nucleotide Number')
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
38
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
39
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
40 mag = int(math.log(N,10))-1
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
41 tail = 10**mag
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
42
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
43 intervel = int(math.ceil(float(N)/tail/5))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
44 tl = []
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
45 k = 0
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
46 upmax = int(math.ceil(float(N)/intervel/tail)*intervel*tail)+1
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
47 ax.set_xticks(np.arange(0,upmax,intervel*tail))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
48 ax.set_xticklabels(np.arange(0,upmax,intervel*tail))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
49 savefig(os.path.join(path, id_s+'.tif'))
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
50
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
51
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
52
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
53
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
54
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
55
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
56
f1eb39775b93 Uploaded
tyty
parents:
diff changeset
57