Skip to content

Commit

Permalink
An informative message is now printed (rather than a stop action) if …
Browse files Browse the repository at this point in the history
…the Lifemap server cannot be reached. The vignette is also managed in this case.
  • Loading branch information
aursiber committed Jul 19, 2024
1 parent ea7cf55 commit 93f8e10
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
61 changes: 32 additions & 29 deletions R/build_Lifemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,37 @@
#' LM <- build_Lifemap(eukaryotes_80, "fr")
#' }
build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbose = TRUE) {

basemap <- match.arg(arg = basemap, choices = basemap)
if(is.null(df$taxid)) {
stop('The dataframe must at least contain a "taxid" column')
}
# create a new "environment" to store the full data
if(!exists("lifemap_basemap_envir", where = .GlobalEnv)) lifemap_basemap_envir <- new.env()

## SET DATASETS ASDRESSES
# getting the right URL depending on the basemap wanted
if(basemap == "ncbi") {
basemap_url <- "https://lifemap-ncbi.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "fr") {
basemap_url <- "https://lifemap-fr.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "base") {
basemap_url <- "https://lifemap.univ-lyon1.fr/data/lmdata.Rdata"
}
# else if(basemap == "virus") {
# basemap_url <- "https://virusmap.univ-lyon1.fr/data/lmdata.Rdata"
# }
else {
stop(sprintf('%s is not a working basemap, try c("base", "fr", "ncbi" or "virus")', basemap))
}

# download full data for chosen basemap
if(verbose) cat("Downloading basemap coordinates...\n")

# control to test if the url is valid
if(!url.exists(basemap_url)) stop ("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")

basemap <- match.arg(arg = basemap, choices = basemap)
if(is.null(df$taxid)) {
stop('The dataframe must at least contain a "taxid" column')
}
# create a new "environment" to store the full data
if(!exists("lifemap_basemap_envir", where = .GlobalEnv)) lifemap_basemap_envir <- new.env()

## SET DATASETS ASDRESSES
# getting the right URL depending on the basemap wanted
if(basemap == "ncbi") {
basemap_url <- "https://lifemap-ncbi.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "fr") {
basemap_url <- "https://lifemap-fr.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "base") {
basemap_url <- "https://lifemap.univ-lyon1.fr/data/lmdata.Rdata"
}
# else if(basemap == "virus") {
# basemap_url <- "https://virusmap.univ-lyon1.fr/data/lmdata.Rdata"
# }
else {
stop(sprintf('%s is not a working basemap, try c("base", "fr", "ncbi" or "virus")', basemap))
}

# download full data for chosen basemap
if(verbose) cat("Downloading basemap coordinates...\n")

# control to test if the url is valid
if(!url.exists(basemap_url)) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
} else {
load(url(basemap_url), envir = lifemap_basemap_envir)

# add LUCA
Expand Down Expand Up @@ -109,4 +111,5 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos
class(lm_obj) <- c("lifemap_obj", "list")

return(lm_obj)
}
}
11 changes: 7 additions & 4 deletions R/display_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ display_map <- function(df = NULL,basemap = c("fr","ncbi", "base","virus")) {
display="https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
}
url2check<-strsplit(display, "osm_tiles")[[1]][1]
if (!url.exists(url2check)) stop ("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
m <- leaflet::leaflet(df) |>
leaflet::addTiles(display, options = leaflet::providerTileOptions(minZoom = 5, maxZoom = 50))
return(m)
if (!url.exists(url2check)) {
message("The Lifemap server or some remote lifemap files cannot be reached. Please try again later.")
} else {
m <- leaflet::leaflet(df) |>
leaflet::addTiles(display, options = leaflet::providerTileOptions(minZoom = 5, maxZoom = 50))
return(m)
}
}
5 changes: 3 additions & 2 deletions vignettes/runLifemapR.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ require("LifemapR")
The very first step to use this package is to have a dataframe containing at least a ```taxid``` column containing NCBI format TaxIds. This dataframe can also contain other data that you might want to visualise.

```{r echo = FALSE, results=FALSE, warning=FALSE}
require("LifemapR")
require("LifemapR", quietly = TRUE)
data(eukaryotes_1000)
LM_eukaryotes <- build_Lifemap(eukaryotes_1000, "ncbi")
```

```{r echo = FALSE}
LM_eukaryotes$df[6:10,1:5]
if(is.lifemap_obj(LM_eukaryotes))
LM_eukaryotes$df[6:10,1:5]
```

You can then transform this dataframe into a format suitable for the visualisation functions of the package with the ```build_Lifemap``` function.\
Expand Down

0 comments on commit 93f8e10

Please sign in to comment.