Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2024.12.12 #445

Open
wants to merge 3 commits into
base: biomodelos
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wallace
Version: 2024.11.18
Date: 2024-11-18
Version: 2024.12.12
Date: 2024-12-12
Title: A Modular Platform for Reproducible Modeling of Species Niches
and Distributions
Description: The 'shiny' application Wallace is a modular platform for
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![R-CMD-check](https://github.com/wallaceEcoMod/wallace/workflows/R-CMD-check/badge.svg)](https://github.com/wallaceEcoMod/wallace/actions) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![CRAN version](http://www.r-pkg.org/badges/version/wallace)](https://CRAN.R-project.org/package=wallace) [![downloads](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange)](https://cranlogs.r-pkg.org:443/badges/grand-total/wallace?color=orange)

# Wallace (v2024.11.18)
# Wallace (v2024.12.12)
*Wallace* is a modular platform for reproducible modeling of species niches and distributions, written in R. The application guides users through a complete analysis, from the acquisition of data to visualizing model predictions on an interactive map, thus bundling complex workflows into a single, streamlined interface.

Developmental versions (such as this branch) can be downloaded from Github with the following R code.
Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/Rmd/text_about.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output: html_document
### **What is *Wallace*?**

<img src="logo.png" alt="logo" style="width: 150px; float:right; padding:10px;"/>
Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2024.09.18) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results.
Welcome to *Wallace*, a flexible application for reproducible ecological modeling, built for community expansion. The current version of *Wallace* (v2024.12.12) steps the user through a full niche/distribution modeling analysis, from data acquisition to visualizing results.

The application is written in `R` with the web app development package `shiny`. Please find the stable version of *Wallace* on <a href="https://CRAN.R-project.org/package=wallace" target="_blank">CRAN</a>, and the development version on <a href="https://github.com/wallaceEcoMod/wallace" target="_blank">Github</a>. We also maintain a *Wallace* <a href="https://wallaceecomod.github.io/" target="_blank">website</a> that has some basic info, links, and will be updated with tutorial materials in the near future.

Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/Rmd/text_intro_tab.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ output: html_document

#### WORKFLOW

*Wallace* (v2024.11.18) currently includes ten components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step.
*Wallace* (v2024.12.12) currently includes thirteen components, or steps of a possible workflow. Each component includes two or more modules, which are possible analyses for that step.

**Components:**

Expand Down
4 changes: 2 additions & 2 deletions inst/shiny/Rmd/text_team.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ output: html_document
<a href="https://andrepazv.github.io" target="_blank">Andrea Paz</a> (developer) received her PhD at CUNY Graduate Center and City College of New York, after which she was a Postdoctoral Researcher at the Crowther Lab in ETH Zürich. She is now an Assistant Professor at the Biological Sciences Department, University of Montréal.
<br>

<img src="img/daniel.jpeg" alt="dani" style="width: 100px;"/>

<img src="img/beth.png" alt="beth" style="width: 100px;"/>

<a href="https://bethgerstner.weebly.com/research.html" target="_blank">Beth E. Gerstner</a> (developer, Wallace Fellow) received her PhD from Michigan State University, is a NASA FINESST Award winner, and a Wallace fellow. She currently works for Map of Life at the Center for Biodiversity and Global Change at Yale University.
<br>

<img src="img/daniel.jpeg" alt="dani" style="width: 100px;"/>

<a href="https://www.amnh.org/research/staff-directory/daniel-lopez-lozano" target="_blank">Daniel López Lozano</a> (developer) is a Biodiversity Informatics Specialist at the American Museum of Natural History's Center for Biodiversity & Conservation.
<br>

Expand Down
2 changes: 1 addition & 1 deletion inst/shiny/Rmd/userReport_intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ knit_engines$set(asis = function(options) {
knitr::opts_chunk$set(message = FALSE, warning = FALSE, eval = FALSE)
```

Please find below the R code history from your *Wallace* v2024.11.18 session.
Please find below the R code history from your *Wallace* v2024.12.12 session.

You can reproduce your session results by running this R Markdown file in RStudio.

Expand Down
171 changes: 141 additions & 30 deletions inst/shiny/custom_modules/rep_biomodelos.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,72 +60,128 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
})

observeEvent(input$pushBiomod, {
if (is.null(spp[[curSp()]]$visualization$mapPred)) {
if (is.null(spp[[curSp()]]$occs)) {
#add warning
shinyalert::shinyalert(
"You need a map prediction built on Wallace in order to push payload to BioModelos. ",
"You need occurrence data loaded in order to push payload to BioModelos. ",
type = "error")
return()
} else {

if (spp[[bioSp()]]$rmm$data$occurrence$sources != "Biomodelos") {
shinyalert::shinyalert(
"You must submit a model built with occurrences from BioModelos. ",
"Your model may not be built with occurrences from BioModelos. ",
type = "error")
return()
}
if (is.null(spp[[bioSp()]]$biomodelos$prediction)) {
shinyalert::shinyalert(
"You need a map prediction built on Wallace before pushing to BioModelos. ",
type = "error")
return()
#return()
}
# if (is.null(spp[[bioSp()]]$biomodelos$prediction)) {
# shinyalert::shinyalert(
# "You need a map prediction built on Wallace before pushing to BioModelos. ",
# type = "error")
# # return()
# }

URL <- 'https://api-biomodelos.humboldt.org.co/v2/models'


### Create Manifest
manifest <- list(
edited_occurrences = paste0(bioSp(), '_occs.csv'),
raster_model_prediction = paste0(bioSp(), '_pred.tif'),
raster_model_threshold = paste0(bioSp(), '_thr.csv'),
edited_occurrences =
if (is.null(spp[[bioSp()]]$occData$occsOrig)) {
"No occurrences uploaded. "
} else {
paste0(bioSp(), '_occs.csv')
},
raster_model_prediction =
if (is.null(spp[[bioSp()]]$biomodelos$prediction)) {
"No prediction. "
} else {
paste0(bioSp(), '_pred.tif')
},
raster_model_threshold =
if (is.null(spp[[bioSp()]]$biomodelos$thrs)) {
"No threshold values. "
} else {
paste0(bioSp(), '_thr.csv')
},
raster_user_prediction =
if (is.null(spp[[bioSp()]]$biomodelos$mask$userSDM)) {
"No user-specified SDM. "
} else {
paste0(bioSp(), '_userSDM.tif')
},
raster_model_modified_expert =
if (is.null(spp[[bioSp()]]$biomodelos$predExpert)) {
"No model prediction modified by expert."
} else {
paste0(bioSp(), '_pred_expert.tif')
},
shape_file_expert =
if (is.null(spp[[bioSp()]]$mask$expertPoly)) {
if (is.null(spp[[bioSp()]]$mask$removePoly)) {
"No model prediction modified by expert."
} else {
paste0(bioSp(), '_expertPolygonsShp.zip')
paste0(bioSp(), '_expertPolygonShp.zip')
},
shape_file_extent = paste0(bioSp(), '_projectionExtentShp.zip'),
biomodelos_metadata = paste0(bioSp(), '_metadata.csv'),
model_metadata = paste0(bioSp(), '_rmms.csv'),
wallace_session = paste0(bioSp(), '_session.Rmd')
shape_file_extent =
if (is.null(spp[[bioSp()]]$procEnvs$bgExt)) {
"No background extent. "
} else {
paste0(bioSp(), '_bgExtentShp.zip')
},
userSDM_extent =
if (is.null(spp[[bioSp()]]$biomodelos$mask$userPolyExt)) {
"No userSDM background extent. "
} else {
paste0(bioSp(), '_userSDM_ExtentShp.zip')
},
biomodelos_metadata =
paste0(bioSp(), '_metadata.csv'),
model_metadata =
paste0(bioSp(), '_rmms.csv'),
wallace_session =
paste0(bioSp(), '_session.Rmd')
# to add something else to the manifest
# new_thing =
# if (is.null(spp[[bioSp()]]$biomodelos$check$here$to$see$if$null)) {
# "Paste statement saying it is null. "
# } else {
# paste0(bioSp(), '_whatever.filetype')
# },
)

### Create files
### Create Files
tmpdir <- tempdir()
# Create occs
# add req occs
if (!is.null(spp[[bioSp()]]$occData$occsOrig)) {
tmpOccs <- file.path(tmpdir, paste0(bioSp(), '_occs.csv'))
occsBio <- spp[[bioSp()]]$occData$occsOrig
usedOccs <- occsBio$occID %in% spp[[bioSp()]]$occs$occID
occsBio <- cbind(occsBio, use = usedOccs)
write.csv(occsBio, tmpOccs, row.names = FALSE)
}

# Create mapPrediction
# add req pred
if (!is.null(spp[[bioSp()]]$biomodelos$prediction)) {
tmpPred <- file.path(tmpdir, paste0(bioSp(), '_pred.tif'))
raster::writeRaster(spp[[bioSp()]]$biomodelos$prediction, tmpPred,
overwrite = TRUE)
}

# Create thr
# add req occs
if (!is.null(spp[[bioSp()]]$biomodelos$thrs)) {
tmpThrs <- file.path(tmpdir, paste0(bioSp(), '_thr.csv'))
write.csv(spp[[bioSp()]]$biomodelos$thrs, tmpThrs, row.names = TRUE)
}

# Create userSDM prediction
# add req pred
if (!is.null(spp[[bioSp()]]$biomodelos$mask$userSDM)) {
tmpUserSDM <- file.path(tmpdir, paste0(bioSp(), '_userSDM.tif'))
raster::writeRaster(spp[[bioSp()]]$biomodelos$mask$userSDM, tmpUserSDM,
overwrite = TRUE)
}

# Create raster model modified by expert
if (!is.null(spp[[bioSp()]]$biomodelos$predExpert)) {
Expand All @@ -135,25 +191,26 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
}

# Create shapefile of expert polygons
if (!is.null(spp[[bioSp()]]$mask$expertPoly)) {
tmpExpPoly <- file.path(tmpdir, paste0(bioSp(), '_expertPolygonsShp.zip'))
if (!is.null(spp[[bioSp()]]$mask$removePoly)) {
tmpExpPoly <- file.path(tmpdir, paste0(bioSp(), '_expertPolygonShp.zip'))
expertPolys <- do.call("rbind",
c(args = lapply(seq_along(spp[[bioSp()]]$mask$expertPoly),
function(i){spp[[bioSp()]]$mask$expertPoly[i][[1]]}),
makeUniqueIDs = TRUE))
sf::st_write(obj = sf::st_as_sf(expertPolys),
dsn = tmpdir,
layer = paste0(bioSp(), '_expertPolygonsShp'),
layer = paste0(bioSp(), '_expertPolygonShp'),
driver = "ESRI Shapefile",
append = FALSE)
extsExpPoly <- c('dbf', 'shp', 'shx')
fsExpPoly <- file.path(tmpdir, paste0(bioSp(), '_expertPolygonsShp.', extsExpPoly))
fsExpPoly <- file.path(tmpdir, paste0(bioSp(), '_expertPolygonShp.', extsExpPoly))
zip::zipr(zipfile = tmpExpPoly , files = fsExpPoly)
}

# Create extent shapefile
# add req ext
tmpExt <- file.path(tmpdir, paste0(bioSp(), '_projectionExtentShp.zip'))
if (!is.null(spp[[bioSp()]]$procEnvs$bgExt)) {
tmpExt <- file.path(tmpdir, paste0(bioSp(), '_bgExtentShp.zip'))
sf::st_write(obj = sf::st_as_sf(spp[[bioSp()]]$procEnvs$bgExt),
dsn = tmpdir,
layer = paste0(bioSp(), '_bgShp'),
Expand All @@ -162,8 +219,24 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
exts <- c('dbf', 'shp', 'shx')
fsExt <- file.path(tmpdir, paste0(bioSp(), '_bgShp.', exts))
zip::zipr(zipfile = tmpExt, files = fsExt)
}

# Create userSDM extent shapefile
# add req ext
if (!is.null(spp[[bioSp()]]$biomodelos$mask$userPolyExt)) {
tmpUserSDMExt <- file.path(tmpdir, paste0(bioSp(), '_userSDM_ExtentShp.zip'))
sf::st_write(obj = sf::st_as_sf(spp[[bioSp()]]$biomodelos$mask$userPolyExt),
dsn = tmpdir,
layer = paste0(bioSp(), '_userSDM_bgShp'),
driver = "ESRI Shapefile",
append = FALSE)
exts <- c('dbf', 'shp', 'shx')
fsExt <- file.path(tmpdir, paste0(bioSp(), '_userSDM_bgShp.', exts))
zip::zipr(zipfile = tmpUserSDMExt, files = fsExt)
}

# Create Metadata
if (!is.null(spp[[bioSp()]]$evalOut)) {
evalTbl <- spp[[bioSp()]]$evalOut@results
if (grepl("Maxent", spp[[bioSp()]]$biomodelos$modelingMethod, fixed = TRUE)) {
evalTbl <- evalTbl[evalTbl$tune.args == spp[[bioSp()]]$rmd$vis_curModel, ]
Expand Down Expand Up @@ -229,6 +302,7 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
'.zip'))
names(bioMet) <- c("name", "value")
write.csv(bioMet, tmpBioMeta, row.names = FALSE)
}

# add req metadata
tmpRMM <- file.path(tmpdir, paste0(bioSp(), '_rmms.csv'))
Expand Down Expand Up @@ -299,19 +373,53 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
combined_rmd <- gsub('``` r', '```{r}', combined_md)
writeLines(combined_rmd, tmpRMD, useBytes = TRUE)

# Create ZIP file
tmpZIP <- file.path(tmpdir, paste0(spp[[bioSp()]]$rmm$code$wallace$biomodelosTaxID, '.zip'))
filesZIP <- c(tmpOccs, tmpBioMeta, tmpPred, tmpThrs, tmpExt, tmpRMM, tmpRMD)
# create file for new item added to manifest
# if (!is.null(spp[[bioSp()]]$biomodelos$check$here$to$see$if$null)) {
# name_of_created_file <- file.path(tmpdir, paste0(bioSp(), '_whatever.filetype'))
# write_function(spp[[bioSp()]]$biomodelos$NEWTHING, name_of_created_file,
# overwrite = TRUE)
# }


### Create ZIP File
tmpZIP <- file.path(tmpdir, paste0(spp[[bioSp()]], '.zip'))
filesZIP <- c(tmpRMM, tmpRMD)
if (!is.null(spp[[bioSp()]]$occData$occsOrig)) {
filesZIP <- c(filesZIP, tmpOccs)
}
if (!is.null(spp[[bioSp()]]$evalOut)) {
filesZIP <- c(filesZIP, tmpBioMeta)
}
if (!is.null(spp[[bioSp()]]$biomodelos$prediction)) {
filesZIP <- c(filesZIP, tmpPred)
}
if (!is.null(spp[[bioSp()]]$biomodelos$thrs)) {
filesZIP <- c(filesZIP, tmpThrs)
}
if (!is.null(spp[[bioSp()]]$procEnvs$bgExt)) {
filesZIP <- c(filesZIP, tmpExt)
}
if (!is.null(spp[[bioSp()]]$biomodelos$mask$userSDM)) {
filesZIP <- c(filesZIP, tmpUserSDM)
}
if (!is.null(spp[[bioSp()]]$biomodelos$mask$userPolyExt)) {
filesZIP <- c(filesZIP, tmpUserSDMExt)
}
if (!is.null(spp[[bioSp()]]$biomodelos$predExpert)) {
filesZIP <- c(filesZIP, tmpPredExp)
}
if (!is.null(spp[[bioSp()]]$mask$expertPolyt)) {
if (!is.null(spp[[bioSp()]]$mask$expertPoly)) {
filesZIP <- c(filesZIP, tmpExpPoly)
}
# to add something to the zip
#if (!is.null(spp[[bioSp()]]$check$if$null)) {
# filesZIP <- c(filesZIP, name_of_created_file)
# }

zip::zipr(zipfile = tmpZIP,
files = filesZIP)

### Create Payload
PAYLOAD <- list(
taxID = spp[[bioSp()]]$rmm$code$wallace$biomodelosTaxID,
biomodelos_user = input$userBio,
Expand All @@ -321,10 +429,13 @@ rep_biomodelos_module_server <- function(input, output, session, common) {
model = httr::upload_file(tmpZIP,
type = "application/zip")
)


response <- httr::content(httr::POST(URL, body = PAYLOAD, encode = "multipart",
httr::add_headers(host = 'api-biomodelos.humboldt.org.co',
authorization = paste0('apiKey ', input$keyPost))),
as = 'parsed')

if (is.null(response)) {
shinyalert::shinyalert(
"Pushed to BioModelos (**)",
Expand Down
Loading