Hello, I am trying to merge and average three BedGraph files using the following code on terminal: bedtools unionbedg -i file1.bedgraph file2.bedgraph file3.bedgraph | awk 'OFS="/t" {sum=0; for (col=4; col<=NF; col++) sum += $col; print $1, $2, $3, sum/(NF-4+1); }' > averaged_file.bedgraph
I get the following error message:
bedtools: src/unionBedGraphs/unionBedGraphs.cpp:99: CHRPOS UnionBedGraphs::ConsumeNextCoordinate(): Assertion `!queue.empty()' failed.
Aborted (core dumped)
I have tried to sort the files using
sort -c -k1,1 -k2,2n <file.bedgraph>
But I get the following error message:
sort: file1.bedgraph:2: disorder: . -1 -1 -1
The head of my BedGraph files (image below) looks like this, so it appears to be in tab-delimited format:
Any advice on why this is failing and possible solutions will be really appreciated! Thanks.
Try deeptools it has many tools for
bedGraph
andbigWig
files.Hi, thanks for the suggestion! Based on deeptools documentation, it looks like multiBigwigSummary might be the one for me:
but it gives a compressed numpy array output (.npz). Do you know whether it's possible to convert .npz to other formats, such as .bg, .bed, or .bw? I'm struggling to even find exactly what data ends up in this .npz file, so I can't figure out a way to convert it to other file types. Thanks again!
It seems that my comment was misleading. There is
--outRawCounts
option but it's output is tab-delimited, I have not tested it. I don't know if it's possible to convertnpz
to other formats. I used it to plotting. There is bigwigCompare command which have--operation
option and it can bemean
but it works only for two files.Consult this post , it seems that
wiggletools
averageswig
files. So you can convertbedGraph
tobigWig
and after averaging makebedGraph
. There are tools indeeptools
and kentutils which can be helpful.Thanks very much, I also found this post yesterday and it seems it might be just the thing. Thanks again for your help!
you're not sorting anything here.
-c
is just for checking the file is already sorted.-1
is not a valid bed coordinate.Thank you, I thought it looked weird. These were in the bed file from which I generated the BedGraph -- do you have an idea of how they've arisen?
Also, thank you for pointing out the "-c" flag error above.