annotate predict/rtts_plot.py @ 4:a292aaf51735 draft

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