Skip to content

Commit

Permalink
update interface
Browse files Browse the repository at this point in the history
  • Loading branch information
venyao committed Aug 17, 2021
1 parent 1b770a3 commit 9cb82a4
Show file tree
Hide file tree
Showing 14 changed files with 904 additions and 738 deletions.
30 changes: 15 additions & 15 deletions GBrowser.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ GBrowser <- function(chr="chr07", start=29616705, end=29629223, accession=NULL,
snpeff.reg.3 <- snpeff.reg.3[snpeff.reg.3$tag %in% mutType, , drop=FALSE]
}

p1 <- ggplot(data=snpeff.reg.3) + geom_point(aes(x=pos, y=yr, color=tag, text=info, fill=tag), size=0.8, pch=25)
p1 <- ggplot2::ggplot(data=snpeff.reg.3) + ggplot2::geom_point(ggplot2::aes(x=pos, y=yr, color=tag, text=info, fill=tag), size=0.8, pch=25)


gff$id <- gsub(":.+", "", gff$id)
Expand Down Expand Up @@ -128,7 +128,7 @@ GBrowser <- function(chr="chr07", start=29616705, end=29629223, accession=NULL,
})
plot.nm <- do.call(rbind, plot.nm.lst)
if (!is.null(plot.nm) && nrow(plot.nm)>0) {
p1 <- p1 + geom_rect(aes(xmin=start, xmax=end, ymin=ymin, ymax=ymax),
p1 <- p1 + ggplot2::geom_rect(ggplot2::aes(xmin=start, xmax=end, ymin=ymin, ymax=ymax),
color="grey30", fill="grey30", data=plot.nm)
}

Expand All @@ -145,7 +145,7 @@ GBrowser <- function(chr="chr07", start=29616705, end=29629223, accession=NULL,
})
plot.mrna <- do.call(rbind, plot.mrna.lst)
if (!is.null(plot.mrna) && nrow(plot.mrna)>0) {
p1 <- p1 + geom_rect(aes(xmin=start, xmax=end, ymin=y+0.118, ymax=y+0.122),
p1 <- p1 + ggplot2::geom_rect(ggplot2::aes(xmin=start, xmax=end, ymin=y+0.118, ymax=y+0.122),
color="grey30", fill="grey30", data=plot.mrna)
}

Expand Down Expand Up @@ -191,24 +191,24 @@ GBrowser <- function(chr="chr07", start=29616705, end=29629223, accession=NULL,
})
plot.tail <- do.call(rbind, plot.tail.lst)
if (!is.null(plot.tail) && nrow(plot.tail)>0) {
p1 <- p1 + geom_polygon(aes(x=xx, y=yy, group=pare), color="grey30", fill="grey30",
p1 <- p1 + ggplot2::geom_polygon(ggplot2::aes(x=xx, y=yy, group=pare), color="grey30", fill="grey30",
data=plot.tail)
}


p1 <- p1 + scale_y_continuous("", breaks=NULL)
p1 <- p1 + theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank()) +
theme(panel.background=element_rect(fill="white",colour="white"))
p1 <- p1 + xlab("Chromosome position")
p1 <- p1 + guides(color=guide_legend(title=NULL))
p1 <- p1 + ggplot2::scale_y_continuous("", breaks=NULL)
p1 <- p1 + ggplot2::theme(panel.grid.major=ggplot2::element_blank(), panel.grid.minor=ggplot2::element_blank()) +
ggplot2::theme(panel.background=ggplot2::element_rect(fill="white",colour="white"))
p1 <- p1 + ggplot2::xlab("Chromosome position")
p1 <- p1 + ggplot2::guides(color=ggplot2::guide_legend(title=NULL))

p1 <- p1 + guides(fill=FALSE)
p1 <- p1 + ggplot2::guides(fill=FALSE)

p3 <- p1 + theme(axis.ticks.y = element_blank(), axis.text.y = element_blank(),
axis.line.y = element_blank())
p3 <- ggplotly(p3, tooltip = c("pos", "info"))
p3 <- p1 + ggplot2::theme(axis.ticks.y = ggplot2::element_blank(), axis.text.y = ggplot2::element_blank(),
axis.line.y = ggplot2::element_blank())
p3 <- plotly::ggplotly(p3, tooltip = c("pos", "info"))

p3 <- p3 %>% layout(
p3 <- p3 %>% plotly::layout(
title = "",
xaxis = list(
rangeselector = list(),
Expand All @@ -233,7 +233,7 @@ GBrowser <- function(chr="chr07", start=29616705, end=29629223, accession=NULL,
}
}

p4 <- onRender(p3, "
p4 <- htmlwidgets::onRender(p3, "
function(el, x) {
el.on('plotly_click', function(d) {
var url = d.points[0].customdata;
Expand Down
27 changes: 18 additions & 9 deletions Global.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
options(warn=-1)

# library(IRanges)
library(plotly)
library(LDheatmap)
library(chopsticks)
# library(plotly)
# library(LDheatmap)
# library(chopsticks)
# library(foreach)
# library(ape)
# library(pegas)
library(plyr)
library(dplyr)
# library(plyr)
library(dplyr)
# library(ggmap)
library(tidyr)
library(gridExtra)
# library(tidyr)
# library(gridExtra)
# library(ggtree)
library(grid)
# library(grid)
library(snpStats)
library(htmlwidgets)
# library(htmlwidgets)
# library(shinycssloaders)
# library(shinysky)
# library(shinyWidgets)
# library(shinythemes)
library(shinyBS)

source("fetchSnp.R")
source("ld.heatmap.R")
Expand Down Expand Up @@ -52,3 +54,10 @@ chrInfo <- read.table("./data/chrInfo.txt", head=T, as.is=T, sep="\t")

acc.tree <- read.table("./data/acc.tree.txt",
head=T, as.is=T, sep="\t", row.names = 1)

footerTagList <- list(
tags$footer(id = "myFooter",
shiny::includeHTML("www/footer.html")
)
)

4 changes: 2 additions & 2 deletions chooser.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ chooserInput <- function(inputId, leftLabel, rightLabel, leftChoices, rightChoic
)),
div(id=inputId, class="chooser",
div(class="chooser-container chooser-left-container",
tags$select(class="left", size=size, multiple=multiple, leftChoices, style="width:185px;background:gray")
tags$select(class="left", size=size, multiple=multiple, leftChoices, style="width:185px;background:gray50")
),
div(class="chooser-container chooser-center-container",
icon("arrow-circle-o-right", "right-arrow fa-3x"),
tags$br(),
icon("arrow-circle-o-left", "left-arrow fa-3x")
),
div(class="chooser-container chooser-right-container",
tags$select(class="right", size=size, multiple=multiple, rightChoices, style="width:185px;background:gray")
tags$select(class="right", size=size, multiple=multiple, rightChoices, style="width:185px;background:gray50")
)
)
)
Expand Down
18 changes: 9 additions & 9 deletions geneStru.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ geneStru <- function(chr="chr09", start=37800, end=46400){
return(dat.mrna)
})
plot.mrna <- do.call(rbind, plot.mrna.lst)
p1 <- ggplot(plot.mrna) + geom_rect(aes(xmin=start, xmax=end, ymin=y+0.118, ymax=y+0.122,
p1 <- ggplot2::ggplot(plot.mrna) + ggplot2::geom_rect(ggplot2::aes(xmin=start, xmax=end, ymin=y+0.118, ymax=y+0.122,
text=anno),
color="grey30", fill="grey30")

Expand All @@ -69,7 +69,7 @@ geneStru <- function(chr="chr09", start=37800, end=46400){
})
plot.nm <- do.call(rbind, plot.nm.lst)
if (nrow(plot.nm)>0) {
p1 <- p1 + geom_rect(aes(xmin=start, xmax=end, ymin=ymin, ymax=ymax, text=anno),
p1 <- p1 + ggplot2::geom_rect(ggplot2::aes(xmin=start, xmax=end, ymin=ymin, ymax=ymax, text=anno),
color="grey30", fill="grey30", data=plot.nm)
}

Expand Down Expand Up @@ -111,17 +111,17 @@ geneStru <- function(chr="chr09", start=37800, end=46400){
return(dat.tail)
})
plot.tail <- do.call(rbind, plot.tail.lst)
p1 <- p1 + geom_polygon(aes(x=xx, y=yy, group=pare), color="grey30", fill="grey30",
p1 <- p1 + ggplot2::geom_polygon(ggplot2::aes(x=xx, y=yy, group=pare), color="grey30", fill="grey30",
data=plot.tail)

snp.pos.df <- data.frame(x=snp.code.pos, ymin=1.23, ymax=1.25, stringsAsFactors = FALSE)
p1 <- p1 + geom_linerange(aes(x=x, ymin=ymin, ymax=ymax), data=snp.pos.df)
p1 <- p1 + geom_segment(aes(x=min(snp.code.pos), xend=max(snp.code.pos), y=1.25, yend=1.25))
p1 <- p1 + ggplot2::geom_linerange(ggplot2::aes(x=x, ymin=ymin, ymax=ymax), data=snp.pos.df)
p1 <- p1 + ggplot2::geom_segment(ggplot2::aes(x=min(snp.code.pos), xend=max(snp.code.pos), y=1.25, yend=1.25))

p1 <- p1 + scale_y_continuous("", breaks=NULL)
p1 <- p1 + theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank()) +
theme(panel.background=element_rect(fill="white",colour="white"))
p1 <- p1 + scale_x_continuous("", breaks=NULL)
p1 <- p1 + ggplot2::scale_y_continuous("", breaks=NULL)
p1 <- p1 + ggplot2::theme(panel.grid.major=ggplot2::element_blank(),panel.grid.minor=ggplot2::element_blank()) +
ggplot2::theme(panel.background=ggplot2::element_rect(fill="white",colour="white"))
p1 <- p1 + ggplot2::scale_x_continuous("", breaks=NULL)

return(p1)
}
Expand Down
6 changes: 3 additions & 3 deletions hapGeo.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ hapGeo <- function(haplotype=NULL) {
showcountries = TRUE,
showsubunits = TRUE,
landcolor = "white",
oceancolor = toRGB("gray90"),
oceancolor = plotly::toRGB("gray90"),
subunitwidth = 1,
countrywidth = 0.5,
subunitcolor = "blue",
countrycolor = "gray85"
)

plotly::plot_geo(dat, lat = ~Latitude, lon = ~Longitude, color = ~hap) %>%
add_markers(
plotly::add_markers(
hovertext = ~text
) %>% layout(title = 'Geographic distribution of rice accessions with different haplotypes', geo = g)
) %>% plotly::layout(title = 'Geographic distribution of rice accessions with different haplotypes', geo = g)

}

6 changes: 3 additions & 3 deletions hapGeoStatic.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ hapGeoStatic <- function(haplotype=NULL) {

load("./data/worldmap.RData")

mp <- mp + geom_point(aes(x=Longitude, y=Latitude, color=hap), size=0.5, data=dat) +
scale_x_continuous("", breaks=NULL) + scale_y_continuous("", breaks=NULL)
mp <- mp + guides(color=guide_legend(title=NULL))
mp <- mp + ggplot2::geom_point(ggplot2::aes(x=Longitude, y=Latitude, color=hap), size=0.5, data=dat) +
ggplot2::scale_x_continuous("", breaks=NULL) + ggplot2::scale_y_continuous("", breaks=NULL)
mp <- mp + ggplot2::guides(color=ggplot2::guide_legend(title=NULL))
mp
}

12 changes: 6 additions & 6 deletions ld.heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,21 @@ ld.heatmap <- function(chr="chr09", start=37800, end=46400, snp.pos=c(1),
dat.snp.mat <- as(dat, "SnpMatrix")

if (gene) {
ll <- LDheatmap(dat.snp.mat, snp.code.pos,
ll <- LDheatmap::LDheatmap(dat.snp.mat, snp.code.pos,
flip=TRUE, title=NULL, ...)

p1 <- geneStru(chr=chr, start=start, end=end)

plot.new()
llQplot2 <- LDheatmap.addGrob(ll, rectGrob(gp=gpar(col="white")), height=.3)
pushViewport(viewport(x=0.483, y=ld.y, width=ld.w, height=.1))
llQplot2 <- LDheatmap::LDheatmap.addGrob(ll, grid::rectGrob(gp=grid::gpar(col="white")), height=.3)
grid::pushViewport(grid::viewport(x=0.483, y=ld.y, width=ld.w, height=.1))

grid.draw(ggplotGrob(p1))
grid::grid.draw(ggplot2::ggplotGrob(p1))
} else {
if (flip) {
LDheatmap(dat.snp.mat, snp.code.pos, flip=TRUE, title=NULL, ...)
LDheatmap::LDheatmap(dat.snp.mat, snp.code.pos, flip=TRUE, title=NULL, ...)
} else {
LDheatmap(dat.snp.mat, snp.code.pos, flip=FALSE, SNP.name = colnames(dat)[snp.pos], title=NULL, ...)
LDheatmap::LDheatmap(dat.snp.mat, snp.code.pos, flip=FALSE, SNP.name = colnames(dat)[snp.pos], title=NULL, ...)
}
}

Expand Down
32 changes: 16 additions & 16 deletions nucDiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ nucDiv <- function(chr="chr07", nuc.start=2800000, nuc.end=2900000, step=10,
div.group.df.1 <- div.group.df[, c("pos", groups)]
div.group.df.2 <- div.group.df[, c("pos", numerator, denominator)]

div.group.df.1.long <- gather(div.group.df.1, group, diversity, -pos)
div.group.df.2.long <- gather(div.group.df.2, group, diversity, -pos)
div.group.df.1.long <- tidyr::gather(div.group.df.1, group, diversity, -pos)
div.group.df.2.long <- tidyr::gather(div.group.df.2, group, diversity, -pos)

nuc.chr <- substr(chr, 4, 5)
nuc.gene.info <- gene.info
Expand All @@ -61,28 +61,28 @@ nucDiv <- function(chr="chr07", nuc.start=2800000, nuc.end=2900000, step=10,
nuc.gene.info$start>=as.numeric(nuc.start) &
nuc.gene.info$end<=as.numeric(nuc.end), ]

p1 <- ggplot(div.group.df.1.long) + geom_line(aes(x=pos, y=diversity, color=group))
p1 <- p1 + xlab("") + ylab("Nucleotide diversity")
p1 <- p1 + theme_classic() + ylim(-0.14, NA)
p1 <- p1 + theme(legend.title = element_blank())
p1 <- p1 + theme(legend.position="top")
p1 <- ggplot2::ggplot(div.group.df.1.long) + ggplot2::geom_line(ggplot2::aes(x=pos, y=diversity, color=group))
p1 <- p1 + ggplot2::xlab("") + ggplot2::ylab("Nucleotide diversity")
p1 <- p1 + ggplot2::theme_classic() + ggplot2::ylim(-0.14, NA)
p1 <- p1 + ggplot2::theme(legend.title = ggplot2::element_blank())
p1 <- p1 + ggplot2::theme(legend.position="top")

if (nrow(nuc.gene.info)>=1) {
p1 <- p1 + geom_rect(aes(xmin=start, xmax=end, ymin=-0.05, ymax=-0.07), color="grey40", data=nuc.gene.info)
p1 <- p1 + geom_text(aes(x=(start+end)/2, y=-0.12, label=id), angle=50, size=2.5, data=nuc.gene.info)
p1 <- p1 + ggplot2::geom_rect(ggplot2::aes(xmin=start, xmax=end, ymin=-0.05, ymax=-0.07), color="grey40", data=nuc.gene.info)
p1 <- p1 + ggplot2::geom_text(ggplot2::aes(x=(start+end)/2, y=-0.12, label=id), angle=50, size=2.5, data=nuc.gene.info)
}

p1 <- p1 + theme(axis.ticks.x = element_blank(), axis.text.x = element_blank(),
axis.line.x = element_blank())
p1 <- p1 + ggplot2::theme(axis.ticks.x = ggplot2::element_blank(), axis.text.x = ggplot2::element_blank(),
axis.line.x = ggplot2::element_blank())

div.group.df.2$value <- div.group.df.2[,numerator]/div.group.df.2[,denominator]

p2 <- ggplot(div.group.df.2) + geom_line(aes(x=pos, y=value))
p2 <- p2 + xlab("genomic position") + ylab(paste0(numerator, "/", denominator))
p2 <- p2 + theme_classic()
p2 <- ggplot2::ggplot(div.group.df.2) + ggplot2::geom_line(ggplot2::aes(x=pos, y=value))
p2 <- p2 + ggplot2::xlab("genomic position") + ggplot2::ylab(paste0(numerator, "/", denominator))
p2 <- p2 + ggplot2::theme_classic()

gp1 <- ggplotGrob(p1)
gp2 <- ggplotGrob(p2)
gp1 <- ggplot2::ggplotGrob(p1)
gp2 <- ggplot2::ggplotGrob(p2)
maxWidth = grid::unit.pmax(gp1$widths[2:5], gp2$widths[2:5])
gp1$widths[2:5] <- as.list(maxWidth)
gp2$widths[2:5] <- as.list(maxWidth)
Expand Down
Loading

0 comments on commit 9cb82a4

Please sign in to comment.