This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Color Bed Track Annotations by Name

I am trying to upload a custom BED track to the UCSC Genome Browser. This track contains annotations from ChromHMM's 15-state model, i.e.

chr10   0       119600  15_Quies
chr10   119600  120400  1_TssA
chr10   120400  136200  14_ReprPCWk
chr10   136200  139400  15_Quies
chr10   139400  145200  9_Het
chr10   145200  162800  15_Quies
chr10   162800  165000  9_Het
chr10   165000  176200  15_Quies
chr10   176200  176600  7_Enh
chr10   176600  177000  5_TxWk

What I want to do is to visualize this track with a different color for each annotation. However, the closest track parameter I can find is itemRgb = On, and to use that I would need to manually add a separate color for each annotation in the BED file. Is there an easier way for me to do this, or if not, is there a one-line command I can use to add in the RGB values?

bed ucsc chromhmm custom tracks

1 answer

using awk to insert tge missing BED columns until the RGB column:

awk '{c="255,0,0";if($4=="15_Quies") {c="0,255,0";} else if($4=="1_TssA") {c="0,0,255";} printf("%s\t0\t.\t%s\t%s\t%s\n",$0,$2,$3,c);}' your.bed

Thank you! This solution works well and is very helpful.

Log in to answer this question.