This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

install.packages('bipartite')
Error in install.packages : Updating loaded packages
install.packages('rglobi')
Error in install.packages : Updating loaded packages
install.packages('tidyverse')
Installing package into ‘/media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/tidyverse_1.3.1.tar.gz'
Content type 'application/x-gzip' length 702779 bytes (686 KB)
==================================================
downloaded 686 KB

* installing *source* package ‘tidyverse’ ...
** package ‘tidyverse’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (tidyverse)

The downloaded source packages are in
    ‘/tmp/Rtmp15lpHk/downloaded_packages’
install.packages("bipartite")
Installing package into ‘/media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/bipartite_2.16.tar.gz'
Content type 'application/x-gzip' length 1839736 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

* installing *source* package ‘bipartite’ ...
** package ‘bipartite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c bmn5.cc -o bmn5.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c identifyModules.cc -o identifyModules.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-5XUBcI/r-base-4.1.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o bipartite.so bmn5.o identifyModules.o init.o -L/usr/lib/R/lib -lR
installing to /media/jorrit/branta/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-bipartite/00new/bipartite/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (bipartite)

The downloaded source packages are in
    ‘/tmp/Rtmp15lpHk/downloaded_packages’
install.packages("rglobi")
Error in install.packages : Updating loaded packages

Plot some visualizations for pre-canned olito2015 dataset.

library(bipartite)
par(xpd=T)
plotweb(bipartite::olito2015)

visweb(bipartite::olito2015)
Warning in visweb(bipartite::olito2015) : Object converted to matrix.

A small hard coded network to get a sense of the data structures.

library(bipartite)
testdata <- data.frame(higher = c("bee1","bee1","bee1","bee2","bee1","bee3"), 
lower = c("plant1","plant2","plant1","plant2","plant3","plant4"), 
webID = c("meadow","meadow","meadow","meadow","meadow","meadow"), freq=c(5,9,1,2,3,7))

dim(testdata)
class(testdata)
summary(testdata)

bipartite::frame2webs(testdata)-> SmallTestWeb

SmallTestWeb
bipartite::plotweb(SmallTestWeb$meadow)

Use GloBI rglobi Web API to get specific interaction records

library(dplyr)

oakfun <- rglobi::get_interactions_by_taxa(sourcetaxon = "Fungi", targettaxon="Quercus", showfield=c('source_taxon_name', 'target_taxon_name')) %>%
  select(source_taxon_name, target_taxon_name) %>%
  mutate(webID = 'web1')

head(oakfun)

Alternatively, use a static file


# about 33k interactions
oakfun <- readr::read_csv('../data/oakfungi.csv') %>%
  select(source_taxon_name, target_taxon_name) %>%
  mutate(webID = 'web1')

head(oakfun)

Or a smaller static file

# a smaller 100 record sample
oakfun <- readr::read_csv('../data/oakfungi-sample.csv') %>%
  select(source_taxon_name, target_taxon_name) %>%
  mutate(webID = 'web1')

head(oakfun)

Now visualize the retrieved globi data

par(xpd=T)
oakfun_web <- bipartite::frame2webs(oakfun, varnames = c("source_taxon_name", "target_taxon_name", "webID"))
bipartite::plotweb(oakfun_web$web1)
bipartite::visweb(oakfun_web$web1)

Here’s some examples of working with network metrics. See bipartite vignette for more examples.

Group level metrics


group_metrics <- bipartite::grouplevel(oakfun_web$web1, level="both", index=c("mean number of links", "weighted cluster coefficient", "effective partners", "niche overlap"), dist="bray")

head(group_metrics)

Species level metrics

species_metrics <- bipartite::specieslevel(oakfun_web$web1, level="lower", index=c("normalised degree", "PDI", "effective partners"), PDI.normalise=F)

head(species_metrics)
LS0tCnRpdGxlOiAiQ2hlYXRzaGVldCBmb3IgRGVhZHdvb2QgV29ya3Nob3AgRGF5IDIiCm91dHB1dDoKICBwZGZfZG9jdW1lbnQ6IGRlZmF1bHQKICBodG1sX25vdGVib29rOiBkZWZhdWx0Ci0tLQoKVGhpcyBpcyBhbiBbUiBNYXJrZG93bl0oaHR0cDovL3JtYXJrZG93bi5yc3R1ZGlvLmNvbSkgTm90ZWJvb2suIFdoZW4geW91IGV4ZWN1dGUgY29kZSB3aXRoaW4gdGhlIG5vdGVib29rLCB0aGUgcmVzdWx0cyBhcHBlYXIgYmVuZWF0aCB0aGUgY29kZS4gCgpgYGB7cn0KaW5zdGFsbC5wYWNrYWdlcygnYmlwYXJ0aXRlJykKaW5zdGFsbC5wYWNrYWdlcygncmdsb2JpJykKaW5zdGFsbC5wYWNrYWdlcygndGlkeXZlcnNlJykKYGBgCgpQbG90IHNvbWUgdmlzdWFsaXphdGlvbnMgZm9yIHByZS1jYW5uZWQgb2xpdG8yMDE1IGRhdGFzZXQuCgpgYGB7cn0KbGlicmFyeShiaXBhcnRpdGUpCn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