Filtering bam file based on depth determined through samtools depth
1
0
Entering edit mode
2.1 years ago
Dak • 0

Hi All,

I have a bam file and I calculated read depth using samtools depth and I now want to filter the bam file to have only the contigs that have a depth between a certain value. I was able to filter the samtools output to create a txt file that only contains the depth region im looking for, but Im struggling to then filter the bam file with this information. The depth file has three columns, the contig name, the POS, and the depth

Screen_Shot_of_Depth_File

I attempted to remove the depth column and use grep to search the bam file, but my output was empty. I also tried to find answers with awk, but quickly got confused as I am still a fairly novice coder. Any ideas on how to proceed would be greatly appreciated.

sam bam filter • 849 views
ADD COMMENT
2
Entering edit mode
2.1 years ago
awk -F '\t' '(int($3)> 123 ) {printf("%s\t%d\t%s\n",$1,int($2)-1,$2);}' depth.output | sort -t $'\t' -k1,1 -k2,2n | bedtools merge > select.bed

samtools view -M -L select.bed in.bam
ADD COMMENT

Login before adding your answer.

Traffic: 1700 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6