Make a BedGraph file
2
0
Entering edit mode
16 months ago

I have a simple BED file displays repetitive elements localization (this file was obtained using RepeatMasker).

Here are the first few rows::

2L  840 882 Simple_repeat
2L  2763    2796    Simple_repeat
2L  3409    3498    DNA/Helitron
2L  5405    5432    Simple_repeat
2L  8844    9132    LINE/unknown

Now, I would like to create a BedGraph file that displays the coverage of repetitive elements per selected bin. Let's assume the bin size is 3000. The desired file should look like this::

2L      1       3001    0.025
2L      3001    6001    0.0387

where 0.025 is calculated as ((882-840)+(2796-2763))/3000.

I can write a Python code to accomplish this, but I believe there might be ready-made tools available for this task. Could you assist me? Thank you in advance.

BedGraph RepeatMasker BED • 1.1k views
ADD COMMENT
1
Entering edit mode
16 months ago
bhumm ▴ 170

Bedtools window piped into genomecov?

https://bedtools.readthedocs.io/en/latest/content/tools/window.html

https://bedtools.readthedocs.io/en/latest/content/tools/genomecov.html

Or perhaps genomecov paired with awk? I'm thinking something like:

genomeCoverageBed -d -bg | awk 'begin{sum=0;} {sum=sum+1;if(NR%3000==0){print sum;sum=0;}}'

Disclaimer: I have not tested either of these strategies

ADD COMMENT
1
Entering edit mode
16 months ago
rfran010 ★ 1.3k

I would suggest bedtools makewindows to generate your 3,000bp bins then bedtools coverage to generate fraction of repeats over your windows. Maybe:

bedtools makewindows -w 3000 -g chrom_sizes > windows.bed
bedtools coverage -a windows.bed -b repeats.bed > coverage.bed
cut -f1-3,7  coverage.bed > coverage.bg

the cut command is because bedtools coverage outputs 4 extra columns, with the forth being "The fraction of bases in A that had non-zero coverage." If you use this command or otherwise have a minimal bed, columns 1-3 & 7 will produce your bedgraph. Otherwise, you will need to adjust column number of the fraction.

ADD COMMENT
1
Entering edit mode

It works, thank you!

ADD REPLY

Login before adding your answer.

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