Commit 9c539ff0 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

delete matplot, no longuer used

parent 7ce6a47b
#
# Copyright (C) 2009 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Plateforme bioinformatique Midi Pyrenees'
__copyright__ = 'Copyright (C) 2009 INRA'
__license__ = 'GNU General Public License'
__version__ = '1.0'
__email__ = 'support.genopole@toulouse.inra.fr'
__status__ = 'beta'
import tempfile, re
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from ng6 import Ace
class Matplot(object):
"""
Class Matplot: in charge to create matplotlib graphics
"""
@staticmethod
def create_length_histogram(seqs):
"""
@param seqs : sequences
@return : the path to the image
"""
x = []
for id, desc, seq, qual in seqs :
x.append(len(seq))
plt.clf()
plt.hist(x, 50, alpha=0.75)
plt.xlabel("Sequence length (bp)")
plt.title("Distribution of sequence lengths over all sequences")
plt.grid(True)
out_file = tempfile.NamedTemporaryFile(suffix=".png").name
plt.savefig(out_file)
return out_file
@staticmethod
def create_length_histogram_re(seq_file):
"""
Uses regexp instead of seqIO to select sequences, requires a sequence is defined on only 1 line
@param seq_file : a sequence file
@return : the path to the image
"""
x = {}
seqre = re.compile("^[ACTGN]+$")
f = open(seq_file, "r")
# First find all sequences
for line in f :
line = line.strip()
# If the line is a sequence line
if seqre.search(line):
if x.has_key(len(line)):
x[len(line)] += 1
else :
x[len(line)] = 1
# Then build the histogram
header = []
value = []
for val in sorted(x.keys()):
header.append(val)
value.append(x[val])
plt.clf()
plt.bar(header, value, alpha=0.75, align="center")
plt.xlabel("Sequence length (bp)")
plt.title("Distribution of sequence lengths over all sequences")
plt.grid(True)
out_file = tempfile.NamedTemporaryFile(suffix=".png").name
plt.savefig(out_file)
return out_file
@staticmethod
def create_histogram(hash_table, limit=30, ylabel="", xlabel="", title=""):
"""
@param hash_table : a table of header values
@param limit : the number of values to display
@param ylabel : the label on y
@param xlabel : the label on x
@param title : the figure title
@return : the path to the image
"""
headers = map(int, hash_table.keys())
headers.sort()
vals = []
for head_val in headers:
vals.append(hash_table[str(head_val)])
plt.clf()
plt.xlim(xmax=limit)
plt.bar(headers[:limit], vals[:limit], log=True, alpha=0.75, align="center")
plt.ylabel(str(ylabel) + " (log scale)")
plt.xlabel(str(xlabel))
plt.title(str(title))
out_file = tempfile.NamedTemporaryFile(suffix=".png").name
plt.savefig(out_file)
return out_file
@staticmethod
def create_multiple_length_histogram(all_samples):
"""
@param all_samples : dictionnary of length repartition
@return : the path to the image
"""
cols=["blue","green","red","magenta","#008080","#808000","yellow","cyan","#4B0082",
"#B00000","#808080","#8B4513","#98FB98","#C71585","#FFA500","#FFD700","#000080"]
plt.clf()
ax = plt.subplot(111)
cptr = 0
samples = sorted(all_samples.keys())
for sample in samples:
positions = all_samples[sample].keys() ;
positions.sort()
x = [] ; y = []
for p in positions:
x.append(int(p))
y.append(int(all_samples[sample][p]))
plt.plot(x, y, label=sample, color=cols[cptr%len(cols)], alpha=0.75)
cptr += 1
# if more than 10 samples have to be displayed
if len(all_samples) < 10 :
leg = plt.legend(loc='best', ncol=2, mode=None, shadow=True, fancybox=True)
for legtitle in leg.get_texts():
legtitle.set_fontsize('small')
plt.xlabel("Sequences length")
plt.ylabel("Number of sequences")
plt.title("Sequences length distribution by sample")
plt.grid(True)
out_file = tempfile.NamedTemporaryFile(suffix=".png").name
plt.savefig(out_file)
return out_file
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment