EcologicalNetworks.jl
EcologicalNetworks.jl copied to clipboard
overlap function and bottom projection of bipartite network
Thank you all for creating this amazing tool! I'm trying to generate the bottom projection of a bipartite network. It seems the 'overlap' function does this, unfortunately I am having trouble manipulating the output. The documentation at ?overlap says "See the documentation for ?overlap for the output format." Any help is greatly appreciated!
With gratitude, Jennie
I'm re-reading the documentation and it should definitely be improved -- the part that matters is here:
The overlap is returned as a vector of named tuples, with elements pair (a tuple of species names), and overlap (the number of shared interactors). The ordering within the pair of species is unimportant, since overlap graphs are symmetrical.
so the way to extract the bottom projection would be to filter out pairs that have top species - that being said, the overlap graph would be undirected, and we expect that interactions are directional. If you have a minimal bit of code you want to write, I'd be happy to give more feedback.
@JennieLavine fwiw, another way to get the projection as a network object would be to multiply the incidence matrix by its transpose:
N_bip = BipartiteNetwork(convert(Matrix{Bool}, [1 1 0 1; 0 1 1 1]))
N_uni_top = UnipartiteQuantitativeNetwork(convert(Matrix{Int64}, N_bip.edges * N_bip.edges'))
N_uni_bot = UnipartiteQuantitativeNetwork(convert(Matrix{Int64}, N_bip.edges' * N_bip.edges))
Note these are quantitative by definition, but could always be convert
ed:
convert(UnipartiteNetwork, N_uni_top)
They also include diagonal elements (i.e. overlap with oneself), that could be removed if desired:
import LinearAlgebra
N_uni_top.edges[LinearAlgebra.diagind(N_uni_top.edges)] .= 0
@tpoisot Is this just a matter of rephrasing the documentation to better reflect the actual output, or should the functions be updated to actually return a "graph"?