This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Subseq bam file

Hi Biostars,

Does anyone know how to subsample read from a bam file? The below command gives the read number of this bam file. I want to get about 100,000,000 read out of 122,441,229 read.

enter image description here

seqtk provides similar function with fastq file like the command below. I was wondering if I can find a bam file version of seqtk.

./seqtk sample -s101 /data/long_read/lr_consoritum/pcb/ENCFF563QZR.fastq 1844630 > ENCFF563QZR_sub.fq
bam subseq

You can probably use BBTools for this as well (untested) :

reformat.sh -Xmx4g in=your.bam out=read.fastq.gz reads=100000000 primaryonly=t

If you have paired-end data then

reformat.sh -Xmx4g in=your.bam out1=read1.fastq.gz out=read1.fastq.gz reads=100000000 primaryonly=t 

1 answer

 samtools view  --subsample 0.816718 in.bam

Log in to answer this question.