This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bedgraph to bed file conversion

Hi I am using a GEO dataset with Chip Seq experiments and it has an uploaded bedgraph file and since I need to use bed files for my analysis, is there a way to convert a bedgrpah to bed , also I don't quite understand the difference between both.

bedgraph bed

1 answer

Bedgraph is BED-like, but puts the score data into the fourth column and often contains headers.

To convert to BED, strip out the headers with grep and put in a dummy ID value with awk:

$ grep -Ev '^(browser|track|#)' myData.bedgraph \
    | awk ' \
​          BEGIN { OFS = "\t"; } \
          { \
              print $1, $2, $3, "id-"NR, $4; \ 
          } \
    ' - \
    > myData.bed

The five-column BED data now follow the convention of putting the ID into the fourth column, and the score value into the fifth column.

Log in to answer this question.