Skip to content

Commit

Permalink
Merge pull request #27 from kescobo/kevdev
Browse files Browse the repository at this point in the history
Some beta diversity functions
  • Loading branch information
kescobo authored Oct 19, 2018
2 parents 1a71f9b + 048449e commit 3cc4711
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Microbiome.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export
optimalorder,
optimalorder!,
ginisimpson,
shannon
shannon,
present,
prevalence


using Reexport
@reexport using SpatialEcology
Expand Down
11 changes: 11 additions & 0 deletions src/abundances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,14 @@ function relativeabundance(a::AbstractComMatrix; kind::Symbol=:fraction)
relativeabundance!(relab, kind=kind)
return relab
end

"""
Check if a given (non-zero) value is greater than a minimum value.
If the minimum abundance is 0, just checks if value is non-zero
"""
present(t::Float64, minabundance::Float64=0.0001) = t == 0 ? false : t >= minabundance

"""
Return the fraction of values that are greater than a minimum
"""
prevalence(a::AbstractArray{<:Real}, minabundance::Float64=0.0001) = mean(x-> present(x, minabundance), a)
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ using Test
end

@test featurenames(filt)[end] == "other"

@test present(0.1, 0.001)
@test !present(0.001, 0.1)
@test present(rand(), 0.)

a = zeros(100)
a[randperm(100)[1:10]] .= rand(10)

@test prevalence(a, 0.) == 0.1
end

@testset "Distances" begin
Expand Down

0 comments on commit 3cc4711

Please sign in to comment.