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.
Edit:
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.
I think samtools view -
and awk
route seems viable.
re
, which would explain it? Also just run time, what is slow? Finally any additional information, e.g. it's human always helps, e.g. if it turns out to be bacteria ... thats different. $\endgroup$samtools view -h
, skip header lines, and then make sed or awk print only lines overlapping an array of numbers you define upfront. That's almost no bottleneck, it just has to go through the entire file once which is not slow. $\endgroup$awk 'NR==N'
$\endgroup$