This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Downsample BAM file according to coverage

I have a BAM file that has 33X whole genome coverage.

I would like to create a new BAM file from the original that has 10X genome coverage.

Is this the correct method?

samtools view -h -s 0.3 in.bam >10x.bam

Also what methods do you use for fast calculation of whole genome coverage? GATK is bloody slow.

reads sequencing bam samtools

~/programs/jvarkit/dist/bamstats04 is pretty good, but it's a pain to compile with ant. Nevertheless, I managed after a day or so and now I'm happy, it's really useful.

USAGE: BamStats04 [options]
 Coverage statistics for a BED file. It uses the Cigar string instead of the start/end to get the voverageVersion: 1.0
Version: null

Options:

--help
-h                            Displays options specific to this tool.
--stdhelp
-H                            Displays options specific to this tool AND options common to all Picard command line
                              tools.
--version                     Displays program version.
IN=File
I=File                        BAM file to process.  Required.
BEDILE=File
BED=File                      BED File.  Required.
NO_DUP=Boolean
NODUP=Boolean                 discard duplicates  Default value: true. This option can be set to 'null' to clear the
                              default value. Possible values: {true, false}
NO_ORPHAN=Boolean
NOORPHAN=Boolean              discard not properly paired  Default value: true. This option can be set to 'null' to
                              clear the default value. Possible values: {true, false}
NO_VENDOR=Boolean
NOVENDOR=Boolean              discard failing Vendor Quality  Default value: true. This option can be set to 'null' to
                              clear the default value. Possible values: {true, false}
MMQ=Integer
MIN_MAPING_QUALITY=Integer    min mapping quality  Default value: 0. This option can be set to 'null' to clear the
                              default value.
MIN_COVERAGE=Integer
MIN_COV=Integer               min coverage to say the position is not covered  Default value: 0. This option can be set
                              to 'null' to clear the default value.

1 answer

Yes, the -s 0.3 will result in an average 10x coverage. One simple method to get total coverage is to simply parse the output of samtools depth.

Log in to answer this question.