Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colour SNP points according to annotation2 rather than chromosome? #13

Open
sophiegresh opened this issue Jul 19, 2017 · 4 comments
Open
Assignees

Comments

@sophiegresh
Copy link

Hi Sahir,

First of all thanks for creating such a fantastic package! I've been trying and failing to edit some of the code in the package for a while now in order to recolour the SNP points according to another variable rather than chromosome number in the manhattan plots, and I was wondering whether you could help? I want to colour the SNPs according to geographical region (of which I have two) as I have multiple populations plotted on the same manhattan plot. When transforming my dataset into the manhattanr class I saved this region variable as the annotation2 so each SNP has either the region "Africa" or "MiddleEast" in the annotation2 column. So is there a way I can colour points according to annotation2 rather than chromosome?

Many Thanks,
Sophie

@sahirbhatnagar
Copy link
Owner

Thanks for your interest in this package. Several people have asked for this feature. I will try to implement it in a function.

for the time being, here is some code that should get you started:

library(manhattanly)
library(magrittr)

DT <- subset(HapMap, CHR %in% 1:3)
DT$region <- sample(c("Africa", "MiddleEast"), size = nrow(DT), replace = TRUE)

x <- manhattanr(DT, snp = "SNP", gene = "GENE", annotation1 = "region")

d <- x$data
pName <- x$pName
snpName <- x$snpName
geneName <- x$geneName
annotation1Name <- x$annotation1Name
annotation2Name <- x$annotation2Name
labs <- x$labs
xlabel <- x$xlabel
ticks <- x$ticks
nchr <- x$nchr
xmax = ceiling(max(d$pos) * 1.03)
xmin = floor(max(d$pos) * -0.03)

p <- plotly::plot_ly()
p %<>% plotly::layout(p, title = "Title", 
                        xaxis = list(title = "Chromosome", 
                        showgrid = FALSE, range = c(xmin, xmax), autotick = FALSE, 
                        tickmode = "array", tickvals = ticks, ticktext = labs, 
                        ticks = "outside"), yaxis = list(title = "-log10(p)"))

icol <- 1
for (i in unique(d$index)) {
  tmp <- d[d$index == unique(d$index)[i], ]
  TEXT <- paste(if (!is.na(snpName)) 
    paste0(snpName, ": ", tmp[[snpName]]), if (!is.na(geneName)) 
      paste0(geneName, ": ", tmp[[geneName]]), if (!is.na(annotation1Name)) 
        paste0(annotation1Name, ": ", tmp[[annotation1Name]]), 
    if (!is.na(annotation2Name)) 
      paste0(annotation2Name, ": ", tmp[[annotation2Name]]), 
    sep = "<br>")
  
  chromo <- unique(tmp[which(tmp$index == i), "CHR"])
  
  p %<>% add_markers(x = tmp$pos, y = tmp$logp, color = tmp$region, 
                       showlegend = F, text = TEXT, name = paste0("chr", chromo))
  
  icol = icol + 1
}
p

See the resulting plot here:

https://plot.ly/~sahirbhatnagar/146/title/

@sophiegresh
Copy link
Author

Thanks so much Sahir, I've managed to integrate that into the function code that I have and it's working beautifully!

@ghost
Copy link

ghost commented May 10, 2018

Hi Sahir,

Thanks for creating such a useful package. On a similar note, is it possible to highlight snps/genes in more than just one color? It seems like the current function only accepts a single color. It would be great if the function could be extended to highlight1, highlight2, as you did with annotate.

Thanks again for the contribution!

@vdejager
Copy link

Hi Sahir,
I would vote for highlighting in multiple colors as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants