Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plot_cladogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pylab import *
from lefse import *
import numpy as np
# support outputting editable texts in pdf
matplotlib.rcParams['pdf.fonttype'] = 42

colors = ['r','g','b','m','c',[1.0,0.5,0.0],[0.0,1.0,0.0],[0.33,0.125,0.0],[0.75,0.75,0.75],'k']
dark_colors = [[0.4,0.0,0.0],[0.0,0.2,0.0],[0.0,0.0,0.4],'m','c',[1.0,0.5,0.0],[0.0,1.0,0.0],[0.33,0.125,0.0],[0.75,0.75,0.75],'k']
Expand Down Expand Up @@ -43,6 +45,7 @@ def read_params(args):
parser.add_argument('input_file', metavar='INPUT_FILE', type=str, help="tab delimited input file")
parser.add_argument('output_file', metavar='OUTPUT_FILE', type=str, help="the file for the output image")
parser.add_argument('--clade_sep',dest="clade_sep", type=float, default=1.5)
parser.add_argument('--customized_colors',dest="customized_colors", help="Accept a list of colors in format like <red,blue,yellow>", type=str, default="")
parser.add_argument('--max_lev',dest="max_lev", type=int, default=-1)
parser.add_argument('--max_point_size',dest="max_point_size", type=float, default=6.0)
parser.add_argument('--min_point_size',dest="min_point_size", type=float, default=1)
Expand Down Expand Up @@ -334,13 +337,15 @@ def get_col_attr(x):
if l2 != None:
for o in l2.findobj(get_col_attr):
o.set_color(params['fore_color'])
# add bbox to deal with legnd overflow
# add bbox_inches to deal with legnd overflow
plt.savefig(out_file,format=params['format'],facecolor=params['back_color'],edgecolor=params['fore_color'],dpi=params['dpi'], bbox_inches='tight')
plt.close()

if __name__ == '__main__':
params = read_params(sys.argv)
params['fore_color'] = 'w' if params['back_color'] == 'k' else 'k'
if params['customized_colors']:
colors = [i.strip() for i in params['customized_colors'].split(',')]
clad_tree = read_data(params['input_file'],params)
draw_tree(params['output_file'],clad_tree,params)

5 changes: 5 additions & 0 deletions plot_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from lefse import *
import random as rand

matplotlib.rcParams['pdf.fonttype'] = 42

colors = ['r','g','b','m','c']

def read_params(args):
Expand All @@ -23,6 +25,7 @@ def read_params(args):
parser.add_argument('--subcl_mean',dest="subcl_mean", type=str, choices=["y","n"], default="y")
parser.add_argument('--subcl_median',dest="subcl_median", type=str, choices=["y","n"], default="y")
parser.add_argument('--font_size',dest="font_size", type=str, default="10")
parser.add_argument('--customized_colors',dest="customized_colors", type=str, default="",help="Accept a list of colors in format like <red,blue,yellow>")
parser.add_argument('-n',dest="unused", metavar="flt", type=float, default=-1.0,help="unused")
parser.add_argument('--format', dest="format", default="png", choices=["png","pdf","svg"], type=str, help="the format for the output file")
parser.add_argument('-f', dest="f", default="diff", choices=["all","diff","one"], type=str, help="wheter to plot all features (all), only those differentially abundant according to LEfSe or only one (the one given with --feature_name) ")
Expand Down Expand Up @@ -91,6 +94,7 @@ def plot(name,k_n,feat,params):
pos = arange(fr,to)
max_x = to
col = colors[j%len(colors)]
#print(col)
vv = [v1/norm for v1 in val]
median = numpy.median(vv)
mean = numpy.mean(vv)
Expand Down Expand Up @@ -142,6 +146,7 @@ def get_edgecol_attr(x):
params['fore_color'] = 'w' if params['back_color'] == 'k' else 'k'
features = read_data(params['input_file_1'],params['input_file_2'],params)
if params['archive'] == "zip": file = zipfile.ZipFile(params['output_file'], "w")
if params['customized_colors']: colors = [i.strip() for i in params['customized_colors'].split(',')]
for k,f in features.items():
print("Exporting ", k)
if params['archive'] == "zip":
Expand Down
6 changes: 6 additions & 0 deletions plot_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from pylab import *
from collections import defaultdict

matplotlib.rcParams['pdf.fonttype'] = 42

from lefse import *
import argparse

Expand All @@ -17,6 +19,7 @@ def read_params(args):
parser.add_argument('output_file', metavar='OUTPUT_FILE', type=str, help="the file for the output image")
parser.add_argument('--feature_font_size', dest="feature_font_size", type=int, default=7, help="the file for the output image")
parser.add_argument('--format', dest="format", choices=["png","svg","pdf"], default='png', type=str, help="the format for the output file")
parser.add_argument('--customized_colors',dest="customized_colors", help="Accept a list of colors in format like <red,blue,yellow>", type=str, default="")
parser.add_argument('--dpi',dest="dpi", type=int, default=72)
parser.add_argument('--title',dest="title", type=str, default="")
parser.add_argument('--title_font_size',dest="title_font_size", type=str, default="12")
Expand Down Expand Up @@ -172,6 +175,9 @@ def plot_histo_ver(path,params,data,report_features):
if __name__ == '__main__':
params = read_params(sys.argv)
params['fore_color'] = 'w' if params['back_color'] == 'k' else 'k'
# support customized_colors
if params['customized_colors']:
colors = [i.strip() for i in params['customized_colors'].split(',')]
data = read_data(params['input_file'],params['output_file'],params['otu_only'])
if params['orientation'] == 'v': plot_histo_ver(params['output_file'],params,data,params['report_features'])
else: plot_histo_hor(params['output_file'],params,data,len(data['cls']) == 2,params['report_features'])
Expand Down