view predict/rtts_plot.py @ 39:c5f80e82efb7 draft

Uploaded
author tyty
date Mon, 20 Oct 2014 14:57:26 -0400
parents a292aaf51735
children
line wrap: on
line source

#!/usr/bin/env python
#Make a plot of reactivity distribution

import sys
import numpy as np
import matplotlib
from pylab import *
import math

#Convert the reactivities (Make NA to 0)
def convert_react(a):
    r = []
    for i in range(len(a)):
        if a[i]!='NA':
            r.append(float(a[i]))
        else:
            r.append(float(0))
    return r
        

#Make a plot of the distribution
def make_plot(ar,id_s,path):
    N = len(ar)
    a = convert_react(ar)
    w = 1
    ind = np.arange(N)

    fig = figure()
    fig, ax = subplots()
    ax.bar(ind+w, a, width = w, color = 'r',edgecolor = 'r')
    ax.set_ylabel('DMS Reactivity')
    ax.set_xlabel('Nucleotide Index')

    
    mag = int(math.log(N,10))-1
    tail = 10**mag

    intervel = int(math.ceil(float(N)/tail)/5)
    print(N)
    print(intervel)
    tl = []
    k = 0
    ax.set_xticks(np.arange(0,N,intervel*tail))
    print(np.arange(0,N,intervel*tail))
    ax.set_xticklabels(np.arange(0,N,intervel*tail))

    ax.set_title(id_s+" reactivity distribution")
    savefig(path+id_s+'.tif')