| Title: | 'Mangal' Client |
|---|---|
| Description: | An interface to the 'Mangal' database - a collection of ecological networks. This package includes functions to work with the 'Mangal RESTful API' methods (<https://mangal-interactions.github.io/mangal-api/>). |
| Authors: | Steve Vissault [aut, ctb] (ORCID: <https://orcid.org/0000-0002-0866-4376>), Kevin Cazelles [aut, cre] (ORCID: <https://orcid.org/0000-0001-6619-9874>), Gabriel Bergeron [aut, ctb], Benjamin Mercier [aut, ctb], Clément Violet [aut, ctb], Dominique Gravel [aut], Timothée Poisot [aut], Thomas Lin Pedersen [rev] (ORCID: <https://orcid.org/0000-0002-5147-4711>), Anna Willoughby [rev] (ORCID: <https://orcid.org/0000-0002-0504-0605>) |
| Maintainer: | Kevin Cazelles <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.2.0 |
| Built: | 2025-12-03 22:27:37 UTC |
| Source: | https://github.com/ropensci/rmangal |
mgNetworksCollection or mgNetwork objects to igraph objects.Coerce mgNetworksCollection or mgNetwork objects to igraph objects.
## S3 method for class 'mgNetwork' as.igraph(x, ...) ## S3 method for class 'mgNetworksCollection' as.igraph(x, ...)## S3 method for class 'mgNetwork' as.igraph(x, ...) ## S3 method for class 'mgNetworksCollection' as.igraph(x, ...)
x |
either a |
... |
currently ignored. |
An object of class igraph for a mgNetwork object and a list of
igraph objects for mgNetworksCollection.
as.igraph(mgNetwork): Convert mgNetwork objects to igraph objects.
as.igraph(mgNetworksCollection): Convert mgNetworksCollection objects to a list of igraph objects.
List interactions type contained in mangal-db
avail_type()avail_type()
Combine mgNetworksCollection and mgNetwork objects into a
mgNetworksCollection object.
combine_mgNetworks(...)combine_mgNetworks(...)
... |
objects of class |
An object of class mgNetworksCollection.
mg_random_1071 <- get_collection(c(1071)) mg_random_1074 <- get_collection(c(1074)) combine_mgNetworks(mg_random_1071, mg_random_1074)mg_random_1071 <- get_collection(c(1071)) mg_random_1074 <- get_collection(c(1074)) combine_mgNetworks(mg_random_1071, mg_random_1074)
Retrieve all references pertaining to the networks collection or individual network
get_citation(x) ## S3 method for class 'mgNetwork' get_citation(x) ## S3 method for class 'mgNetworksCollection' get_citation(x)get_citation(x) ## S3 method for class 'mgNetwork' get_citation(x) ## S3 method for class 'mgNetworksCollection' get_citation(x)
x |
an object of class |
Bibtex entries as a character vector.
get_citation(mgNetwork): Get BibTeX entries for the publication associated to the network.
get_citation(mgNetworksCollection): Get BibTeX entries for the publication associated to the networks.
# network collection lagoon_net_collection <- get_collection(search_datasets("lagoon")) get_citation(lagoon_net_collection) # individual network mg_18 <- get_network_by_id(18) get_citation(mg_18)# network collection lagoon_net_collection <- get_collection(search_datasets("lagoon")) get_citation(lagoon_net_collection) # individual network mg_18 <- get_network_by_id(18) get_citation(mg_18)
Retrieve a set of networks based on the results of one of the search_*()
function. The function also accepts a numeric vector of Mangal network IDs.
get_collection(x, ...) ## Default S3 method: get_collection(x, ...) ## S3 method for class 'mgSearchDatasets' get_collection(x, ...) ## S3 method for class 'mgSearchNetworks' get_collection(x, ...) ## S3 method for class 'mgSearchReferences' get_collection(x, ...) ## S3 method for class 'mgSearchNodes' get_collection(x, ...) ## S3 method for class 'mgSearchTaxonomy' get_collection(x, ...) ## S3 method for class 'mgSearchInteractions' get_collection(x, ...)get_collection(x, ...) ## Default S3 method: get_collection(x, ...) ## S3 method for class 'mgSearchDatasets' get_collection(x, ...) ## S3 method for class 'mgSearchNetworks' get_collection(x, ...) ## S3 method for class 'mgSearchReferences' get_collection(x, ...) ## S3 method for class 'mgSearchNodes' get_collection(x, ...) ## S3 method for class 'mgSearchTaxonomy' get_collection(x, ...) ## S3 method for class 'mgSearchInteractions' get_collection(x, ...)
x |
|
... |
arguments to be passed on to |
Returns a object of class mgNetworksCollection which is a collection
(actually, a list) of mgNetwork objects get_network_by_id()).
get_collection(default): Get a collection of networks (default).
get_collection(mgSearchDatasets): Get a collection of networks from a mgSearchDatasets object.
get_collection(mgSearchNetworks): Get a collection of networks from a mgSearchNetworks object.
get_collection(mgSearchReferences): Get a collection of networks from a mgSearchReferences object.
get_collection(mgSearchNodes): Get a collection of networks from a mgSearchNodes object.
get_collection(mgSearchTaxonomy): Get a collection of networks from a mgSearchTaxonomy object.
get_collection(mgSearchInteractions): Get a collection of networks from a mgSearchInteractions object.
search_datasets(), search_interactions(), search_networks(),
search_nodes(), search_references(), search_taxonomy().
mg_2 <- get_collection(c(1076:1077)) mg_anemone <- get_collection(search_networks(query = "anemone%"))mg_2 <- get_collection(c(1076:1077)) mg_anemone <- get_collection(search_networks(query = "anemone%"))
Summarize mgNetwork properties.
Summarize mgNetworksCollection properties.
get_network_by_id(ids, as_sf = FALSE, force_collection = FALSE) get_network_by_id_indiv(id, as_sf = FALSE) ## S3 method for class 'mgNetwork' print(x, ...) ## S3 method for class 'mgNetworksCollection' print(x, n = 6, ...) ## S3 method for class 'mgNetwork' summary(object, ...) ## S3 method for class 'mgNetworksCollection' summary(object, ...)get_network_by_id(ids, as_sf = FALSE, force_collection = FALSE) get_network_by_id_indiv(id, as_sf = FALSE) ## S3 method for class 'mgNetwork' print(x, ...) ## S3 method for class 'mgNetworksCollection' print(x, n = 6, ...) ## S3 method for class 'mgNetwork' summary(object, ...) ## S3 method for class 'mgNetworksCollection' summary(object, ...)
ids |
a vector of Mangal identifier for networks ( |
as_sf |
a logical. Should networks metadata be converted into an sf
object? Note that to use this feature |
force_collection |
a logical. Should the output to be of class
|
id |
a single network identifier ( |
x |
an object of class |
... |
ignored. |
n |
maximum number of networks to display. |
object |
object of class |
A mgNetwork object includes five data frames:
network: includes all generic information on the network (if as_sf=TRUE
then it is an object of class sf);
nodes: information pertaining to nodes (includes taxonomic information);
interactions: includes ecological interactions and their attributes;
dataset: information pertaining to the original dataset;
reference: details about the original publication.
A summary method is available for objects of class mgNetwork object and
returns the following network properties:
the number of nodes;
the number of edges;
the connectance;
the linkage density;
the degree (in, out an total) and the eigenvector centrality of every nodes.
get_network_by_id_indiv(): Retrieve an individual network by its
identifier.
net18 <- get_network_by_id(id = 18) net18_c <- get_network_by_id(id = 18, force_collection = TRUE) nets <- get_network_by_id(id = c(18, 23))net18 <- get_network_by_id(id = 18) net18_c <- get_network_by_id(id = 18, force_collection = TRUE) nets <- get_network_by_id(id = c(18, 23))
Mangal API's endpoints
rmangal_endpointsrmangal_endpoints
A data frame with 2 columns and 1 row per endpoint.
These functions send a request to a specified endpoint of the Mangal API.
rmangal_request(endpoint, query = NULL, limit = 100, cache = FALSE, ...) rmangal_request_singleton(endpoint, id, cache = FALSE, ...)rmangal_request(endpoint, query = NULL, limit = 100, cache = FALSE, ...) rmangal_request_singleton(endpoint, id, cache = FALSE, ...)
endpoint |
A character string specifying the API endpoint to query.
Must be one of the endpoints listed in |
query |
Either a character string for a keyword search, or a named list
for custom queries. If |
limit |
An integer specifying the maximum number of results per page. Default is 100. |
cache |
Logical or character. If |
... |
Additional arguments (currently ignored). |
id |
An integer or character specifying the unique identifier of the resource to retrieve. Must be a single value. |
An object of class mgGetResponses containing the response body
and the raw HTTP response(s).
An object of class mgGetResponses containing the response body
and the raw HTTP response.
rmangal_request(): Send a request to a specified endpoint of the
Mangal API and returns all matching results.
rmangal_request_singleton(): Retrieves a single resource by its ID from a
specified endpoint of the Mangal API.
# Search for networks with keyword "insect" result <- rmangal_request("network", query = "insect", limit = 10) # Custom query for a specific dataset result <- rmangal_request("network", query = list(dataset_id = 19)) # Retrieve network with ID 5013 result <- rmangal_request_singleton("network", id = 5013)# Search for networks with keyword "insect" result <- rmangal_request("network", query = "insect", limit = 10) # Custom query for a specific dataset result <- rmangal_request("network", query = list(dataset_id = 19)) # Retrieve network with ID 5013 result <- rmangal_request_singleton("network", id = 5013)
Identify relevant datasets using a keyword or a custom query.
If the query is a character string, then all character columns in the table
are searched and the entries for which at least one
partial match was found are returned. Alternatively, a named list can be
used to look for an exact match in a specific column (see Details section).
search_datasets(query, ...)search_datasets(query, ...)
query |
either a character string including a single keyword or a named list containing a custom query (see details section below). Note that if an empty character string is passed, then all available entries are returned. |
... |
Additional arguments passed to |
If query is a named list, the name used should be one of the following:
id: unique identifier of the dataset
name: name of the dataset
date: date (YYYY-mm-dd) of the corresponding publication
description: a brief description of the dataset
ref_id: the Mangal identifier of the dataset
Note that for lists with more than one element, only the first element is used, the others are ignored. Examples covering custom queries are provided below.
An object of class mgSearchDatasets, which basically is a data.frame
object including all datasets corresponding to the query. For each dataset
entry, the networks and the original reference are attached.
# Return all datasets (takes time) # all_datasets <- search_datasets("") # all_datasets # class(all_datasets) # Search with keyword mg_lagoon <- search_datasets(query = "lagoon") # Search with a custom query (specific column) mg_kemp <- search_datasets(query = list(name = "kemp_1977")) mg_16 <- search_datasets(query = list(ref_id = 16))# Return all datasets (takes time) # all_datasets <- search_datasets("") # all_datasets # class(all_datasets) # Search with keyword mg_lagoon <- search_datasets(query = "lagoon") # Search with a custom query (specific column) mg_kemp <- search_datasets(query = list(name = "kemp_1977")) mg_16 <- search_datasets(query = list(ref_id = 16))
Search for specific interactions using a keyword or a specific type of
interactions (e.g. mutualism). If the query is a character string, then
all character columns in the table are searched and the entries for which at
least one partial match was found are returned.
Alternatively, a named list can be used to look for an exact match in a
specific column (see Details).
search_interactions(query, type = NULL, expand_node = FALSE, ...)search_interactions(query, type = NULL, expand_node = FALSE, ...)
query |
either a character string including a single keyword or a named list containing a custom query (see details section below). Note that if an empty character string is passed, then all available entries are returned. |
type |
a |
expand_node |
a logical. Should the function returned extra information
pertaining to nodes? Default is set to |
... |
Additional arguments passed to |
Names of the list should match one of the column names within the table.
For the interaction table, those are:
id: unique identifier of the interaction;
attr_id: identifier of a specific attribute;
direction: edge direction ("directed", "undirected" or "unknown");
network_id: Mangal network identifier;
node_from: node id which the interaction originates;
node_to: node to which the interaction goes;
type: use argument type instead.
Note that for lists with more than one element, only the first element is
used, the others are ignored. The type of interactions (argument type)
currently available are the following
"competition";
"amensalism";
"neutralism";
"commensalism";
"mutualism";
"parasitism";
"predation";
"herbivory";
"symbiosis";
"scavenger";
"detritivore".
An object of class mgSearchInteractions, i.e. a data.frame object
including interactions.
All networks in which interactions are involved are also attached to the
data.frame.
df_inter <- search_interactions(type = "competition") # Get all networks containing competition competition_networks <- get_collection(df_inter) df_net_926 <- search_interactions(list(network_id = 926))df_inter <- search_interactions(type = "competition") # Get all networks containing competition competition_networks <- get_collection(df_inter) df_net_926 <- search_interactions(list(network_id = 926))
Search over all networks using a keyword, a custom query or a spatial object
If the query is a character string, then all character columns in the table
are searched and the entries for which at least one
partial match was found are returned.
Alternatively, a named list can be used to look for an exact match in a
specific column (see 'Details' section).
search_networks(query, ...) search_networks_sf(query_sf, ...)search_networks(query, ...) search_networks_sf(query_sf, ...)
query |
either a character string including a single keyword or a named
list containing a custom query (see details section below), or a spatial
object (see the description of |
... |
Further arguments passed to |
query_sf |
a spatial object of class |
Names of the list should match one of the column names within the table.
For the networks table, those are
id: unique identifier of the network;
all_interactions: false interaction can be considered as real false interaction
dataset_id: the identifier of the dataset;
public: network publicly available;
Note that for lists with more than one element, only the first element is used, the others are ignored. An example is provided below.
An object of class mgSearchNetworks, which is a data.frame object with
all networks information.
search_networks_sf(): Search networks within a spatial object passed
as an argument. Note that sf must be installed to use this function.
mg_insect <- search_networks(query = "insect%") # Retrieve the search results nets_insect <- get_collection(mg_insect) # Spatial query if (requireNamespace("sf", quietly = TRUE)) { area <- sf::st_read(system.file("shape/nc.shp", package = "sf")) networks_in_area <- search_networks_sf(area) plot(networks_in_area) } else { cli::cli_warn("Package sf is missing") } # Retrieve network ID 5013 net_5013 <- search_networks(query = list(id = 5013)) # Network(s) of dataset ID 19 mg_19 <- search_networks(list(dataset_id = 19))mg_insect <- search_networks(query = "insect%") # Retrieve the search results nets_insect <- get_collection(mg_insect) # Spatial query if (requireNamespace("sf", quietly = TRUE)) { area <- sf::st_read(system.file("shape/nc.shp", package = "sf")) networks_in_area <- search_networks_sf(area) plot(networks_in_area) } else { cli::cli_warn("Package sf is missing") } # Retrieve network ID 5013 net_5013 <- search_networks(query = list(id = 5013)) # Network(s) of dataset ID 19 mg_19 <- search_networks(list(dataset_id = 19))
Search for networks by querying the nodes table.
If the query is a character string, then all character columns in the table
are searched and the entries for which at least one
partial match was found are returned.
Alternatively, a named list can be used to look for an exact match in a
specific column (see Details section)
search_nodes(query, ...)search_nodes(query, ...)
query |
either a character string including a single keyword or a named list containing a custom query (see details section below). Note that if an empty character string is passed, then all available entries are returned. |
... |
Additional arguments passed to |
Names of the list should match one of the column names within the table.
For the nodes table, those are:
id: unique identifier of the nodes;
original_name: taxonomic name as in the original publication;
node_level: either population, taxon or individual;
network_id: Mangal network identifier.
Note that for lists with more than one element, only the first element is used, the others are ignored. An example is provided below.
An object of class mgSearchNodes, which basically is a data.frame object
including taxa that are matching the query and corresponding information.
All networks in which taxa are involved are also attached to the data.frame.
res_acer <- search_nodes("Acer") res_926 <- search_nodes(list(network_id = 926))res_acer <- search_nodes("Acer") res_926 <- search_nodes(list(network_id = 926))
Search for a specific reference using a keyword or a Digital Object
Identifier (DOI).
If the query is a character string, then all character columns in the table
are searched and the entries for which at least one
partial match was found are returned.
Alternatively, a named list can be used to look for an exact match in a
specific column (see Details section).
search_references(query, doi = NULL, ...)search_references(query, doi = NULL, ...)
query |
either a character string including a single keyword or a named list containing a custom query (see details section below). Note that if an empty character string is passed, then all available entries are returned. |
doi |
|
... |
Additional arguments passed to |
Names of the list should match one of the column names within the table.
For the reference table, those are:
id: unique identifier of the reference
first_author: first author
doi: use doi instead
jstor: JSTOR identifier
year: year of publication.
Note that for lists with more than one element, only the first element is used, the others are ignored. An example is provided below.
An object of class mgSearchReferences, which is a list that includes a
wide range of details associated to the reference, including all datasets
and networks related to the publication that are included in Mangal database.
search_references(doi = "10.2307/3225248") search_references(list(jstor = 3683041)) search_references(list(year = 2001))search_references(doi = "10.2307/3225248") search_references(list(jstor = 3683041)) search_references(list(year = 2001))
Search network by taxon names and unique taxonomic identifiers.
This function offers the opportunity to retrieve taxon based on (i) known
identifier such as the taxonomic serial number (TSN), GBIF ID etc. or (ii)
text search using partial match. Have a look at the list of arguments to see
the complete list of identifiers accessible. If any unique identifier
argument is used (i.e. tsn etc.), then query is ignored. Moreover, if
several taxonomic identifiers are specified, then only the first one is
considered.
search_taxonomy( query, tsn = NULL, gbif = NULL, eol = NULL, col = NULL, bold = NULL, ncbi = NULL, ... )search_taxonomy( query, tsn = NULL, gbif = NULL, eol = NULL, col = NULL, bold = NULL, ncbi = NULL, ... )
query |
a character string including a single keyword. Note that if an empty character string is passed, then all datasets available are returned. |
tsn |
a |
gbif |
a |
eol |
a |
col |
a |
bold |
a |
ncbi |
a |
... |
Further arguments passed to |
Taxon names of the taxonomy table were validated with
TNRS (see https://tnrs.biendata.org) and/or GNR
(see https://resolver.globalnames.org/). The taxon names in this table
might not be the taxon name documented in the original publication.
In order to identify relevant networks with the original name, use
search_nodes().
The validation of taxon names was performed by an automated procedure and if there is any doubt, the original names recorded by authors should be regarded as the most reliable information. Please report any issue related to taxonomy at https://github.com/mangal-interactions/contribute/issues/new/choose/.
An object of class mgSearchTaxonomy, which is a data.frame including
all taxa matching the query.
search_taxonomy("Acer") # Retrieve higher classification tsn_acer <- search_taxonomy("Acer")$taxonomy.tsnsearch_taxonomy("Acer") # Retrieve higher classification tsn_acer <- search_taxonomy("Acer")$taxonomy.tsn