Skip to content

Commit

Permalink
Add option to skip coverage plots (issue #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariober committed Mar 15, 2020
1 parent b4a6f09 commit 44fdd18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
20 changes: 13 additions & 7 deletions bin/cnv_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suppressMessages(library(gridExtra))

# -----------------------------------------------------------------------------

VERSION= sprintf('0.15.0; facets=%s', packageVersion('facets'))
VERSION= sprintf('0.16.0; facets=%s', packageVersion('facets'))

docstring<- sprintf('DESCRIPTION \\n\\
Detect somatic copy number variants (CNVs) and estimate purity and ploidy in a\\n\\
Expand Down Expand Up @@ -131,6 +131,10 @@ parser$add_argument('--unmatched', '-u', help=
'Normal sample is unmatched. If set, heterozygote SNPs are\\n\\
called using tumor reads only and logOR calculations are different', action= 'store_true')

parser$add_argument('--no-cov-plot', '-np', help=
'Do not produce coverage plots (they can be memory intensive).\\n\\
Other plots remain unaffected', action= 'store_true')

def_rnd<- 'The name of the input file'
parser$add_argument('--rnd-seed', '-s', help= sprintf(
'Seed for random number generator. Default: %s', def_rnd), type= 'character', default= def_rnd)
Expand Down Expand Up @@ -812,11 +816,13 @@ if(sys.nframe() == 0){
}
rcmat_flt<- filter_rcmat(rcmat= rcmat[['pileup']], min_ndepth= xargs$depth[1],
max_ndepth= xargs$depth[2], target_bed= targets)

write(sprintf('[%s] Plotting histogram of coverage...', Sys.time()), stderr())
plot_coverage(rcmat= rcmat[['pileup']], rcmat_flt= rcmat_flt,
fname= paste0(xargs$out, '.cov.pdf'), title= paste0('Depth of coverage\n', xargs$out))


if(xargs$no_cov_plot == FALSE){
write(sprintf('[%s] Plotting histogram of coverage...', Sys.time()), stderr())
plot_coverage(rcmat= rcmat[['pileup']], rcmat_flt= rcmat_flt,
fname= paste0(xargs$out, '.cov.pdf'), title= paste0('Depth of coverage\n', xargs$out))
}

rcmat[['pileup']]<- NULL

x_ <- gc(verbose= FALSE)
Expand Down Expand Up @@ -887,7 +893,7 @@ if(sys.nframe() == 0){
par(las= 1, mar= c(3, 3, 1, 1), mgp= c(1.5, 0.5, 0), tcl= -0.3)
logRlogORspider(facets$proc_out$out, facets$proc_out$dipLogR)
x_ <- dev.off()

si<- capture.output(sessionInfo())
write(si, stderr())
}
9 changes: 9 additions & 0 deletions test/test_cnv_facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ def testBamInput(self):
self.assertTrue(os.path.exists('test_out/out.csv.gz'))
self.assertEqual('', vcf_validator('test_out/out.vcf.gz'))

def testDoNotPlot(self):
p = sp.Popen("""../bin/cnv_facets.R --no-cov-plot -t data/TCRBOA6-T-WEX.sample.bam -n data/TCRBOA6-N-WEX.sample.bam -vcf data/common.sample.vcf.gz -o test_out/out""", shell=True, stdout= sp.PIPE, stderr= sp.PIPE)
stdout, stderr = p.communicate()
self.assertEqual(0, p.returncode)
self.assertTrue(os.path.exists('test_out/out.vcf.gz'))
self.assertTrue(os.path.exists('test_out/out.cnv.png'))
self.assertTrue(os.path.exists('test_out/out.spider.pdf'))
self.assertTrue(not os.path.exists('test_out/out.cov.pdf'))

def testBamInputNotProperlyPaired(self):
# Prepare a bam files with 'properly paired' flag removed
p = sp.Popen(r"""
Expand Down

0 comments on commit 44fdd18

Please sign in to comment.