How to determine the density and mean of features in specified intervals?
1
0
Entering edit mode
9.3 years ago
Les Ander ▴ 110

Hi

I have 2 bed files.

File1.bed

chr1 1 100 0.5
chr1 900 1000 1.5
chr1 1100 1105 0.5

File2.bed

chr1  1  400
chr1 401 800
chr1 801 1200

I want to determine the frequency of events in File1.bed in each of the intervals in File2.bed

So for the above input files, the output would be

chr1  1  400 1
chr1 401 800 0
chr1 801 1200 2

Any suggestions?

Also, what if in addition to counting the number of features in the window, I also want to compute their average?

interval bed counting bedtools • 2.3k views
ADD COMMENT
0
Entering edit mode
9.3 years ago
LauferVA 4.5k
#!bin/bash

FILE1="file1.bed" ## make sure these files are consistently delimited (space or tab)
FILE2="file2.bed"

while read CHR START_POS END_POS; do
    echo "for the interval" $CHR $START_POS $END_POS
    awk -v CHR=$CHR -v SP=$START_POS -v EP=$END_POS '($1==CHR && $2>=SP && $3<=EP){print $0}' $FILE1 | wc -l
done < "$FILE2"
ADD COMMENT
0
Entering edit mode

Thank you

ADD REPLY
0
Entering edit mode

Hi Les - you are welcome! hope it helped. do you understand how it works?

VL

ADD REPLY

Login before adding your answer.

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