Tool:Quick Command to Filter Bam Files
0
0
Entering edit mode
2.5 years ago
Sasha ▴ 850

Hi,

Was looking for a while on how to edit bed files to specific chromosome regions which made sense to me. Finally made this quick AWK command that made the outcome simple:

awk '{if ($2>=START_COORDINATES && $3=<END_COORDINATES && $1=="CHROMOSOME") print $1, $2, $3}' file.bed > file_mod.bed

An example with the command would be:

awk '{if ($2>200 && $3 <300 && $1=="chr10") print $1, $2, $3}' file.bed > file_mod.bed

Cheers.

P.S. also - check out Pierre's suggestion below!

bed awk • 943 views
ADD COMMENT
1
Entering edit mode
awk -F '\t' '($1=="chr10" && !($2 >300 || $3 <200))' file.bed > file_mode.bed
ADD REPLY
0
Entering edit mode

Your example requires full containment, in that both start and end are within the interval, whereas the solution by Pierre Lindenbaum solution accepts any overlap.

Though I think there might be a subtle bug there, since in BED format one coordinate is inclusive while the other not, it feels that one check should have >=

ADD REPLY
0
Entering edit mode

I'd rather use bedtools intersect (or bedops intersect/element-of) than mess around with awk. More performant and better documented, easier to read.

ADD REPLY
0
Entering edit mode

Great suggestions!

ADD REPLY

Login before adding your answer.

Traffic: 1748 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