Skip to content

Commit

Permalink
Just spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aursiber committed Jul 31, 2024
1 parent 42a5a84 commit 563a6d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
36 changes: 22 additions & 14 deletions R/build_Lifemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@
build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbose = TRUE) {

basemap <- match.arg(arg = basemap, choices = basemap)
if(is.null(df$taxid)) {
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()
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") {
if (basemap == "ncbi") {
basemap_url <- "https://lifemap-ncbi.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "fr") {
} else if (basemap == "fr") {
basemap_url <- "https://lifemap-fr.univ-lyon1.fr/data/lmdata.Rdata"
} else if(basemap == "base") {
} else if (basemap == "base") {
basemap_url <- "https://lifemap.univ-lyon1.fr/data/lmdata.Rdata"
}
# else if(basemap == "virus") {
Expand All @@ -71,9 +73,11 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos
}
)

if(!is.na(y)) {
if (!is.na(y)) {
# download full data for chosen basemap
if(verbose) cat("Downloading basemap coordinates...\n")
if (verbose) {
cat("Downloading basemap coordinates...\n")
}
load(url(basemap_url), envir = lifemap_basemap_envir)

# add LUCA
Expand All @@ -82,17 +86,21 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos

# get info for unique taxids (then we work with df_distinct, not df anymore)
df_distinct <- dplyr::distinct(df, .data$taxid, .keep_all = TRUE)
if(nrow(df_distinct) != nrow(df)) {
warning(sprintf("%s duplicated TaxIDs were removed \n",nrow(df)-nrow(df_distinct)))
if (nrow(df_distinct) != nrow(df)) {
warning(sprintf("%s duplicated TaxIDs were removed \n", nrow(df) - nrow(df_distinct)))
}

# get data
if(verbose) cat("Getting info for requested taxids...\n")
if (verbose) {
cat("Getting info for requested taxids...\n")
}

# get index of requested taxids
indexes <- fastmatch::fmatch(df_distinct$taxid, lifemap_basemap_envir$DF$taxid)
if(sum(is.na(indexes)) > 0) {
warning(sprintf("%s TaxID(s) could not be found: %s \n",sum(is.na(indexes)), paste(df_distinct$taxid[is.na(indexes)], sep=",")))
if (sum(is.na(indexes)) > 0) {
warning(sprintf("%s TaxID(s) could not be found: %s \n",
sum(is.na(indexes)),
paste(df_distinct$taxid[is.na(indexes)], sep = ",")))
}

# create new df with only existing taxids
Expand All @@ -105,8 +113,8 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos
ANCESTORS <- lifemap_basemap_envir$DF[fastmatch::fmatch(real_ancestors, lifemap_basemap_envir$DF$taxid), ]

# add type
DATA0$type<-"requested"
ANCESTORS$type<-"ancestor"
DATA0$type <- "requested"
ANCESTORS$type <- "ancestor"
# bind all
DATA1 <- rbind(DATA0, ANCESTORS)

Expand Down
14 changes: 7 additions & 7 deletions R/display_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
#'
#' @examples
#' display_map()
display_map <- function(df = NULL, basemap = c("fr","ncbi", "base","virus")) {
display_map <- function(df = NULL, basemap = c("fr", "ncbi", "base", "virus")) {
basemap <- match.arg(basemap)
if (basemap == "fr"){
display="http://lifemap-fr.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
display <- "http://lifemap-fr.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
} else if (basemap == "ncbi"){
display="http://lifemap-ncbi.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
display <- "http://lifemap-ncbi.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
} else if (basemap == "base"){
display="http://lifemap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
display <- "http://lifemap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
} else if (basemap == "virus"){
display="https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
display <- "https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png"
}
url2check<-strsplit(display, "osm_tiles")[[1]][1]
url2check <- strsplit(display, "osm_tiles")[[1]][1]

m <- tryCatch({
leaflet::leaflet(df) |>
Expand All @@ -44,7 +44,7 @@ display_map <- function(df = NULL, basemap = c("fr","ncbi", "base","virus")) {
}
)

if(!all(is.na(m))) {
if (!all(is.na(m))) {
return(m)
} else {
return(NA)
Expand Down

0 comments on commit 563a6d1

Please sign in to comment.