Skip to content

Repository for the phylogenetic indicator calculation workflow as part of the Bcubed project.

License

Notifications You must be signed in to change notification settings

b-cubed-eu/pdindicatoR

Repository files navigation

pdindicatoR

Phylogenetic diversity (PD) is a measure of biodiversity which takes evolution into account. It is calculated as the sum of the lengths of the phylogenetic tree branches representing the minimum tree-spanning path among a group of species. Phylogenetic diversity can be used in conservation planning to maximise a variety of features, meaning we do not aim to conserve specific features, but rather want to boost a diverse range of features. Conserving a variety of features could be particularly useful in light of the changing environmental conditions, as we can only guess which features will be important in the future.

In this package, we provide a workflow to calculate a metric that gives information about how well PD of a certain higher taxonomic group is currently safeguarded by protected areas and a spatial visualisation which can be used to identify potential directions for future expansion of protected areas.

Installation

Example

This example shows a basic workflow for using the functions in the pdindicatoR package to calculate PD from a phylogenetic tree and an occurence cube with occurences for a certain higher taxon, produce a gridded map of PD scores with colour gradient scale, and show the overlap with protected areas.

# Load packages
library(tidyverse)
library(rotl)
library(sf)
library(gdalUtilities)
library(ape)
library(rnaturalearth)
library(purrr)

Editing the config file

In order to start the workflow, the user should edit config.R in order to set the working directory path and specify the location of the phylogenetic tree (Newick format) and data cube (.csv format) files. In addition, a cutoff-value for 'high phylogenetic diversity'should be specified and the coordinates of the bounding box for the maps.

wd_path <- "~/username/pdindicatoR/"
tree_path <- "./data/Musteloidea_tree.tre"
cube_path <- "./data/cube_musteloidea_BE_databricks.csv"
cutoff <- 6
taxon <- "Musteloidea"
xmin = 3885477
xmax = 3929441
ymin = 3103857
ymax = 3126672

Loading tree and datacube

A phylogenetic tree and occurrence datacube for selected taxa should be provided by the user. The phylogenetic tree should be specified in Newick format and contain branch lengths. Published phylogenetic trees can be downloaded through the Open Tree of Life project. Occurrence datacubes can be generated by querying the GBIF SQL Occurrence Download API. This webpage details how to query the API while This webpage contains instructions on how to write a SQL query that returns an occurrence cube. The API can also be queried using the occ_download_sql() function of rgbif.

The phylogenetic tree and datacube are loaded into R and printed to confirm they are processed correctly.

tree <- ape::read.tree(tree_path)
cube <- read.csv(cube_path, stringsAsFactors = FALSE, sep="\t") # specify the correct seperator depending on the format of the datacube
plot(tree, cex=0.45)
head(cube)

Phylogenetic tree of Musteloidea

To add: img of head(cube), with the request that user should check that the column names are respected.

Load functions -- Can be removed once package is installable --

The pdindicatoR functions can be loaded using source().

# Load functions
source("./R/taxonmatch.R")
source("./R/append_ott_id.R")
source("./R/pdmap.R")
source("./R/pdindicator.R")
source("./R/convert_multipolygons.R")
source("./R/calculate_PD.R")

_

Matching species in phylogenetic tree and datacube

The leaf labels of a phylogenetic tree downloaded from the OTL database are specified as either species names or OTL id's (ott_id). We can use the function append_ott_id() to match them with their corresponding GBIF id, and append the corresponding ott_id's to the provided datacube.

mcube <- append_ott_id(tree, cube)
head(mcube)

Calculate Phylogenetic Diversity for each grid cell

We first have to aggregate the occurrence cube in order to get a list of observed species for each grid cell.

aggr_cube <- aggregate_cube(mcube)

We can then calculate the PD value for all grid cells by using the purrr:map function to apply the function calculate_PD() for each grid cell.

PD_cube <- aggr_cube %>% mutate(PD = purrr::map(unique_names, calculate_pd, tree=tree))

Visualize PD on a map & calculate the indicator

About

Repository for the phylogenetic indicator calculation workflow as part of the Bcubed project.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published