def main(): args = docopt(__doc__) args = BtPlot.check_input(args) blobdb_f = args['--infile'] rank = args['--rank'] min_length = int(args['--length']) max_group_plot = int(args['--plotgroups']) hide_nohits = args['--nohit'] taxrule = args['--taxrule'] c_index = args['--cindex'] exclude_groups = args['--exclude'] labels = args['--label'] colour_f = args['--colours'] refcov_f = args['--refcov'] catcolour_f = args['--catcolour'] multiplot = args['--multiplot'] out_prefix = args['--out'] sort_order = args['--sort'] sort_first = args['--sort_first'] hist_type = args['--hist'] no_title = args['--notitle'] ignore_contig_length = args['--noscale'] format_plot = args['--format'] no_plot_blobs = args['--noblobs'] no_plot_reads = args['--noreads'] legend_flag = args['--legend'] cumulative_flag = args['--cumulative'] cov_lib_selection = args['--lib'] filelabel = args['--filelabel'] exclude_groups = BtIO.parseCmdlist(exclude_groups) refcov_dict = BtIO.parseReferenceCov(refcov_f) user_labels = BtIO.parseCmdLabels(labels) catcolour_dict = BtIO.parseCatColour(catcolour_f) colour_dict = BtIO.parseColours(colour_f) # Load BlobDb print BtLog.status_d['9'] % blobdb_f blobDb = BtCore.BlobDb('blobplot') blobDb.version = blobtools.__version__ blobDb.load(blobdb_f) # Generate plot data print BtLog.status_d['18'] data_dict, min_cov, max_cov, cov_lib_dict = blobDb.getPlotData( rank, min_length, hide_nohits, taxrule, c_index, catcolour_dict) plotObj = BtPlot.PlotObj(data_dict, cov_lib_dict, cov_lib_selection, 'blobplot', sort_first) plotObj.exclude_groups = exclude_groups plotObj.version = blobDb.version plotObj.format = format_plot plotObj.max_cov = max_cov plotObj.min_cov = min_cov plotObj.no_title = no_title plotObj.multiplot = multiplot plotObj.hist_type = hist_type plotObj.ignore_contig_length = ignore_contig_length plotObj.max_group_plot = max_group_plot plotObj.legend_flag = legend_flag plotObj.cumulative_flag = cumulative_flag # order by which to plot (should know about user label) plotObj.group_order = BtPlot.getSortedGroups(data_dict, sort_order, sort_first) # labels for each level of stats plotObj.labels.update(plotObj.group_order) # plotObj.group_labels is dict that contains labels for each group : all/other/user_label if (user_labels): for group, label in user_labels.items(): plotObj.labels.add(label) plotObj.group_labels = {group: set() for group in plotObj.group_order} plotObj.relabel_and_colour(colour_dict, user_labels) plotObj.compute_stats() plotObj.refcov_dict = refcov_dict # Plotting info_flag = 1 out_f = '' for cov_lib in plotObj.cov_libs: plotObj.ylabel = "Coverage" plotObj.xlabel = "GC proportion" if (filelabel): plotObj.ylabel = basename(cov_lib_dict[cov_lib]['f']) out_f = "%s.%s.%s.p%s.%s.%s" % (blobDb.title, taxrule, rank, max_group_plot, hist_type, min_length) if catcolour_dict: out_f = "%s.%s" % (out_f, "catcolour") if ignore_contig_length: out_f = "%s.%s" % (out_f, "noscale") if c_index: out_f = "%s.%s" % (out_f, "c_index") if exclude_groups: out_f = "%s.%s" % (out_f, "exclude_" + "_".join(exclude_groups)) if labels: out_f = "%s.%s" % (out_f, "userlabel_" + "_".join( set([name for name in user_labels.values()]))) out_f = "%s.%s" % (out_f, "blobplot") if (plotObj.cumulative_flag): out_f = "%s.%s" % (out_f, "cumulative") if (plotObj.multiplot): out_f = "%s.%s" % (out_f, "multiplot") out_f = BtIO.getOutFile(out_f, out_prefix, None) if not (no_plot_blobs): plotObj.plotScatter(cov_lib, info_flag, out_f) info_flag = 0 if not (no_plot_reads) and ( plotObj.cov_libs_total_reads_dict[cov_lib]): # prevent plotting if --noreads or total_reads == 0 plotObj.plotBar(cov_lib, out_f) plotObj.write_stats(out_f)
if rank not in RANKS: BtLog.error('9', rank) # Are sort_order and hist_type sane? if not sort_order in ['span', 'count']: BtLog.error('14', sort_order) if not hist_type in ['span', 'count']: BtLog.error('15', hist_type) # is taxrule provided? if taxrule not in TAXRULES: BtLog.error('8', taxrule) # compute labels if supplied user_labels = BtPlot.parse_labels(labels) if (exclude_groups): if "," in exclude_groups: exclude_groups = exclude_groups.rsplit(",") else: exclude_groups = exclude_groups refcov_dict = {} if (refcov_f): refcov_dict = BtPlot.parseRefCov(refcov_f) catcolour_dict = {} if (catcolour_f) and (c_index): BtLog.error('24') elif (catcolour_f):
for name in readFasta(infile): fasta_order.append(name) fasta_dict[name] = 0.0 return fasta_dict, fasta_order if __name__ == '__main__': main_dir = dirname(__file__) #print data_dir args = docopt(__doc__) assembly_f = args['--infile'] cov_fs = args['--cov'] fasta_dict = {} fasta_order = [] if not isfile(assembly_f): BtLog.error('0', assembly_f) else: fasta_dict, fasta_order = parseFasta(assembly_f) for cov_f in cov_fs: if not isfile(cov_f): BtLog.error('0', cov_f) else: lib_cov_dict = BtPlot.parseCovFile(cov_f) for name in fasta_order: fasta_dict[name] = fasta_dict.get(name, 0.0) + lib_cov_dict[name] for name in fasta_order: print "%s\t%s" % (name, fasta_dict[name])
#exclude_groups = args['--exclude'] format = args['--format'] #no_plot_blobs = args['--noblobs'] #no_plot_reads = args['--noreads'] #refcov_f = args['--refcov'] #catcolour_f = args['--catcolour'] # Does blobdb_f exist ? if not isfile(blobdb_f): BtLog.error('0', blobdb_f) # Does cov_f exist ? if not isfile(cov_f): BtLog.error('0', cov_f) # parse cov file in dict cov_dict = BtPlot.parseCovFile(cov_f) # Are ranks sane ? if rank not in RANKS: BtLog.error('9', rank) # Are sort_order and hist_type sane? if not sort_order in ['span', 'count']: BtLog.error('14', sort_order) if not hist_type in ['span', 'count']: BtLog.error('15', hist_type) # is taxrule provided? if taxrule not in TAXRULES: BtLog.error('8', taxrule)
fasta_order.append(name) fasta_dict[name] = 0.0 return fasta_dict, fasta_order if __name__ == '__main__': main_dir = dirname(__file__) #print data_dir args = docopt(__doc__) assembly_f = args['--infile'] cov_fs = args['--cov'] fasta_dict = {} fasta_order = [] if not isfile(assembly_f): BtLog.error('0', assembly_f) else: fasta_dict, fasta_order = parseFasta(assembly_f) for cov_f in cov_fs: if not isfile(cov_f): BtLog.error('0', cov_f) else: lib_cov_dict = BtPlot.parseCovFile(cov_f) for name in fasta_order: fasta_dict[name] = fasta_dict.get(name, 0.0) + lib_cov_dict[name] for name in fasta_order: print "%s\t%s" % (name, fasta_dict[name])