Skip to content

Commit

Permalink
Export and document preys_of and predators_of
Browse files Browse the repository at this point in the history
  • Loading branch information
ismael-lajaaiti committed Nov 16, 2022
1 parent 1eb05d0 commit 6f9fb03
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/BEFWM2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export potential_competition_links
export potential_facilitation_links
export potential_interference_links
export potential_refuge_links
export predators_of
export preys_of
export producer_growth
export producers
export richness
Expand Down
50 changes: 47 additions & 3 deletions src/measures/structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,31 @@ producers(A::AbstractMatrix) = (1:richness(A))[all(A .== 0; dims = 2)|>vec]
#### end ####

#### Find predators ####
"Return indexes of the predators of species `i`."
"""
predators_of(i, network)
Return indexes of the predators of species `i` for the given `network`.
# Examples
```jldoctest
julia> foodweb = FoodWeb([0 0 0; 1 0 0; 1 1 0]);
julia> predators_of(1, foodweb)
2-element Vector{Int64}:
2
3
julia> predators_of(2, foodweb)
1-element Vector{Int64}:
3
julia> predators_of(3, foodweb)
Int64[]
```
See also [`preys_of`](@ref) and [`producers`](@ref).
"""
predators_of(i, A::AdjacencyMatrix) = A[:, i].nzind
predators_of(i, net::FoodWeb) = predators_of(i, net.A)
predators_of(i, net::MultiplexNetwork) = predators_of(i, net.layers[:trophic].A)
Expand All @@ -45,10 +69,30 @@ predators(net::EcologicalNetwork) = filter(ispredator, net)
#### end ####

#### Find preys ####
"Return indexes of the preys of species `i`."
preys_of(i, A::AdjacencyMatrix) = A[i, :].nzind
"""
preys_of(i, network)
Return indexes of the preys of species `i` for the given `network`.
# Examples
```jldoctest
julia> foodweb = FoodWeb([0 0 0; 0 0 0; 1 1 0]);
julia> preys_of(3, foodweb)
2-element Vector{Int64}:
1
2
julia> preys_of(1, foodweb) # empty
Int64[]
```
See also [`predators_of`](@ref) and [`producers`](@ref).
"""
preys_of(i, net::FoodWeb) = preys_of(i, net.A)
preys_of(i, net::MultiplexNetwork) = preys_of(i, net.layers[:trophic].A)
preys_of(i, A::AdjacencyMatrix) = A[i, :].nzind

"Is species `i` a prey?"
isprey(i, A::AdjacencyMatrix) = !isempty(A[:, i].nzind)
Expand Down

0 comments on commit 6f9fb03

Please sign in to comment.