Question: How to determine the density and mean of features in specified intervals?
0
gravatar for Les Ander
3.8 years ago by
Les Ander110
United States
Les Ander110 wrote:

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 counting bed bedtools • 1.2k views
ADD COMMENTlink modified 3.8 years ago by Vincent Laufer1.0k • written 3.8 years ago by Les Ander110
0
gravatar for Vincent Laufer
3.8 years ago by
Vincent Laufer1.0k
United States
Vincent Laufer1.0k wrote:

#!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 COMMENTlink modified 3.8 years ago • written 3.8 years ago by Vincent Laufer1.0k

Thank you

ADD REPLYlink written 3.8 years ago by Les Ander110

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

VL

ADD REPLYlink written 3.8 years ago by Vincent Laufer1.0k
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: 1650 users visited in the last hour