Skip to content

Commit

Permalink
Distance metrics (#57)
Browse files Browse the repository at this point in the history
* Add jaccard and hellinger distances.

* Update documentation file with new distances

* Increase version number to 0.8.0

* Bump version number in docs/Project.toml

* Change version to 0.7.1
  • Loading branch information
pknight24 authored Jan 11, 2021
1 parent fc3c617 commit 651ea89
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["microbiology", "microbiome", "biology"]
license = "MIT"
desc = "Functions and types for working with microbial community data"
authors = ["@kescobo <kevbonham@gmail.com>"]
version = "0.7.0"
version = "0.7.1"

[deps]
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Microbiome = "3bd8f0ae-a0f2-5238-a5af-e1b399a4940c"

[compat]
Documenter = "0.24"
Microbiome = "0.7"
Microbiome = "0.7.1"
4 changes: 3 additions & 1 deletion docs/src/diversity.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Quite often, it's useful to boil stuff down to distances between samples.
from [`Distances.jl`](https://github.com/JuliaStats/Distances.jl)
to get a symetric distance matrix.

Right now, only Bray-Curtis is implemented, because it's the only one I use,
Right now, only Bray-Curtis, Jaccard, and Hellinger are implemented,
but it would be straightforward to add any others.
Open an issue if you want them!

Expand All @@ -25,5 +25,7 @@ using the `fit(MDS, ...)` from `MultivariateStats.jl` under the hood.

```@docs
braycurtis
jaccard
hellinger
pcoa
```
2 changes: 2 additions & 0 deletions src/Microbiome.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export ginisimpson,
present,
prevalence,
braycurtis,
jaccard,
hellinger,
pcoa

using Statistics
Expand Down
19 changes: 16 additions & 3 deletions src/diversity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,28 @@ end
"""
braycurtis(abt::AbstractAbundanceTable)
Retruns a pairwise Bray-Curtis dissimilarity matrix.
Returns a pairwise Bray-Curtis dissimilarity matrix.
"""
braycurtis(abt::AbstractAbundanceTable) = pairwise(BrayCurtis(), collect(abundances(abt)), dims=2)

"""
jaccard(abt::AbstractAbundanceTable)
Returns a pairwise Jaccard distance matrix.
"""
jaccard(abt::AbstractAbundanceTable) = pairwise(Jaccard(), collect(abundances(abt)), dims=2)

"""
hellinger(abt::AbstractAbundanceTable)
Returns a pairwise Hellinger distance matrix.
"""
hellinger(abt::AbstractAbundanceTable) = pairwise(HellingerDist(), collect(abundances(abt)), dims=2)

"""
pcoa(abt::AbstractAbundanceTable, f=braycurtis)
Returns eigenvectors from fiting `MDS` to a distance metric generated by `f`,
Returns eigenvectors from fitting `MDS` to a distance metric generated by `f`,
by default `braycurtis`.
"""
pcoa(abt::AbstractAbundanceTable, f=braycurtis) = fit(MDS, f(abt), distances = true)
pcoa(abt::AbstractAbundanceTable, f=braycurtis) = fit(MDS, f(abt), distances = true)
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ end
end

@test all(braycurtis(comm) .== [0 1 1 1 1; 1 0 1 1 1; 1 1 0 1 1; 1 1 1 0 1; 1 1 1 1 0])
@test all(jaccard(comm) .== [0 1 1 1 1; 1 0 1 1 1; 1 1 0 1 1; 1 1 1 0 1; 1 1 1 1 0])
@test all(hellinger(comm) .== [0 1 1 1 1; 1 0 1 1 1; 1 1 0 1 1; 1 1 1 0 1; 1 1 1 1 0])
@test pcoa(comm) isa MDS
end

Expand Down

2 comments on commit 651ea89

@kescobo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/27771

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.1 -m "<description of version>" 651ea89946e5969250a2e50a88959bb3015973ab
git push origin v0.7.1

Please sign in to comment.