myles-lewis/locuszoomr

graph range in locuszoomr

Closed this issue · 2 comments

Hello, I appreciate for this great tool.
I have several issues while I draw plots locuszoomr and arrange other plots with cowplot.

First, when I get recombination rate, it always return error.
Here is my code.

> loc <- locus(data = tb_1, seqname = 5, xrange = c(96207000, 96259000), flank = 1e5, ens_db = "EnsDb.Hsapiens.v75")
chromosome 5, position 96207000 to 96259000
186 SNPs/datapoints
> loc <- link_LD(loc, token = my_token)
Obtaining LD on 186 SNPs
LDlink server is working...
> tb_1$r2 <- loc$data$ld
> loc <- link_recomb(loc, genome = "hg19")
Retrieving recombination data from UCSC
Error in .local(object, ...) : tabular output format not available
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
[1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
[6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cowplot_1.1.1             EnsDb.Hsapiens.v75_2.99.0 ensembldb_2.10.2          AnnotationFilter_1.10.0   AnnotationHub_2.18.0     
[6] BiocFileCache_1.10.2      dbplyr_2.1.1              locuszoomr_0.2.1          GenomicFeatures_1.38.2    AnnotationDbi_1.48.0     
[11] Biobase_2.46.0            GenomicRanges_1.38.0      GenomeInfoDb_1.22.1       IRanges_2.20.2            S4Vectors_0.24.4         
[16] ggbio_1.34.0              ggplot2_3.5.0             BiocGenerics_0.32.0      

loaded via a namespace (and not attached):
[1] colorspace_2.0-2              ellipsis_0.3.2                biovizBase_1.34.1             htmlTable_2.4.1              
[5] XVector_0.26.0                base64enc_0.1-3               dichromat_2.0-0.1             rstudioapi_0.15.0            
[9] farver_2.1.0                  remotes_2.4.2.1               ggrepel_0.9.1                 bit64_4.0.5                  
[13] interactiveDisplayBase_1.24.0 fansi_0.5.0                   splines_3.6.3                 cachem_1.0.5                 
[17] knitr_1.45                    jsonlite_1.8.8                Formula_1.2-5                 Rsamtools_2.2.3              
[21] cluster_2.1.4                 png_0.1-7                     graph_1.64.0                  shiny_1.6.0                  
[25] BiocManager_1.30.22           compiler_3.6.3                httr_1.4.7                    backports_1.2.1              
[29] assertthat_0.2.1              Matrix_1.5-1                  fastmap_1.1.0                 lazyeval_0.2.2               
[33] cli_3.6.2                     later_1.2.0                   htmltools_0.5.7               prettyunits_1.1.1            
[37] tools_3.6.3                   gtable_0.3.0                  glue_1.7.0                    GenomeInfoDbData_1.2.2       
[41] reshape2_1.4.4                dplyr_1.1.4                   rappdirs_0.3.3                Rcpp_1.0.7                   
[45] vctrs_0.6.5                   Biostrings_2.54.0             rtracklayer_1.46.0            xfun_0.42                    
[49] stringr_1.5.1                 mime_0.11                     lifecycle_1.0.4               XML_3.99-0.3                 
[53] zoo_1.8-9                     zlibbioc_1.32.0               scales_1.3.0                  gggrid_0.2-0                 
[57] BSgenome_1.54.0               VariantAnnotation_1.32.0      promises_1.2.0.1              hms_1.1.0                    
[61] ProtGenerics_1.18.0           SummarizedExperiment_1.16.1   RBGL_1.62.1                   LDlinkR_1.3.0                
[65] RColorBrewer_1.1-2            yaml_2.2.1                    curl_5.2.1                    memoise_2.0.1                
[69] gridExtra_2.3                 biomaRt_2.42.1                rpart_4.1.19                  latticeExtra_0.6-29          
[73] stringi_1.7.3                 RSQLite_2.3.1                 BiocVersion_3.10.1            checkmate_2.3.1              
[77] BiocParallel_1.20.1           rlang_1.1.3                   pkgconfig_2.0.3               matrixStats_0.59.0           
[81] bitops_1.0-7                  lattice_0.20-45               purrr_1.0.2                   GenomicAlignments_1.22.1     
[85] ggstats_0.5.1                 htmlwidgets_1.5.3             labeling_0.4.2                bit_4.0.4                    
[89] tidyselect_1.2.0              GGally_2.2.1                  plyr_1.8.6                    magrittr_2.0.3               
[93] R6_2.5.1                      generics_0.1.0                Hmisc_4.7-2                   DelayedArray_0.12.3          
[97] DBI_1.1.1                     pillar_1.9.0                  foreign_0.8-81                withr_3.0.0                  
[101] survival_3.5-5                RCurl_1.98-1.3                nnet_7.3-19                   tibble_3.2.1                 
[105] crayon_1.4.1                  utf8_1.2.1                    plotly_4.10.4                 OrganismDbi_1.28.0           
[109] jpeg_0.1-8.1                  progress_1.2.2                grid_3.6.3                    data.table_1.14.0            
[113] blob_1.2.1                    digest_0.6.34                 xtable_1.8-4                  httpuv_1.6.1                 
[117] tidyr_1.3.1                   openssl_2.1.1                 munsell_0.5.0                 viridisLite_0.4.0            
[121] askpass_1.1

How can I fix it? Can I get recombination rate from UCSC, and insert in the data to visualize?

Second, I'm trying to align regional plot from locuszoomr and gene model from ggbio by using cowplot. Aligning of y-axis was successful, but the ranges of x-axis didn't match. Is there any option to control xlim in ggplot version of locuszoomr?
Following codes were used to align the plots.

loc <- locus(
  data = tb,
  seqname = 5,
  xrange = c(96207000, 96259000),
  fix_window = 0,
  ens_db = "EnsDb.Hsapiens.v75"
)
p1 <- gg_scatter(loc)
p2 <- gg_genetracks(loc)
# load window
df <- read.table(
  "deletion_window.bed",
  sep = "\t",
  header = FALSE,
  stringsAsFactors = FALSE
)
bed <- sapply(
  split(df, df$V4),
  function(i) {
    GRanges(
      seqnames = i$V1,
      ranges = IRanges(
        start = i$V2,
        end = i$V3,
        names = i$V4
      )
    )
  }
)
# load gene model
txdb <- makeTxDbFromGFF(
  "gene_model.gtf",
  format = "gtf"
)
p3 <- autoplot(txdb, which = bed$gene)
plot_grid(p1, p2, p3@ggplot, ncol = 1, align = "v")

It's resulting plot.

plot_zoom_png

Hi cuppacuppa,

If you are using gg_scatter() you can alter the xlim by doing something like:

p1 <- gg_scatter(loc)
p1 <- p1 + xlim(96.2, 96.3)

This overwrites the axis limits in the ggplot2 object. You can do this to both the gg_scatter and gg_genetracks objects. Note the x axis is scaled by dividing by 1e6 to make the formatting of the numbers nicer.

Of the 3 arguments xrange, flank and window, xrange overwrites the others.

Alternatively once you generate loc you can force change the xrange numbers in loc$xrange. These are used to generate the x axis limits in both gg_scatter and gg_genetracks.

I've not encountered that error in link_recomb. Is it reproducible every time if you rerun it? link_recomb sometimes generates a server API error on occasions. Rerunning the same code can fix it. One other thing you could try is to zoom out of the region and see if it manages to download some recombination data over a wider area.

I will investigate further as well.

Bw, Myles

I tried that region with hg19 and link_recomb(). I didn't get an error and the plots have recombination lines. I wonder if this is another intermittent error from UCSC that relates to the rtracklayer package.