Skip to content

Commit

Permalink
fixed bug with CLI of plotting methods introduced in 1.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
donovan-h-parks committed Aug 10, 2019
1 parent 64cab7f commit 1a93438
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
6 changes: 3 additions & 3 deletions bin/checkm
Expand Up @@ -324,7 +324,7 @@ Example: checkm qa ./output/lineage.ms ./output

# generic arguments for plots
plot_need_qa_results_parser = argparse.ArgumentParser(add_help=False)
plot_need_qa_results_parser.add_argument('output_dir', help="directory specified during qa command")
plot_need_qa_results_parser.add_argument('results_dir', help="directory specified during qa command")

plot_parser = argparse.ArgumentParser(add_help=False)
plot_parser.add_argument('bin_dir', help="directory containing bins to plot (fasta format)")
Expand Down Expand Up @@ -391,9 +391,9 @@ Example: checkm qa ./output/lineage.ms ./output
formatter_class=CustomHelpFormatter,
description='Create image with GC, CD, and TD distribution plots together.',
epilog='Example: checkm dist_plot ./output ./bins ./plots tetra.tsv 95')
plot_dist_parser.add_argument('analyze_dir', help="directory specified during analyze command")
plot_dist_parser.add_argument('results_dir', help="directory specified during analyze command")
plot_dist_parser.add_argument('bin_dir', help="directory containing bins to plot (fasta format)")
plot_dist_parser.add_argument('plot_dir', help="directory to hold plots")
plot_dist_parser.add_argument('output_dir', help="directory to hold plots")
plot_dist_parser.add_argument('tetra_profile', help='tetranucleotide profiles for each sequence (see tetra command)')
plot_dist_parser.add_argument('distributions', help='reference distribution(s) to plot; integer between 0 and 100', nargs='+', type=int, choices=xrange(0, 101), default=95, metavar='dist_value')

Expand Down
3 changes: 3 additions & 0 deletions checkm/VERSION
@@ -1,3 +1,6 @@
1.0.17
- fixed bug with CLI of plotting methods introduced in 1.0.16

1.0.16
- made ~/.checkm the default directory for CheckM reference data
- "checkm data setRoot <directory>" is no longer interactive and the directory must be given on the command line
Expand Down
2 changes: 1 addition & 1 deletion checkm/coverageWindows.py
Expand Up @@ -94,7 +94,7 @@ def run(self, binFiles, bamFile, bAllReads, minAlignPer, maxEditDistPer, windowS

# make sure BAM file is sorted
if not os.path.exists(bamFile + '.bai'):
self.logger.error(' [Error] BAM file is not sorted: ' + bamFile + '\n')
self.logger.error('BAM file is not sorted: ' + bamFile + '\n')
sys.exit(1)

# calculate coverage of each BAM file
Expand Down
58 changes: 29 additions & 29 deletions checkm/main.py
Expand Up @@ -411,7 +411,7 @@ def gcPlot(self, options):
self.logger.info('[CheckM - gc_plot] Creating GC histogram and delta-GC plot.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -424,7 +424,7 @@ def gcPlot(self, options):
plots.plot(f, options.distributions)

binId = binIdFromFilename(f)
outputFile = os.path.join(options.plot_dir, binId) + '.gc_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.gc_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -435,7 +435,7 @@ def codingDensityPlot(self, options):
self.logger.info('[CheckM - coding_plot] Creating coding density histogram and delta-CD plot.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -448,7 +448,7 @@ def codingDensityPlot(self, options):
plots.plot(f, options.distributions)

binId = binIdFromFilename(f)
outputFile = os.path.join(options.plot_dir, binId) + '.coding_density_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.coding_density_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -459,7 +459,7 @@ def tetraDistPlot(self, options):
self.logger.info('[CheckM - tetra_plot] Creating tetra-distance histogram and delta-TD plot.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -475,7 +475,7 @@ def tetraDistPlot(self, options):
binId = binIdFromFilename(f)
plots.plot(f, tetraSigs, options.distributions)

outputFile = os.path.join(options.plot_dir, binId) + '.tetra_dist_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.tetra_dist_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -486,7 +486,7 @@ def distributionPlots(self, options):
self.logger.info('[CheckM - dist_plot] Creating GC, CD, and TD distribution plots.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -502,7 +502,7 @@ def distributionPlots(self, options):
binId = binIdFromFilename(f)
plots.plot(f, tetraSigs, options.distributions)

outputFile = os.path.join(options.plot_dir, binId) + '.ref_dist_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.ref_dist_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -513,7 +513,7 @@ def tetraPcaPlot(self, options):
self.logger.info('[CheckM - tetra_pca] Creating PCA plot of tetranucleotide signatures.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -530,7 +530,7 @@ def tetraPcaPlot(self, options):
plots.plot(f, seqIds, pc, variance)

binId = binIdFromFilename(f)
outputFile = os.path.join(options.plot_dir, binId) + '.tetra_pca_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.tetra_pca_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -542,7 +542,7 @@ def coveragePcaPlot(self, options):

checkDirExists(options.bin_dir)
checkFileExists(options.coverage_file)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand Down Expand Up @@ -579,7 +579,7 @@ def coveragePcaPlot(self, options):
plots.plot(f, seqIds, pc, variance)

binId = binIdFromFilename(f)
outputFile = os.path.join(options.plot_dir, binId) + '.cov_pca_plots.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.cov_pca_plots.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -591,7 +591,7 @@ def gcBiasPlot(self, options):
self.logger.info('[CheckM - gc_bias_plot] Plotting bin coverage as a function of GC.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -607,7 +607,7 @@ def gcBiasPlot(self, options):
plots.plot(f, coverageProfile)

binId = binIdFromFilename(f)
outputFile = os.path.join(options.plot_dir, binId) + '.gc_bias_plot.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.gc_bias_plot.' + options.image_type
plots.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -619,7 +619,7 @@ def nxPlot(self, options):
self.logger.info('[CheckM - nx_plot] Creating Nx-plots.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -631,7 +631,7 @@ def nxPlot(self, options):
filesProcessed += 1
nx.plot(f)

outputFile = os.path.join(options.plot_dir, binId) + '.nx_plot.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.nx_plot.' + options.image_type
nx.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -643,7 +643,7 @@ def cumulativeLengthPlot(self, options):
self.logger.info('[CheckM - len_plot] Creating cumulative sequence length plot.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -655,7 +655,7 @@ def cumulativeLengthPlot(self, options):
filesProcessed += 1
plot.plot(f)

outputFile = os.path.join(options.plot_dir, binId) + '.seq_len_plot.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.seq_len_plot.' + options.image_type
plot.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -667,7 +667,7 @@ def lengthHistogram(self, options):
self.logger.info('[CheckM - len_hist] Creating sequence length histogram.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -679,7 +679,7 @@ def lengthHistogram(self, options):
filesProcessed += 1
plot.plot(f)

outputFile = os.path.join(options.plot_dir, binId) + '.len_hist.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.len_hist.' + options.image_type
plot.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -691,14 +691,14 @@ def markerPlot(self, options):
self.logger.info('[CheckM - marker_plot] Creating marker gene position plot.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

# generate plot for each bin
binFiles = self.binFiles(options.bin_dir, options.extension)

resultsParser = ResultsParser(None)
markerGeneStats = resultsParser.parseMarkerGeneStats(options.output_dir)
binStats = resultsParser.parseBinStatsExt(options.output_dir)
markerGeneStats = resultsParser.parseMarkerGeneStats(options.results_dir)
binStats = resultsParser.parseBinStatsExt(options.results_dir)

plot = MarkerGenePosPlot(options)
filesProcessed = 1
Expand All @@ -713,7 +713,7 @@ def markerPlot(self, options):
bPlotted = plot.plot(f, markerGeneStats[binId], binStats[binId])

if bPlotted:
outputFile = os.path.join(options.plot_dir, binId) + '.marker_pos_plot.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.marker_pos_plot.' + options.image_type
plot.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)
else:
Expand All @@ -727,7 +727,7 @@ def parallelCoordPlot(self, options):
self.logger.info('[CheckM - par_plot] Creating parallel coordinate plot of GC and coverage.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)
checkFileExists(options.coverage_file)

binFiles = self.binFiles(options.bin_dir, options.extension)
Expand All @@ -742,7 +742,7 @@ def parallelCoordPlot(self, options):
seqStats = {}
for f in binFiles:
binId = binIdFromFilename(f)
seqStats[binId] = binStats.sequenceStats(options.output_dir, f)
seqStats[binId] = binStats.sequenceStats(options.results_dir, f)

# create plot for each bin

Expand All @@ -755,7 +755,7 @@ def parallelCoordPlot(self, options):

plot.plot(binId, seqStats, coverageStats)

outputFile = os.path.join(options.plot_dir, binId) + '.paralel_coord_plot.' + options.image_type
outputFile = os.path.join(options.output_dir, binId) + '.paralel_coord_plot.' + options.image_type
plot.savePlot(outputFile, dpi=options.dpi)
self.logger.info('Plot written to: ' + outputFile)

Expand All @@ -767,7 +767,7 @@ def binQAPlot(self, options):
self.logger.info('[CheckM - bin_qa_plot] Creating bar plot of bin quality.')

checkDirExists(options.bin_dir)
makeSurePathExists(options.plot_dir)
makeSurePathExists(options.output_dir)

binFiles = self.binFiles(options.bin_dir, options.extension)

Expand All @@ -790,7 +790,7 @@ def binQAPlot(self, options):
bMakePlot = plot.plot(binFiles, binStatsExt, options.bIgnoreHetero, None)

if bMakePlot:
outputFile = os.path.join(options.plot_dir, 'bin_qa_plot.' + options.image_type)
outputFile = os.path.join(options.output_dir, 'bin_qa_plot.' + options.image_type)
plot.savePlot(outputFile, dpi=options.dpi)

self.logger.info('Plot written to: ' + outputFile)
Expand Down
7 changes: 5 additions & 2 deletions checkm/plot/codingDensityPlots.py
Expand Up @@ -21,6 +21,7 @@

import os
import sys
import logging

import numpy as np

Expand All @@ -36,6 +37,8 @@
class CodingDensityPlots(AbstractPlot):
def __init__(self, options):
AbstractPlot.__init__(self, options)

self.logger = logging.getLogger('timestamp')

def plot(self, fastaFile, distributionsToPlot):
# Set size of figure
Expand All @@ -52,9 +55,9 @@ def plot(self, fastaFile, distributionsToPlot):

def plotOnAxes(self, fastaFile, distributionsToPlot, axesHist, axesDeltaCD):
# parse Prodigal output
gffFile = os.path.join(self.options.out_folder, 'bins', binIdFromFilename(fastaFile), DefaultValues.PRODIGAL_GFF)
gffFile = os.path.join(self.options.results_dir, 'bins', binIdFromFilename(fastaFile), DefaultValues.PRODIGAL_GFF)
if not os.path.exists(gffFile):
print 'Missing gene feature file (%s). This plot if not compatible with the --genes option.' % DefaultValues.PRODIGAL_GFF
self.logger.error('Missing gene feature file (%s). This plot if not compatible with the --genes option.' % DefaultValues.PRODIGAL_GFF)
sys.exit()

prodigalParser = ProdigalGeneFeatureParser(gffFile)
Expand Down
2 changes: 1 addition & 1 deletion checkm/plot/markerGenePosPlot.py
Expand Up @@ -92,7 +92,7 @@ def plot(self, binFile, markerGeneStats, binStats):

# get position of genes in bin
prodigalFastaParser = ProdigalFastaParser()
geneFile = os.path.join(self.options.out_folder, 'bins', binId, DefaultValues.PRODIGAL_AA)
geneFile = os.path.join(self.options.results_dir, 'bins', binId, DefaultValues.PRODIGAL_AA)
genePos = prodigalFastaParser.genePositions(geneFile)

# Set size of figure
Expand Down

0 comments on commit 1a93438

Please sign in to comment.