diff --git a/main.R b/main.R index 0c32a7e..6b70e73 100644 --- a/main.R +++ b/main.R @@ -1,4 +1,6 @@ -source("data.R") +library(shiny) -data <- load_data_cached("input") -print(data) \ No newline at end of file +source("server.R") +source("ui.R") + +runApp(shinyApp(ui, server)) \ No newline at end of file diff --git a/scatter_plot.R b/scatter_plot.R new file mode 100644 index 0000000..11ca41c --- /dev/null +++ b/scatter_plot.R @@ -0,0 +1,73 @@ +library(data.table) +library(ggplot2) + +#' Draw a scatter plot containing gene positions. +scatter_plot <- function(gene_ids, data) { + species <- data$species + setorder(species, median_distance) + + distances <- data$distances[geneid %in% gene_ids] + + plot <- ggplot() + + scale_x_continuous( + name = "Species", + breaks = seq_len(nrow(species)), + labels = species$label + ) + + scale_y_continuous(name = "Distance to telomeres [Mbp]") + + geom_line( + species, + mapping = aes( + x = as.numeric(rownames(species)), + y = median_distance / 1000000 + ) + ) + + colors <- rainbow(length(gene_ids)) + + for (i in seq_len(length(gene_ids))) { + gene_id <- gene_ids[i] + + gene_distances <- data.table( + index = as.numeric(rownames(species)), + distance = unlist(distances[geneid == gene_id, -1]) + ) + + plot <- plot + + geom_point( + gene_distances, + mapping = aes( + x = index, + y = distance / 1000000, + ), + color = colors[i] + ) + } + + plot + + # plot( + # species[, median_distance] / 1000000, + # type = "l", + # xaxt = "n", + # xlab = "", + # ylab = "Distance to telomere (Mbp)", + # bty = "n" + # ) + + # axis( + # 1, + # at = seq_len(nrow(species)), + # tick = FALSE, + # labels = FALSE + # ) + + # mtext( + # data$species[, label], + # side = 1, + # at = seq_len(nrow(species)), + # las = 2, + # # col = axis.labels.col, + # adj = 1 + # ) +} \ No newline at end of file diff --git a/server.R b/server.R new file mode 100644 index 0000000..47d4917 --- /dev/null +++ b/server.R @@ -0,0 +1,23 @@ +library(data.table) +library(DT) +library(shiny) + +source("data.R") +source("scatter_plot.R") + +data <- load_data_cached("input") + +server <- function(input, output) { + output$genes <- renderDT({ + datatable( + data$genes[, c("name", "chromosome")], + rownames = FALSE, + style = "bootstrap" + ) + }) + + output$scatter <- renderPlot({ + gene_ids <- data$genes[input$genes_rows_selected, id] + scatter_plot(gene_ids, data) + }) +} \ No newline at end of file diff --git a/ui.R b/ui.R new file mode 100644 index 0000000..472d91c --- /dev/null +++ b/ui.R @@ -0,0 +1,17 @@ +library(DT) +library(shiny) + +ui <- fluidPage( + titlePanel("TPE-OLD candidates"), + sidebarLayout( + position = "right", + sidebarPanel( + h3("Candidate selection"), + DTOutput("genes"), + width = 3 + ), + mainPanel( + plotOutput("scatter"), + ) + ) +) \ No newline at end of file