Skip to content

Commit

Permalink
Format subsampling
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Mar 7, 2024
1 parent f2d760c commit 7e79495
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/local/subsampling.nf
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ process SUBSAMPLING {
samtools coverage ${bam_file} > samtools_coverage_${bam_file.baseName}.txt
csvtk grep -t -f3 -p 16569 -C '\$' samtools_coverage_${bam_file.baseName}.txt
mean_cov=\$(csvtk grep -t -f3 -p 16569 -C '\$' samtools_coverage_${bam_file.baseName}.txt | csvtk cut -t -f 7)
# convert to integer
mean_cov_int=\$(printf "%.0f" "\$mean_cov")
# set seed to 1 (for reproducbility) and FRAC to coverage/mean_cov (e.g. 1.2)
fraction=\$(echo "scale=4; 1+(${coverage} / \${mean_cov})" | bc)
if [ \${mean_cov_int} -gt ${coverage} ]
then
samtools view -s \$fraction -b -o ${bam_file.baseName}.subsampled.bam ${bam_file}
Expand Down

0 comments on commit 7e79495

Please sign in to comment.