Skip to content

Commit

Permalink
feat: bipartite motifs
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Jun 23, 2023
1 parent 2a7d340 commit 6f6de46
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/SpeciesInteractionNetworks.bib
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,17 @@ @Article{Poisot2023Network
publisher = {Elsevier {BV}},
}

@Article{Simmons2018Motifs,
author = {Benno I. Simmons and Alyssa R. Cirtwill and Nick J. Baker and Hannah S. Wauchope and Lynn V. Dicks and Daniel B. Stouffer and William J. Sutherland},
journal = {Oikos},
title = {Motifs in bipartite ecological networks: uncovering indirect interactions},
year = {2018},
month = {oct},
number = {2},
pages = {154--170},
volume = {128},
doi = {10.1111/oik.05670},
publisher = {Wiley},
}

@Comment{jabref-meta: databaseType:bibtex;}
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nav:
- Specificity: micro_level/specificity.md
- Centrality: micro_level/centrality.md
- Meso:
- Motifs: meso_level/motifs.md
- Paths: meso_level/paths.md
- Macro:
- Links counting: macro_level/links.md
Expand Down
11 changes: 11 additions & 0 deletions docs/src/meso_level/motifs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Motifs

!!! abstract

ya

## List of motifs

```@docs
motifs
```
3 changes: 3 additions & 0 deletions src/SpeciesInteractionNetworks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export ShortestPathMethod
export normalize
export shortestpath, pathbetween

include("meso_level/motifs.jl")
export motifs

include("meso_level/paths/BellmanFord.jl")
export BellmanFord

Expand Down
48 changes: 48 additions & 0 deletions src/meso_level/motifs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
motifs(::Type{Bipartite}, nodes::Integer)
Returns a list of bipartite motifs with the specified number of nodes. The list
of motifs for each richness are from [Simmons2018Motifs](@citet).
###### References
[Simmons2018Motifs](@citet*)
"""
function motifs(::Type{Bipartite}, nodes::Integer)
A = Matrix{Bool}[]
if nodes == 2
A = [ones(Bool, 1,1)]
end
if nodes == 3
A = Matrix{Bool}[
Bool[1 1;],
reshape(Bool[1; 1], (2,1))
]
end
if nodes == 4
A = Matrix{Bool}[
Bool[1 1 1;],
Bool[1 1; 0 1],
Bool[1 1; 1 1],
reshape(Bool[1; 1; 1], (3,1)),
]
end
if nodes == 5
A = Matrix{Bool}[
Bool[1 1 1 1;],
Bool[1 0; 1 0; 1 1;],
Bool[1 0; 1 1; 0 1;],
Bool[1 0; 1 1; 1 1;],
Bool[1 1; 1 1; 1 1;],
Bool[1 0 0; 1 1 1;],
Bool[1 1 0; 0 1 1;],
Bool[1 1 0; 1 1 1;],
Bool[1 1 1; 1 1 1],
reshape(Bool[1; 1; 1; 1;], (4, 1)),
]
end
if isempty(A)
throw("Bipartite motifs with $(nodes) nodes are not supported")
end
return SpeciesInteractionNetwork{Bipartite, Binary}.(A)
end

0 comments on commit 6f6de46

Please sign in to comment.