Consider a sorted, indexed, only mapped reads containing BAM file.
Is there a way to get a sub BAM based on read line numbers?
For example get a sub BAM file which contains read line numbers [1, 3, 8, 70] of the original BAM.
This can be done iteratively using a counter but its too slow. Is there a way to do this using samtools view or some tool like it.
Size of the BAM file is ~7GB. Its human exome.
I'm using Julia (https://github.com/BioJulia/XAM.jl/) to iterate over the BAM and it takes me ~300 seconds to iterate over all the records. I feel this is too slow.
I'm running a function on each read of the BAM file and it decides which bucket the read has to go into. So this is specific subsampling.
samtools view - and
awk route seems viable.