freestatman / ideogRam

R htmlwidget package for ideogram.js
https://freestatman.github.io/ideogRam/
16 stars 4 forks source link

Issue with add_track() #16

Open wxiang-us opened 3 years ago

wxiang-us commented 3 years ago

Firstly, thanks very much for this nice shiny tool, very useful!

I was trying to create a shiny app showing karyotype with certain annotated region highlight, but got error message: "Error: all(sapply(dots, function(x) is(x, "GRanges"))) is not TRUE" Seems the error is due to code of the add_track() function

{ stopifnot(inherits(ideo, "ideogRam")) dots <- list(...) stopifnot(all(sapply(dots, function(x) is(x, "GRanges")))) ideoraw(ideo)$annotations <- c(ideoraw(ideo)[["annotations"]], dots) ideo }

This stopifnot(all(sapply(dots, function(x) is(x, "GRanges")))) is not used in the ideogram.js; could you please let me know what's the possible reason of this error?

Btw, the example page showing ideogRam usage examples is gone, maybe due to updating issue? Could you re upload the example code?

Appreciate your help!

Below is code for my little test shiny app where the error showed up:

library(shiny) library(ideogRam) server <- function(input, output) { output$ideo_01 <- renderIdeogRam({ chromosome <- input$chromosome organism <- input$organism orientation <- input$orientation if (orientation == "default") orientation <- NULL

barWidth <- as.numeric(input$barWidth)
chrHeight <- as.numeric(input$chrHeight)
chrMargin <- as.numeric(input$chrMargin)
chrWidth <- as.numeric(input$chrWidth)
ploidy <- input$ploidy
rows <- input$rows
sex <- input$sex
rotatable <- as.logical(input$rotatable)
showBandLabels <- as.logical(input$showBandLabels)
showChromosomeLabels <- as.logical(input$showChromosomeLabels)
showAnnotTooltip <- as.logical(input$showAnnotTooltip)
showFullyBanded <- as.logical(input$showFullyBanded)
showNonNuclearChromosomes <- as.logical(input$showNonNuclearChromosomes)

ten_virtual_cnvs <- ideogRam:::sample_10_virtual_cnvs
ideogRam(organism = "human", chromosome = chromosome, sex = sex, width = '50%', 
         annotationsLayout = "overlay", 
         orientation = "horizontal")  %>% 
         add_track(ten_virtual_cnvs)    

}) }

ui <- shinyUI(fluidPage( titlePanel("IdeogRam test out of CCN"), sidebarPanel( width = 4, textInput("organism", label = "Organism", value = "human", placeholder = "Organism's name or organism's NCBI Taxonomy ID"), textInput("chromosome", label = "Chromosome", value = "", placeholder = "Default showing all chromosomes"), selectInput("orientation", label = "Orientation", choices = c("default", "horizontal", "vertical")),

numericInput("barWidth", label = "barWidth", value = 3, min = 1, max = 10),
numericInput("chrHeight", label = "chrHeight", value = 400, min = 10, max = 1000, step = 10),
numericInput("chrMargin", label = "chrMargin", value = 10, min = 0, max = 100, step = 1),
numericInput("chrWidth", label = "chrWidth", value = 10, min = 0, max = 100, step = 1),

numericInput("ploidy", label = "Ploidy", value = 1, min = 1, max = 8, step = 1),
numericInput("rows", label = "rows", value = 1, min = 1, max = 5, step = 1),
selectInput("sex", label = "sex", choices = c("male", "female")),
checkboxInput("rotatable", label = "rotatable", value = TRUE),
checkboxInput("showBandLabels", label = "showBandLabels", value = FALSE),
checkboxInput("showChromosomeLabels", label = "showChromosomeLabels", value = TRUE),
checkboxInput("showAnnotTooltip", label = "showAnnotTooltip", value = TRUE),
checkboxInput("showFullyBanded", label = "showFullyBanded", value = TRUE),
checkboxInput("showNonNuclearChromosomes", label = "showNonNuclearChromosomes", value = FALSE)

), mainPanel( ideogRamOutput("ideo_01") ) )) runApp(list(ui = ui, server = server))