Skip to content

Commit

Permalink
Merge pull request #27 from richardreeve/multiple
Browse files Browse the repository at this point in the history
Updating phylogenetic diversity types, speed-up, Julia v1.0!
  • Loading branch information
richardreeve authored Aug 16, 2018
2 parents ef0a4d5 + 415a46b commit 917d201
Show file tree
Hide file tree
Showing 42 changed files with 990 additions and 812 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@ os:
julia:
- 0.6
- 0.7
- 1.0
- nightly

matrix:
fast_finish: true
allow_failures:
- julia: 0.7
- julia: nightly

before_install:
# linux
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y "deb http://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -s -c)/"; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq -y; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install git libxml2-dev r-base r-base-dev r-recommended -y; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install git libxml2-dev r-base r-base-dev r-recommended -y --allow-unauthenticated; fi

script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then JULIA_MUST_CROSSVALIDATE=1 julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.build("Diversity"); Pkg.test("Diversity", coverage=true)'; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.build("Diversity"); Pkg.test("Diversity", coverage=true)'; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then JULIA_MUST_CROSSVALIDATE=1 julia -e '(try using Pkg; true catch; false end || Pkg.init()); Pkg.clone(pwd()); Pkg.build("Diversity"); Pkg.test("Diversity", coverage=true)'; fi
# (VERSION >= v"0.7.0-" && (ENV["JULIA_MUST_CROSSVALIDATE"] = "0"));
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then julia -e '(try using Pkg; true catch; false end || Pkg.init()); Pkg.clone(pwd()); Pkg.build("Diversity"); Pkg.test("Diversity", coverage=true)'; fi

after_success:
- julia -e 'cd(Pkg.dir("Diversity", "test")); include("coverage.jl")'
- julia -e 'Pkg.add("Documenter"); cd(Pkg.dir("Diversity")); include(joinpath("docs", "make.jl"))'
- julia -e '(try using Pkg; catch end); using Diversity; cd(Diversity.path()); include("coverage.jl")'
- julia -e '(try using Pkg; catch end); Pkg.add("Documenter"); using Diversity; cd(Diversity.path(;dir=".")); include(joinpath("docs", "make.jl"))'
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ A complete list of these functions is shown below:
* `norm_meta_beta()` : effective number of distinct subcommunities
* `meta_gamma()` : metacommunity similarity-sensitive diversity

#### Diversity.Phylogenetics
#### Phylogenetics

Phylogenetic diversity (described [here][leinster-cobbold-url]) is
included in the Diversity.Phylogenetics submodule. Documentation for
these diversity measures can be found
automatically included in the Diversity module when the `Phylo` package
is loaded. Documentation for these diversity measures can be found
[here](http://richardreeve.github.io/Diversity.jl/latest/phylogenetics/).
The phylogenetics code relies on the [Phylo][phylo-url] package to
generate trees to incorporate into the diversity code, and the
`Diversity.Phylogenetics` sub-package will be created when both
main packages are loaded:

```julia-repl
julia> using Diversity, Phylo, Diversity.Phylogenetics
julia> using Diversity, Phylo
Creating Diversity to Phylo interface...
julia> communities = [4 1; 3 2; 1 0; 0 1] / 12;
Expand All @@ -171,16 +171,11 @@ String["tip 1", "tip 2", "tip 3", "tip 4"]
julia> metaphylo = Metacommunity(communities, PhyloTypes(nt));
julia> raw_meta_rho(metaphylo, [1, 2])
2×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼──────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "RawRho" │ 1 │ "types" │ "" │ "metacommunity" │
│ 2 │ "RawRho" │ 2 │ "types" │ "" │ "metacommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "" │ 1.66187 │
│ 2 │ "" │ 1.51391 │
2×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼──────────────┼─────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Phylogenetic │ RawRho │ 1 │ types │ │ metacommunity │ │ 1.75622 │
│ 2 │ Phylogenetic │ RawRho │ 2 │ types │ │ metacommunity │ │ 1.61371 │
```

The package also provides some other sub-modules for related measures:
Expand Down
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
Expand Down Expand Up @@ -40,8 +41,8 @@ install:
build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
- C:\projects\julia\bin\julia -e "(try using Pkg; true catch; false end || Pkg.init());
Pkg.clone(pwd(), \"Diversity\"); Pkg.build(\"Diversity\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Diversity\")"
- C:\projects\julia\bin\julia -e "(try using Pkg; catch end); Pkg.test(\"Diversity\")"
18 changes: 7 additions & 11 deletions docs/diversity.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ 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 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()`.

```julia
# First, calculate the normalised alpha component
Expand Down Expand Up @@ -128,6 +128,7 @@ generate trees to incorporate into the diversity code:

```julia-repl
julia> using Diversity, Phylo, Diversity.Phylogenetics
Creating Diversity to Phylo interface...
julia> communities = [4 1; 3 2; 1 0; 0 1] / 12;
Expand All @@ -139,16 +140,11 @@ String["tip 1", "tip 2", "tip 3", "tip 4"]
julia> metaphylo = Metacommunity(communities, PhyloTypes(nt));
julia> raw_meta_rho(metaphylo, [1, 2])
2×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼──────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "RawRho" │ 1 │ "types" │ "" │ "metacommunity" │
│ 2 │ "RawRho" │ 2 │ "types" │ "" │ "metacommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "" │ 1.66187 │
│ 2 │ "" │ 1.51391 │
2×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼──────────────┼─────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Phylogenetic │ RawRho │ 1 │ types │ │ metacommunity │ │ 1.80666 │
│ 2 │ Phylogenetic │ RawRho │ 2 │ types │ │ metacommunity │ │ 1.7056 │
```

[docs-latest-img]: https://img.shields.io/badge/docs-latest-blue.svg
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Documenter
using Diversity

makedocs(modules = [Diversity, Diversity.Phylogenetics,
makedocs(modules = [Diversity,
Diversity.Ecology, Diversity.Jost, Diversity.Hill],
clean = false)

Expand Down
2 changes: 1 addition & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ docs_dir: 'build'

pages:
- Introduction: index.md
- Phylogenetics: phylogenetics.md
- Submodules:
- Phylogenetics: phylogenetics.md
- API: api.md
- Other related measures:
- Ecology: ecology.md
Expand Down
59 changes: 19 additions & 40 deletions docs/src/ecology.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,34 @@ julia> community /= sum(community);
julia> diversity = simpson(community)
1×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼───────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "Simpson" │ 2 │ "types" │ "" │ "subcommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "1" │ 0.36 │
│ Row │ div_type │ measure │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼──────────┼─────────┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Unique │ Simpson │ types │ │ subcommunity │ 1 │ 0.36 │
julia> ecosystem = [2 2 0.; 0 2 2]';
julia> ecosystem /= sum(ecosystem);
julia> jaccard(ecosystem)
1×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼───────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "Jaccard" │ 0 │ "types" │ "" │ "metacommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "" │ 0.333333 │
1×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼──────────┼─────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Unique │ Jaccard │ 0 │ types │ │ metacommunity │ │ 0.333333 │
julia> generalisedjaccard(ecosystem, [0, 1, 2])
3×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼───────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "Jaccard" │ 0 │ "types" │ "" │ "metacommunity" │
│ 2 │ "Jaccard" │ 1 │ "types" │ "" │ "metacommunity" │
│ 3 │ "Jaccard" │ 2 │ "types" │ "" │ "metacommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "" │ 0.333333 │
│ 2 │ "" │ 0.414214 │
│ 3 │ "" │ 0.5 │
3×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼─────────────┼─────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Arbitrary Z │ Jaccard │ 0 │ types │ │ metacommunity │ │ 0.333333 │
│ 2 │ Arbitrary Z │ Jaccard │ 1 │ types │ │ metacommunity │ │ 0.414214 │
│ 3 │ Arbitrary Z │ Jaccard │ 2 │ types │ │ metacommunity │ │ 0.5 │
julia> generalisedjaccard(ecosystem, [0, 1, 2], eye(3))
3×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼───────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "Jaccard" │ 0 │ "types" │ "" │ "metacommunity" │
│ 2 │ "Jaccard" │ 1 │ "types" │ "" │ "metacommunity" │
│ 3 │ "Jaccard" │ 2 │ "types" │ "" │ "metacommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "" │ 0.333333 │
│ 2 │ "" │ 0.414214 │
│ 3 │ "" │ 0.5 │
3×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼─────────────┼─────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Arbitrary Z │ Jaccard │ 0 │ types │ │ metacommunity │ │ 0.333333 │
│ 2 │ Arbitrary Z │ Jaccard │ 1 │ types │ │ metacommunity │ │ 0.414214 │
│ 3 │ Arbitrary Z │ Jaccard │ 2 │ types │ │ metacommunity │ │ 0.5 │
```

```@contents
Expand Down
20 changes: 7 additions & 13 deletions docs/src/hill.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@
Accessing the main functionality in the package is simple:

```jldoctest
julia> using Diversity.Hill
ulia> using Diversity.Hill
julia> community = [10, 20, 20, 0, 3];
julia> community /= sum(community);
julia> diversities = hillnumber(community, [0, 1, 2])
3×7 DataFrames.DataFrame
│ Row │ measure │ q │ type_level │ type_name │ partition_level │
├─────┼──────────────┼───┼────────────┼───────────┼─────────────────┤
│ 1 │ "HillNumber" │ 0 │ "types" │ "" │ "subcommunity" │
│ 2 │ "HillNumber" │ 1 │ "types" │ "" │ "subcommunity" │
│ 3 │ "HillNumber" │ 2 │ "types" │ "" │ "subcommunity" │
│ Row │ partition_name │ diversity │
├─────┼────────────────┼───────────┤
│ 1 │ "1" │ 4.0 │
│ 2 │ "1" │ 3.36264 │
│ 3 │ "1" │ 3.09021 │
3×8 DataFrames.DataFrame
│ Row │ div_type │ measure │ q │ type_level │ type_name │ partition_level │ partition_name │ diversity │
├─────┼──────────┼────────────┼───┼────────────┼───────────┼─────────────────┼────────────────┼───────────┤
│ 1 │ Unique │ HillNumber │ 0 │ types │ │ subcommunity │ 1 │ 4.0 │
│ 2 │ Unique │ HillNumber │ 1 │ types │ │ subcommunity │ 1 │ 3.36264 │
│ 3 │ Unique │ HillNumber │ 2 │ types │ │ subcommunity │ 1 │ 3.09021 │
```

```@contents
Expand Down
Loading

0 comments on commit 917d201

Please sign in to comment.