import_network: Import an undirected interaction network

View source: R/import-network-matrix.R

import_networkR Documentation

Import an undirected interaction network

Description

Read a global undirected network from a tabular edge list, import a square adjacency matrix, or normalize a supported network object. Reciprocal and duplicate edges are collapsed and self-links are removed. When scored duplicate rows disagree, a warning reports their count and examples. The highest edge score is retained, or the highest absolute score when an absolute-value selector is used. The selected source edge-score column becomes the single canonical igraph weight attribute or adjacency-aligned legacy weights. In a user-supplied scored table, a source score of zero is interpreted as no edge and skipped. Existing network objects and curated adapters preserve zero edge weights.

Usage

import_network(
  source,
  from_column = 1L,
  to_column = 2L,
  score_column = NULL,
  min_score = NULL,
  n_top = NULL,
  greedy = TRUE,
  header = FALSE,
  sep = "\t",
  comment_char = "",
  case_sensitive = FALSE,
  verbose = TRUE,
  output_network_format = c("igraph", "sparse", "legacy"),
  species,
  input_id_format = master_id_format(species),
  id_mappings = NULL,
  ambiguous = c("error", "drop", "first", "expand"),
  unmapped = c("keep", "drop", "error"),
  is_matrix = FALSE,
  min_abs_score = NULL,
  n_abs_top = NULL
)

Arguments

source

File path, URL, connection, matrix, data frame, or supported network object.

from_column, to_column

Names or one-based indices of edge endpoint columns.

score_column

Optional name or one-based index of the source edge score column. Its numeric values are stored as edge weights. If NULL, imported edges are unweighted.

min_score

Optional minimum retained edge score.

n_top

Optional number of highest-scoring unique edges to retain.

greedy

Boundary-tie policy used with n_top or n_abs_top. The default, TRUE, includes every edge tied at the selection boundary; FALSE keeps only edges strictly above it; and NULL returns exactly the requested number of edges by filling the tie in alphanumeric canonical-endpoint order. Use greedy = NULL when equal network sizes are required for consistent benchmarks.

header

Whether a text source has a header row. Ignored for a matrix or data frame.

sep

Field separator used for text sources. Ignored for a matrix or data frame.

comment_char

Comment marker used for text sources. The default disables comment processing. Ignored for a matrix or data frame.

case_sensitive

Preserve case when matching node identifiers.

verbose

Report the imported node and edge counts.

output_network_format

Return an igraph, sparse, or legacy NEArender network.

species

Required species identifier. Accepts any scientific/common name, package species ID, three-letter KEGG style organism ID, or taxonomy ID listed by available_id_formats(). Use explicit NULL only for unsupported species or non-biological data.

input_id_format

Submitted identifier format. Defaults to master_id_format() for species; non-master input must name a format listed by available_id_formats(). Required when species = NULL.

id_mappings

Optional object from load_id_mappings(). When supplied, both endpoints are converted to its species master format.

ambiguous, unmapped

Mapping policies passed to map_identifiers().

is_matrix

Treat source as a square undirected adjacency matrix rather than as a tabular edge list. Row and column names must be identical and non-empty, and the matrix must be symmetric. Its values become edge weights; the diagonal is ignored and zero off-diagonal entries are treated as absent edges. from_column, to_column, and score_column may be omitted or explicitly set to NULL in this mode.

min_abs_score

Optional minimum retained absolute edge score. This is useful for signed adjacency matrices such as correlation matrices. The signed value is preserved as the edge weight.

n_abs_top

Optional number of unique edges with the highest absolute scores to retain. Signed edge weights are preserved. The greedy boundary-tie policy also applies to this option. Only one of min_score, min_abs_score, n_top, and n_abs_top may be supplied.

Details

An edge weight is stored metadata; it is not automatically a transition probability. Renderers such as rwr.render() and pagerank.render() use topology alone unless use_edge_weights = TRUE. A transition probability is derived, when requested, by normalizing the non-negative outgoing edge weights.

NEArender does not create directed networks. With is_matrix = TRUE, source must therefore be a symmetric adjacency matrix. Asymmetric matrices are rejected rather than interpreted as directed networks. For dense matrices, edge-score filtering is applied while the matrix is scanned, so excluded cells are never materialized as edge rows. Top-N selection uses bounded chunks to determine its score boundary first. After a matrix import, temporary edge tables are collected. On Linux systems using glibc, free allocator pages are also returned to the operating system so repeated imports do not retain their peak RSS.

Pathway Commons aggregates interaction evidence from multiple curated resources and records supporting publications for most edges. The catalogued pathwaycommons_hgnc adapter derives a PubMed-count edge score: the number of distinct supporting publications plus a 0.5 pseudocount. Relations without a linked PubMed record therefore remain edges with weight 0.5. With load_network_database(), min_score = 1.5 requires at least one publication and min_score = 2.5 requires at least two.

Value

A checked and normalized undirected igraph object by default, a sparse network, or a named-adjacency-list network. Weighted igraph output has one numeric weight edge attribute; sparse output stores binary adjacency separately from weights; legacy output stores named adjacency-aligned weights. Identifier and repair metadata are available through normalization_info().

See Also

available_databases(), load_network_database(), read_network(), export_network(), convert_network()

Examples

edges <- data.frame(from = c("A", "B", "B"), to = c("B", "A", "C"),
  score = c(0.8, 0.9, 0.7))
import_network(edges, "from", "to", "score", verbose = FALSE,
  species = "human")
correlation <- matrix(c(0, 0.8, -0.4, 0.8, 0, 0.2, -0.4, 0.2, 0),
  nrow = 3, dimnames = list(c("A", "B", "C"), c("A", "B", "C")))
import_network(correlation, is_matrix = TRUE, min_abs_score = 0.4,
  verbose = FALSE, species = NULL, input_id_format = "custom")
import_network(correlation, is_matrix = TRUE, n_abs_top = 2,
  greedy = NULL, verbose = FALSE, species = NULL,
  input_id_format = "custom")

NEArender documentation built on Nov. 28, 2026, 5:10 p.m.