Question: Getting length of every interval in a bed file
0
gravatar for arsala521
9 months ago by
arsala52110
arsala52110 wrote:

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

ADD COMMENTlink modified 9 months ago by onestop_data250 • written 9 months ago by arsala52110
1

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 REPLYlink modified 9 months ago • written 9 months ago by genomax91k
1
gravatar for onestop_data
9 months ago by
onestop_data250
onestop_data250 wrote:

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 COMMENTlink modified 9 months ago • written 9 months ago by onestop_data250
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1148 users visited in the last hour