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

Multiple diversity types, speed-up, Julia v1.0! #27

Merged
merged 27 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1d7ff59
Add in getdiversityname() interface to report on what kind of diversi…
richardreeve Jul 10, 2018
62e1550
Extend diversity measures to report diversity type and then change te…
richardreeve Jul 10, 2018
881a09f
Update Hill, Ecology and Jost sub-packages to handle diversity type info
richardreeve Jul 10, 2018
bddfb9b
Update docs (and doctests) for new outputs.
richardreeve Jul 10, 2018
3d490e6
Minor testing completeness.
richardreeve Jul 11, 2018
f46c653
New interface identifies columns that need to be added to output to d…
richardreeve Jul 11, 2018
3ff8f8a
Implement new added output column interface in PhyloTypes and use in …
richardreeve Jul 11, 2018
6e37a38
Massive reduction in memory use (and increase in speed) in getweight(…
richardreeve Aug 8, 2018
fc707a4
Renaming arguments in EcoBase subpackage.
richardreeve Aug 8, 2018
0e87c38
No longer needed now we use Requires.
richardreeve Aug 9, 2018
f292edc
Correct type for 1.
richardreeve Aug 9, 2018
1d91fb4
>10x speed up and reduction in memory use for powermean().
richardreeve Aug 9, 2018
b6797c5
Indexing using eachindex().
richardreeve Aug 12, 2018
f889cfe
Add Diversity.path() to access package folder and upgrade travis and …
richardreeve Aug 12, 2018
20b755e
Redo travis testing to fix(?) problems with RCall on Julia >= 0.7.
richardreeve Aug 12, 2018
f698b03
Fixing travis.
richardreeve Aug 12, 2018
ae5b357
Travis ongoing.
richardreeve Aug 12, 2018
88cee0f
Fixing Requires (with Phylo) to work with 1.0.
richardreeve Aug 16, 2018
34d6996
Add in new iterator syntax
richardreeve Aug 16, 2018
6b007d7
Fixing code to new 1.0 syntax
richardreeve Aug 16, 2018
bbd4cfa
Fixing problems in EcoBase for 1.0.
richardreeve Aug 16, 2018
1650a9d
Phylo interface is no longer a sub-module.
richardreeve Aug 16, 2018
5e2d020
Update testing to do RCall work on 1.0.
richardreeve Aug 16, 2018
f592f2a
Update testing to 1.0.
richardreeve Aug 16, 2018
5c87997
Missing broadcasts.
richardreeve Aug 16, 2018
ca35de5
Fix warning for Phylo.
richardreeve Aug 16, 2018
415a46b
Fix handling of Phylo package through Requires.jl - adjust docs.
richardreeve Aug 16, 2018
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
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