Diversity.jl

Provides functionality for measuring alpha, beta and gamma diversity of metacommunities (e.g. ecosystems) and their constituent subcommunities.
https://github.com/ecojulia/diversity.jl

Category: Biosphere
Sub Category: Biodiversity Analysis and Metrics

Keywords

biodiversity diversity-measurement ecology julia partitioning-diversity phylogenetic-diversity

Keywords from Contributors

julialang data-storage hdf5-binaries hdf5-files hdf5-library jld mat literate-programming scientific-reports biology

Last synced: about 23 hours ago
JSON representation

Repository metadata

Julia package for diversity measurement

README.md

Diversity

A package for measuring and partitioning diversity

| Documentation | Build Status | DOI | |:-----------------:|:--------------------------:|:--------------------------:| | stable docs | build tests JuliaNightly | Zenodo | | dev docs | codecov | |

Summary

Diversity is a Julia package that provides functionality for measuring alpha, beta and gamma diversity of metacommunities (e.g. ecosystems) and their constituent subcommunities. It implements the framework described in the arXiv paper arXiv:1404.6520 (q-bio.QM), How to partition diversity, which generalises Hill numbers and the similarity-sensitive measures of Leinster and Cobbold so that the diversity of a community can be partitioned among its subcommunities. Similarity between individuals may be of any kind - taxonomic, phylogenetic, genetic, functional or phenotypic - and the package provides a series of older ecological diversity measures through sub-modules as well.

The framework page of the documentation explains what each measure means and where it comes from; it is the place to start if the names below are unfamiliar.

The package is cross-validated against our R package boydorr/rdiversity, which is developed independently, so please raise an issue if you find any problems. We use a DataFrame as the common output format for all of the diversity calculations to provide consistency with rdiversity.

Installation

The package is registered in the General registry on v1.x and so can be installed with add. For example on Julia v1.10:

(@v1.13) pkg> add Diversity
    Resolving package versions...
    Updating `~/.julia/environments/v1.13/Project.toml`
  [d3d5718d] + Diversity v0.6.5
    Updating `~/.julia/environments/v1.13/Manifest.toml`
  [d3d5718d] + Diversity v0.6.5
  
(@v1.13) pkg>

Project Status

The package is confirmed to build and work against Julia v1.10 (the current LTS) and the current release, on Linux, macOS and Windows. It is also tested against nightly.

Contributing and Questions

Contributions are very welcome, as are feature requests and suggestions. Please open an issue if you encounter any problems or would just like to ask a question.

Usage

Diversity Measures

The main package provides numbers-equivalent diversity measures (Hill numbers), similarity-sensitive diversity measures generalising them (from Leinster and Cobbold, 2012), and the alpha, beta and gamma measures that partition those across the subcommunities of a metacommunity. See the framework for what each measure means.

The diversity functions exist both with unicode names (e.g. ᾱ()), which are not automatically exported as we feel they are too short, and with matching ascii names (e.g. NormalisedAlpha()), which are. We also provide a general function to extract any diversity measure for a series of subcommunity relative abundances.

Getting started

Before calculating diversity a Metacommunity object must be created. This object contains all the information needed to calculate diversity.

# Load the package into Julia
using Diversity

# Example population
pop = [1 1 0; 2 0 0; 3 1 4]
pop = pop / sum(pop)

# Create Metacommunity object
meta = Metacommunity(pop)

Calculating diversity

First we need to calculate the low-level diversity component seperately, by passing a metacommunity object to the appropriate function; RawAlpha(), NormalisedAlpha(), RawBeta(), NormalisedBeta(), RawRho(), NormalisedRho(), or Gamma().

# First, calculate the normalised alpha component
component = NormalisedAlpha(meta)

Afterwhich, subdiv() or metadiv() are used to calculate subcommunity or metacommunity diversity, respectively (since both subcommunity and metacommunity diversity measures are transformations of the same low-level components, this is computationally more efficient).

# Then, calculate species richness of the subcommunities
subdiv(component, 0)

# or the average (alpha) species richness across the whole population
metadiv(component, 0)

# We can also generate a diversity profile by calculating multiple q-values simultaneously
df = subdiv(component, 0:30)

In some instances, it may be useful to calculate all subcommunity (or metacommunity) measures. In which case, a Metacommunity object may be passed directly to subdiv() or metadiv():

# To calculate all subcommunity diversity measures
subdiv(meta, 0:2)

# To calculate all metacommunity diversity measures
metadiv(meta, 0:2)

Alternatively, if computational efficiency is not an issue, a single measure of diversity may be calculated directly by calling a wrapper function:

norm_sub_alpha(meta, 0:2)

A complete list of these functions is shown below:

  • raw_sub_alpha() : per-subcommunity estimate of naive-community metacommunity diversity
  • norm_sub_alpha() : similarity-sensitive diversity of each subcommunity in isolation
  • raw_sub_rho() : redundancy of individual subcommunities
  • norm_sub_rho() : representativeness of individual subcommunities
  • raw_sub_beta() : distinctiveness of individual subcommunities
  • norm_sub_beta() : per-subcommunity estimate of effective number of distinct subcommunities
  • sub_gamma() : contribution per individual in a subcommunity toward metacommunity diversity
  • raw_meta_alpha() : naive-community metacommunity diversity
  • norm_meta_alpha() : average similarity-sensitive diversity of subcommunities
  • raw_meta_rho() : average redundancy of subcommunities
  • norm_meta_rho() : average representativeness of subcommunities
  • raw_meta_beta() : average distinctiveness of subcommunities
  • norm_meta_beta() : effective number of distinct subcommunities
  • meta_gamma() : metacommunity similarity-sensitive diversity

Phylogenetic diversity

Phylogenetic diversity (described here) is automatically included in the Diversity module when the Phylo package is loaded. Documentation for these diversity measures can be found here. The phylogenetics code relies on the Phylo package to generate trees to incorporate into the diversity code, and the ppropriate code will be created when both main packages are loaded:

julia> using Diversity, Phylo

julia> communities = [4 1; 3 2; 1 0; 0 1] / 12;

julia> nt = rand(Nonultrametric(4))
RootedTree with 4 tips, 7 nodes and 6 branches.
Leaf names are tip 1, tip 2, tip 4 and tip 3


julia> metaphylo = Metacommunity(communities, PhyloBranches(nt));

julia> raw_meta_rho(metaphylo, [1, 2])
2×8 DataFrame
│ Row │ div_type            │ measure │ q     │ type_level │ type_name │ partition_level │ partition_name │ diversity │
│     │ String              │ String  │ Int64 │ String     │ String    │ String          │ String         │ Float64   │
├─────┼─────────────────────┼─────────┼───────┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1   │ Phylogenetic Branch │ RawRho  │ 1     │ types      │           │ metacommunity   │                │ 1.7787    │
│ 2   │ Phylogenetic Branch │ RawRho  │ 2     │ types      │           │ metacommunity   │                │ 1.66749   │

Genetic diversity

Genetic diversity is provided by two lightweight extensions, so you only load what your data needs: BioSequences for a vector of aligned sequences, and PopGen for a PopData object read from a VCF file. Similarity between types is derived from pairwise genetic distances, mirroring the gen2dist() / dist2sim() pipeline in rdiversity. Documentation for these measures can be found here.

julia> using Diversity, BioSequences

julia> seqs = [dna"ACGTACGT", dna"ACGAACGT", dna"TTTTTTTT"];

julia> gt = GeneticType(seqs; names = ["a", "b", "c"]);

julia> meta_gamma(Metacommunity([0.3, 0.3, 0.4], gt), 0).diversity
1-element Vector{Float64}:
 1.930059437936407

The package also provides some other sub-modules for related measures:

Diversity.Ecology

Many existing ecological diversity measures can be derived from our diversity measures, and so we provide them in the Diversity.Ecology submodule along with generalised versions of them that relate to our general measures of alpha, beta and gamma diversity at subcommunity and metacommunity levels. The generalisations of species richness, Shannon entropy and Simpson's index are the only standard measures we are aware of whose subcommunity components sum directly to the corresponding metacommunity measure (although note that Simpson's index decreases for increased diversity, so small components are more diverse). Documentation for these diversity measures can be found here.

Diversity.Hill

Hill numbers are found in the Diversity.Hill sub-module. Documentation for these diversity measures can be found here.

Diversity.Jost

Lou Jost's diversity measures are found in the Diversity.Jost sub-module. Documentation for these diversity measures is here.

Documentation

Documentation is generated by the Base documentation in Julia and online via the Documenter package.

Using the docs

Accessing the documentation in Julia is easy:

using Diversity

# Returns any documentation for the subdiv() function
?subdiv

The documentation is also available online.

Latest release

The online documentation for the current stable release is here.

Development branch

The online documentation for the latest dev (unreleased) branch is here.

Citation (CITATION.bib)

@article{Diversity.jl-2016,
  author        = {Reeve, Richard and Leinster, Tom and Cobbold, Christina A and
                   Thompson, Jill and Brummitt, Neil A and Mitchell, Sonia N and
		   Matthews, Louise},
  title         = {How to partition diversity},
  journal       = {ArXiv e-prints},
  archivePrefix = "arXiv",
  eprint        = {1404.6520},
  eprinttype    = {arxiv},
  primaryClass  = "q-bio.QM",
  doi           = {10.48550/arXiv.1404.6520},
  keywords      = {Quantitative Biology - Quantitative Methods},
  year          = 2016,
  month         = dec
}

@phdthesis{Diversity.jl-2019,
  author        = {Mitchell, Sonia N},
  title         = {The measurement, dynamics, and interpretation of biological diversity},
  school        = {University of Glasgow},
  year          = 2019,
  address       = {Glasgow, UK}
}

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 909
Total Committers: 10
Avg Commits per committer: 90.9
Development Distribution Score (DDS): 0.056

Commits in past year: 83
Committers in past year: 2
Avg Commits per committer in past year: 41.5
Development Distribution Score (DDS) in past year: 0.096

Name Email Commits
Richard Reeve g****t@r****t 858
soniamitchell s****l@g****k 16
Isaac Peetoom Heida i****a@g****m 12
Tony Kelman t****y@k****t 9
Claire Harris c****s@b****k 7
github-actions[bot] 4****] 2
Michael Krabbe Borregaard m****d@s****k 2
dependabot[bot] 4****] 1
Michael Hatherly m****y@g****m 1
Elliot Saba s****t@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 14 days ago

Total issues: 19
Total pull requests: 43
Average time to close issues: about 1 year
Average time to close pull requests: 3 months
Total issue authors: 6
Total pull request authors: 11
Average comments per issue: 5.47
Average comments per pull request: 3.42
Merged pull request: 37
Bot issues: 0
Bot pull requests: 7

Past year issues: 0
Past year pull requests: 9
Past year average time to close issues: N/A
Past year average time to close pull requests: 15 days
Past year issue authors: 0
Past year pull request authors: 3
Past year average comments per issue: 0
Past year average comments per pull request: 0.78
Past year merged pull request: 6
Past year bot issues: 0
Past year bot pull requests: 3

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/ecojulia/diversity.jl

Top Issue Authors

  • richardreeve (13)
  • PeetoomHeida (2)
  • mkborregaard (1)
  • peter1000 (1)
  • kescobo (1)
  • JuliaTagBot (1)

Top Pull Request Authors

  • richardreeve (27)
  • github-actions[bot] (4)
  • dependabot[bot] (3)
  • tkelman (2)
  • mkborregaard (1)
  • soniamitchell (1)
  • staticfloat (1)
  • EvoArt (1)
  • claireh93 (1)
  • PeetoomHeida (1)
  • MichaelHatherly (1)

Top Issue Labels

  • enhancement (4)
  • testing (1)
  • bug (1)

Top Pull Request Labels

  • dependencies (3)
  • enhancement (2)
  • API (1)
  • julia (1)
  • testing (1)

Package metadata

proxy.golang.org: github.com/ecojulia/diversity.jl

proxy.golang.org: github.com/EcoJulia/Diversity.jl

juliahub.com: Diversity

Julia package for diversity measurement

  • Homepage: http://docs.ecojulia.org/Diversity.jl/
  • Documentation: https://docs.juliahub.com/General/Diversity/stable/
  • Licenses: BSD-2-Clause
  • Latest release: 0.5.15 (published over 2 years ago)
  • Last Synced: 2026-10-13T13:33:22.291054Z (about 2 months ago)
  • Versions: 19
  • Dependent Packages: 1
  • Dependent Repositories: 4
  • Downloads: 25 Last month
  • Rankings:
    • Dependent repos count: 5.615%
    • Forks count: 14.479%
    • Average: 15.152%
    • Stargazers count: 18.871%
    • Dependent packages count: 21.644%

Dependencies

.github/workflows/CompatHelper.yaml actions
  • julia-actions/setup-julia latest composite
.github/workflows/TagBot.yaml actions
  • JuliaRegistries/TagBot v1 composite
.github/workflows/docs.yaml actions
  • actions/checkout v2 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/nightly.yaml actions
  • actions/checkout v2 composite
  • julia-actions/julia-buildpkg latest composite
  • julia-actions/julia-runtest latest composite
  • julia-actions/setup-julia v1 composite
.github/workflows/testing.yaml actions
  • actions/checkout v2 composite
  • codecov/codecov-action v1 composite
  • coverallsapp/github-action master composite
  • julia-actions/julia-buildpkg master composite
  • julia-actions/julia-processcoverage v1 composite
  • julia-actions/julia-runtest master composite
  • julia-actions/setup-julia v1 composite
  • r-lib/actions/setup-r master composite
.github/workflows/doc-cleanup.yaml actions
  • actions/checkout v2 composite
.github/workflows/metadata.yaml actions
  • actions/checkout v7 composite
  • julia-actions/cache v3 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-runtest v1 composite
  • julia-actions/setup-julia v3 composite
docs/Project.toml julia
  • DataStructures *
  • Dates *
  • Diversity *
  • Documenter *
  • Git *
  • HTTP *
  • JSON *
  • JuliaFormatter *
  • Pkg *
  • ResearchSoftwareMetadata *
  • TOML *
  • YAML *
Project.toml julia
  • DataFrames *
  • EcoBase *
  • InteractiveUtils *
  • LinearAlgebra *
  • Missings *
  • RecipesBase *
  • Statistics *
  • StringDistances *

Score: 9.464982590349763