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!
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
>=
I'd rather use bedtools intersect (or bedops intersect/element-of) than mess around with
awk
. More performant and better documented, easier to read.Great suggestions!