diff --git a/docs/SpeciesInteractionNetworks.bib b/docs/SpeciesInteractionNetworks.bib index 16db38b9..c3972303 100644 --- a/docs/SpeciesInteractionNetworks.bib +++ b/docs/SpeciesInteractionNetworks.bib @@ -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;} diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 77dc4915..4e5ee626 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -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 diff --git a/docs/src/meso_level/motifs.md b/docs/src/meso_level/motifs.md new file mode 100644 index 00000000..39cea3d6 --- /dev/null +++ b/docs/src/meso_level/motifs.md @@ -0,0 +1,11 @@ +# Motifs + +!!! abstract + + ya + +## List of motifs + +```@docs +motifs +``` diff --git a/src/SpeciesInteractionNetworks.jl b/src/SpeciesInteractionNetworks.jl index 9ce55a67..71c8cb83 100644 --- a/src/SpeciesInteractionNetworks.jl +++ b/src/SpeciesInteractionNetworks.jl @@ -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 diff --git a/src/meso_level/motifs.jl b/src/meso_level/motifs.jl new file mode 100644 index 00000000..d911be35 --- /dev/null +++ b/src/meso_level/motifs.jl @@ -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 \ No newline at end of file