Skip to contents

Parses, filters, and caches the CTD chemical-gene interactions file so that it can be used by enrichment_CTD. This function must be called once before running any enrichment analysis.

The raw data file must be downloaded manually from the CTD website. The required file is CTD_chem_gene_ixns.csv.gz, available at https://ctdbase.org/reports/CTD_chem_gene_ixns.csv.gz.

Usage

import_CTD(file_path)

Arguments

file_path

Character. A local path or a URL to the CTD chemical-gene interactions file (CTD_chem_gene_ixns.csv or CTD_chem_gene_ixns.csv.gz). Remote URLs are downloaded and cached with BiocFileCache; the package assumes no default URL, so you supply the source and a one-time CTD data-licensing reminder is shown on first remote fetch.

Value

Invisible NULL. Called for its side effect of caching the processed data.

Details

Processing steps performed by import_CTD:

  1. Reads the CSV, skipping the 27 CTD header lines.

  2. Filters interactions to Homo sapiens only (OrganismID 9606).

  3. For each chemical, collects the associated Entrez gene IDs.

  4. Maps Entrez IDs to HGNC gene symbols via org.Hs.eg.db.

  5. Saves four cached objects via BiocFileCache: chemicals, ChemicalName_GeneEntrezIds, ChemicalName_GeneSymbols, and ctd_interactions (a long-format table of chemical–gene–action triples used by enrichment_CTD(interaction_types = ...)).

The cache is managed by BiocFileCache under tools::R_user_dir("ctdR", "cache"). To re-import (e.g. after downloading a newer CTD release), simply call import_CTD() again — existing cache resources are overwritten.

Filtering by interaction type (e.g., to retain only "increases^expression" interactions) is done at enrichment time via the interaction_types argument of enrichment_CTD, not here — so a single import supports any combination of filters without re-running this step.

Data Licensing Disclaimer

This package does not bundle or redistribute any CTD data. The Comparative Toxicogenomics Database is maintained by NC State University and its data are subject to specific licensing terms. Users are responsible for downloading the data directly from https://ctdbase.org and for complying with the CTD Terms of Service (https://ctdbase.org/about/legal.jsp). By using this function you acknowledge that you have read and accepted those terms.

See also

enrichment_CTD for running enrichment analysis after import, including the interaction_types filter.

Examples

# Examples write to a temporary cache, so running them cannot
# disturb CTD data you have already imported. Set the same option
# yourself to keep an analysis isolated from your main cache.
options(ctdR.cache = tempfile())

sample_file <- system.file(
    "extdata", "CTD_chem_gene_ixns_sample.csv",
    package = "ctdR"
)
import_CTD(sample_file)
#> Reading CTD chemical-gene interactions from: /home/runner/work/_temp/Library/ctdR/extdata/CTD_chem_gene_ixns_sample.csv
#> Filtered to 86 human interactions
#> Mapping genes for 10 chemicals...
#> Warning: 10 ChemicalID(s) appear with more than one ChemicalName in the CTD file; only the first name per ID is retained. Affected IDs: D000082, D001564, D002104, D003907, D004958 ... (and 5 more)
#> CTD data cached successfully in: /tmp/Rtmpt9pODL/file1b135ed75707
#>   10 chemicals | 17 unique genes | 0 s
#>   CTD release: Mon Jan 01 00:00:00 EST 2024