Color label of rainfall plot drawn by KaryoploteR
1
2
Entering edit mode
3.3 years ago
FL512 ▴ 20

Thanks to the amazing package of KaryoploteR and a great tutorial website, I was able to make a rainfall plot. https://bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html

However, one thing that I am suffering from making a perfect rainfall plot is color label is missing. I would like to know and visualize what color is what like C>A is yellow, C>G is red for example. Tutorial website states to ask a question to Biostars, I am posting my question here.

Thank you very much in advance.

plot KaryoploteR Rainfall R • 2.0k views
ADD COMMENT
3
Entering edit mode
3.3 years ago

You can use the standard legend() command as outlined in this issue here: https://support.bioconductor.org/p/124328/

Minimal example based on https://bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html :

library(karyoploteR)


somatic.mutations <- read.table(file="ftp://ftp.sanger.ac.uk/pub/cancer/AlexandrovEtAl/somatic_mutation_data/Pancreas/Pancreas_raw_mutations_data.txt", header=FALSE, sep="\t", stringsAsFactors=FALSE)
somatic.mutations <- setNames(somatic.mutations, c("sample", "mut.type", "chr", "start", "end", "ref", "alt", "origin"))

somatic.mutations <- split(somatic.mutations, somatic.mutations$sample)
sm <- somatic.mutations[["APGI_1992"]]
sm.gr <- toGRanges(sm[,c("chr", "start", "end", "mut.type", "ref", "alt")])
seqlevelsStyle(sm.gr) <- "UCSC"

variant.colors <- getVariantsColors(sm.gr$ref, sm.gr$alt)
kp <- plotKaryotype(plot.type=4)
kpPlotRainfall(kp, data = sm.gr, col=variant.colors)
uniq_cols <- variant.colors[!duplicated(variant.colors)]
legend(x = "bottomright", fill=uniq_cols, legend=names(uniq_cols))

Now you can customise the call to legend() in any way you like.

Looks like this:example rainbow plot

ADD COMMENT
0
Entering edit mode

Thank you very much for your response Phillip. Also, thank you for providing the reference website. It helps a lot. Now I can see the figure legend on my plot.

Thank you again!

ADD REPLY
0
Entering edit mode

Good luck :)

ADD REPLY
0
Entering edit mode

By the way, it is weird to me but I see 7 colors in my plot. Green (T>G), black (C>G), purple (T>A), red (C>T), yellow (T>C), blue (C>A) and gray (blank, no information)

Has anyone been having a same problem with color legend? How come it happens since I only extracted columns of "Chr", "Start", "End", "Mut_type", "REF", "ALT" from loaded Txt file.

ADD REPLY
0
Entering edit mode

Uh,,

I removed all the INDEL from my samples and there are no more gray dot shown in the rainfall plot, which I was expected. However, still gray box exist in the figure legend.

Anyway, the source file downloaded from the website: https://bernatgel.github.io/karyoploter_tutorial//Examples/Rainfall/Rainfall.html has no problem at all for the plot, indicating this is something wrong with my sample file.

I will figure it out. Thank you.

ADD REPLY
1
Entering edit mode

Good work! I reckon uniq_cols still has the color-less indel in it.

This is what mine looks like:

> uniq_cols
      T>C       C>T       C>A       C>G       T>G       T>A 
"#fbe800" "#e40611" "#4c64ae" "#000000" "#6eb529" "#bf4a96"

You might have another entry in there with ' ' or something like that. To remove:

uniq_cols[-c(1)]

or whatever the position of the empty gray is in your named vector uniq_cols.

ADD REPLY

Login before adding your answer.

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