trans_metab: Create 'trans_metab' object for metabolite analysis.

trans_metabR Documentation

Create trans_metab object for metabolite analysis.

Description

This class is a wrapper for a series of metabolite analysis, including origin inference and pathway enrichment.

Methods

Public methods


Method new()

Create the trans_metab object.

Usage
trans_metab$new(metab = NULL, microb = NULL)
Arguments
metab

default NULL; metabolite data. A microtable object or data.frame object. If the input is a data.frame object, the function can judge whether it is abundance table and preprocess the data.

microb

default NULL; A microtable object.

Returns

data_metab and data_microb stored in the object.

Examples
\donttest{
data(soil_metab)
data(soil_microb)
t1 <- trans_metab$new(metab = soil_metab, microb = soil_microb)
}

Method cal_match()

Matching compound names against the database from TidyMass2 (DOI: 10.1038/s41467-026-68464-7) to facilitate the acquisition of standardized nomenclature. An alternative way is to use MetaboAnalyst website (https://www.metaboanalyst.ca/faces/upload/ConvertView.xhtml).

Usage
trans_metab$cal_match(
  database_path = "./metorigindb_split_202602",
  method = "jw",
  maxDist = 0.3,
  ...
)
Arguments
database_path

default "./metorigindb_split_202602"; directory path of the downloaded database. Please download the pre-collated metorigindb database (RData format) from zenodo (https://zenodo.org/records/18618912) and extract the compressed archive.

method

default "jw"; method of approximate string matching. Default "jw" is Jaro-Winkler distance. See the method parameter of amatch function in stringdist package.

maxDist

default 0.3; See the maxDist parameter of amatch function in stringdist package.

...

parameters passed to amatch function of stringdist package.

Returns

res_match table stored in the object.

Examples
\dontrun{
t1$cal_match()
}

Method cal_origin()

Metabolite origin inference based on the preprocessed database from TidyMass2 (DOI: 10.1038/s41467-026-68464-7)

Usage
trans_metab$cal_origin(
  database_path = "./metorigindb_split_202602",
  match_col = "names",
  match_names_distance = 0,
  bac_level = "Genus"
)
Arguments
database_path

default "./metorigindb_split_202602"; directory path of the downloaded database. Please download the pre-collated metorigindb database (RData format) from zenodo (https://zenodo.org/records/18618912) and extract the compressed archive.

match_col

default "names"; How to match to the data of metorigindb. Default "names" means using the input names of metabolites. If the tax_table has other columns like "HMDB_ID" or "KEGG_ID", the user can provide more items, like c("names", "HMDB_ID"). The program will automatically identify the corresponding columns from the input data based on keywords such as HMDB or KEGG, and then match them with the database.

match_names_distance

default 0; distance threshold used if the res_match_table is found in the object, which is calculated from the cal_match function. Available for the "names" option in match_col parameter.

bac_level

default "Genus"; which bacteria level is used to parse the taxa in the data_microb of object. The function can automatically match the taxa those found in the input data.

Returns

res_origin_rawtable table and res_origin_list list stored in the object. res_origin_rawtable is the origin table extracted from the metorigindb database based on the match of name or other ID. In res_origin_list, name is the metabolite; each element is the taxa that may produce the metabolite.

Examples
\dontrun{
t1$cal_origin()
t1$cal_origin(match_col = c("names", "HMDB_ID", "KEGG_ID"))
}

Method cal_origin_network()

Metabolite-bacteria network based on the res_origin_list data from the cal_origin function

Usage
trans_metab$cal_origin_network()
Returns

igraph format network.

Examples
\dontrun{
t1$cal_origin_network()
}

Method cal_pathway()

Map metabolites to pathways based on a database (KEGG, MetaCyc, Reactome, or custom).

Usage
trans_metab$cal_pathway(
  db_type = c("kegg", "metacyc", "reactome", "custom")[1],
  db_path = NULL,
  id_type = NULL,
  save_db = FALSE
)
Arguments
db_type

default "kegg"; pathway database type, one of "kegg", "metacyc", "reactome", "custom".

db_path

default NULL; pathway database file path (RData format). For KEGG: if NULL, will attempt to fetch from KEGG REST API. For MetaCyc/Reactome/Custom: must provide local database file path.

id_type

default NULL; column name in tax_table containing metabolite IDs. If NULL, will be automatically set based on db_type: "KEGG_ID" for kegg, "METACYC_ID" for metacyc, "REACTOME_ID" for reactome, "CUSTOM_ID" for custom.

save_db

default FALSE; whether save the fetched database (KEGG) to the local folder.

Returns

res_pathway_map (data.frame) stored in the object. Contains columns: pathway_id, pathway_name, metab_id, metab_name.

Examples
\dontrun{
# KEGG pathway mapping (online)
t1$cal_pathway()

# KEGG pathway mapping (local database)
t1$cal_pathway(db_type = "kegg", db_path = "kegg_pathway_db.RData")
}

Method cal_pathway_enrich()

Perform pathway enrichment analysis for target metabolites using Fisher's exact test.

Usage
trans_metab$cal_pathway_enrich(
  target_metabs = NULL,
  background_metabs = NULL,
  p_adjust_method = "BH",
  p_cutoff = 0.05,
  min_metab_count = 3
)
Arguments
target_metabs

character vector; target metabolite names (row names in tax_table), e.g., differential metabolites. If NULL, will use all metabolites in the pathway mapping.

background_metabs

character vector; background metabolite names (row names in tax_table). If NULL, will use all metabolites in the pathway mapping result.

p_adjust_method

default "BH"; p-value adjustment method. See p.adjust function.

p_cutoff

default 0.05; significance threshold for adjusted p-value.

min_metab_count

default 3; minimum number of background metabolites in a pathway for enrichment test.

Returns

res_pathway_enrich data.frame stored in the object. Contains: pathway_id, pathway_name, metab_count, background_count, enrichment_factor, p_value, p_adjust, significant.

Examples
\dontrun{
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:10]
t1$cal_pathway_enrich(target_metabs = target)
}

Method plot_pathway_enrich()

Visualize pathway enrichment analysis results.

Usage
trans_metab$plot_pathway_enrich(
  plot_type = c("bubble", "bar")[1],
  top_n = 20,
  color_by = "p_adjust",
  size_by = "metab_count",
  order_by = "p_adjust",
  color_gradient_low = "#132B43",
  color_gradient_high = "#56B1F7"
)
Arguments
plot_type

default "bubble"; plot type, "bubble" or "bar".

top_n

default 20; number of top pathways to display.

color_by

default "p_adjust"; column name for color mapping.

size_by

default "metab_count"; column name for size mapping (only for bubble plot).

order_by

default "p_adjust"; column name for ordering pathways.

color_gradient_low

default "#132B43"; color for low values (e.g., high p-value = not significant).

color_gradient_high

default "#56B1F7"; color for high values (e.g., low p-value = significant).

Returns

ggplot2 object.

Examples
\dontrun{
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:10]
t1$cal_pathway_enrich(target_metabs = target)
t1$plot_pathway_enrich()
}

Method cal_pathway_network()

Build metabolite-pathway network based on pathway mapping and enrichment results.

Usage
trans_metab$cal_pathway_network(
  significant_only = TRUE,
  p_cutoff = 0.05,
  use_enrichment = TRUE
)
Arguments
significant_only

default TRUE; whether to use only significant enriched pathways.

p_cutoff

default 0.05; p-value cutoff for significant pathways (used only when significant_only = TRUE).

use_enrichment

default TRUE; whether to require enrichment results. If FALSE, build network from all pathway mappings.

Returns

igraph object representing metabolite-pathway bipartite network.

Examples
\dontrun{
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:50]
t1$cal_pathway_enrich(target_metabs = target)
net <- t1$cal_pathway_network()
}

Method clone()

The objects of this class are cloneable with this method.

Usage
trans_metab$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `trans_metab$new`
## ------------------------------------------------


data(soil_metab)
data(soil_microb)
t1 <- trans_metab$new(metab = soil_metab, microb = soil_microb)


## ------------------------------------------------
## Method `trans_metab$cal_match`
## ------------------------------------------------

## Not run: 
t1$cal_match()

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$cal_origin`
## ------------------------------------------------

## Not run: 
t1$cal_origin()
t1$cal_origin(match_col = c("names", "HMDB_ID", "KEGG_ID"))

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$cal_origin_network`
## ------------------------------------------------

## Not run: 
t1$cal_origin_network()

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$cal_pathway`
## ------------------------------------------------

## Not run: 
# KEGG pathway mapping (online)
t1$cal_pathway()

# KEGG pathway mapping (local database)
t1$cal_pathway(db_type = "kegg", db_path = "kegg_pathway_db.RData")

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$cal_pathway_enrich`
## ------------------------------------------------

## Not run: 
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:10]
t1$cal_pathway_enrich(target_metabs = target)

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$plot_pathway_enrich`
## ------------------------------------------------

## Not run: 
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:10]
t1$cal_pathway_enrich(target_metabs = target)
t1$plot_pathway_enrich()

## End(Not run)

## ------------------------------------------------
## Method `trans_metab$cal_pathway_network`
## ------------------------------------------------

## Not run: 
t1$cal_pathway()
target <- rownames(t1$data_metab$otu_table)[1:50]
t1$cal_pathway_enrich(target_metabs = target)
net <- t1$cal_pathway_network()

## End(Not run)

microeco documentation built on Oct. 20, 2026, 9:06 a.m.