# HG changeset patch # User dave # Date 1569961502 14400 # Node ID 03aeb837e398ef524eb97da0f1e25119265c88dc # Parent 20823bce09e70fd9497e5a3f9e533aa2cc9849c4 Uploaded diff -r 20823bce09e7 -r 03aeb837e398 downsample.xml --- a/downsample.xml Tue Sep 24 16:20:27 2019 -0400 +++ b/downsample.xml Tue Oct 01 16:25:02 2019 -0400 @@ -1,32 +1,75 @@ - + reads to desired coverage samtools gawk = 1) exit 1 ; else print f }') ; - then samtools view '$reads' -s \$FACTOR -O $reads.datatype -o '$output' ; - else ; - cp '$reads' '$output' + if FACTOR=\$(samtools depth '$reads' | awk '{ readcovs[x++]=\$3; } END { n = asort(readcovs) ; idx=int((x+1)/2) ; coverage = ((idx==(x+1)/2) ? readcovs[idx] : (readcovs[idx]+readcovs[idx+1])/2) ; factor = 1/(coverage/$target_coverage) ; if (factor >= 1) exit 1 ; else print factor }') ; + then samtools view '$reads' -s \$FACTOR -O BAM -o '$output' -@ \${GALAXY_SLOTS:-1} ; + else samtools view -O BAM '$reads' -o '$output' ; fi ]]> - + - - - - - + + + + + + - + = 1) exit 1 ; + else print factor + }' + +On an exit code of 1, the tool will simply copy the input to the output without +altering it. If the :bash:`awk` step returns a value instead, the tool then runs +:bash:`samtools view -s 1 / (median coverage / desired coverage)` + +]]> diff -r 20823bce09e7 -r 03aeb837e398 test-data/downsample-in1.bam Binary file test-data/downsample-in1.bam has changed diff -r 20823bce09e7 -r 03aeb837e398 test-data/downsample-out1.bam Binary file test-data/downsample-out1.bam has changed