Getting length of every interval in a bed file
1
0
Entering edit mode
4.3 years ago
arsala521 ▴ 30

Hello everyone,

I want to get the length of every region present in my bed file. I went through the bedtools and bedops options but they don't have the command for that.

I don't want the combine length of all the regions of bed file, instead I need length of every interval.

Is there any way to do that?

Thanks in advance

bed • 2.2k views
ADD COMMENT
1
Entering edit mode

You could do something like this:

$ more test.bed
chr7    127471196  127472363  Pos1  0  +
chr7    127472363  127473540  Pos2  0  +
chr7    127473530  127475693  Pos3  0  +
chr7    127474697  127475866  Pos4  0  +
chr7    127475864  127487031  Neg1  0  -
chr7    127477031  127478193  Neg2  0  -
chr7    127478198  127489365  Neg3  0  -
chr7    127479365  127490538  Pos5  0  +
chr7    127480532  127481691  Neg4  0  -

$ awk  '{OFS="\t"}{print $1,$2,$2,($3-$2)}' test.bed 
chr7    127471196       127471196       1167
chr7    127472363       127472363       1177
chr7    127473530       127473530       2163
chr7    127474697       127474697       1169
chr7    127475864       127475864       11167
chr7    127477031       127477031       1162
chr7    127478198       127478198       11167
chr7    127479365       127479365       11173
chr7    127480532       127480532       1159
ADD REPLY
1
Entering edit mode
4.3 years ago
onestop_data ▴ 330

This should do it. awk '{print($3-$2)}' {YOUR_BEDFILE}

INPUT

chr1 213941196 213942363

chr1 213942363 213943535

chr1 213943530 213944677

OUTPUT

1167

1172

1147

ADD COMMENT

Login before adding your answer.

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