Hi,

I'm trying to extract reads based on their start coordinate in a bam file. I've tried using samtools view but that seems to give all reads covering that region, not originating there.

Apologies if this has been asked elsewhere but I couldn't find an answer via Google.

Many thanks.
Something like:

`samtools view -h -q 10 in.bam chr1:1000-1500 | awk 'BEGIN{OFS="\t"}{if($1 ~ @) {print} else {if($4 >= 1000 || $4 <=1500) {print} else {}}}' | samtools view -Sbo output.bam -` 

One could restructure this to get around the default print action in awk, but this will also get the job done.