Skip to contents

What is GPSA?

GPSA (Gene-set Perturbation Signature Analysis) provides fast similarity search over large-scale perturbation signature databases using cMAP/GSEA-style rankZ semantics.

Given a query gene set, GPSA finds perturbations (e.g., gene knockouts, drug treatments) that produce similar or opposite transcriptomic effects. This enables:

  • Drug repurposing (find compounds that reverse a disease signature)
  • Mechanism discovery (identify genes whose perturbation mimics your phenotype)
  • Cross-study comparison (compare your results against public databases)

Installation

Install GPSA from GitHub:

# Install remotes if needed
if (!requireNamespace("remotes", quietly = TRUE)) {
  install.packages("remotes")
}

# Install GPSA from GitHub
remotes::install_github("Shipeng-Guo/GPSA")

Optional Dependencies

# For GSEA visualization (recommended)
if (!requireNamespace("BiocManager", quietly = TRUE)) {
  install.packages("BiocManager")
}
BiocManager::install("fgsea")

# For MSigDB gene sets (used in examples)
install.packages("msigdbr")

# For advanced plotting
install.packages("ggplot2")

First-time Setup: HDF5 Database

GPSA requires a pre-built HDF5 database containing perturbation signatures. Download the database file and set its path:

library(GPSA)

# Set path once (persists for session)
options(GPSA.h5 = "/path/to/gpsa_db.h5")

# Alternative: environment variable
# Sys.setenv(GPSA_H5 = "/path/to/gpsa_db.h5")

Loading the Database

GPSA offers two loading modes:

library(GPSA)

# Memory mode (recommended): ~0.15s per query, ~1GB RAM
db <- gpsa_load_db(preload_Z = TRUE, verbose = TRUE)
#> Preloading /Z into memory ...
#> Preloaded /Z (1062.9 MB) into RAM; subsequent queries avoid disk I/O.
#> Loaded DB: 19613 genes x 7103 signatures; Z_definition=cmap_rankZ_qnorm

# Disk mode: ~7s per query, minimal RAM
# db <- gpsa_load_db(preload_Z = FALSE)

print(db)
#> GPSA Database
#>   Genes: 19613
#>   Signatures: 7103
#>   H5 file: /mnt/e/wsl_projects/GPSA_projects/GPSA/output/gpsa_rankZ_logFC_optimized.h5
#>   Memory preloaded: Yes

Example 1: Estrogen Response (Suppressed)

Let’s find perturbations that suppress estrogen signaling. We’ll use the Hallmark Estrogen Response Early gene set from MSigDB.

library(msigdbr)

# Get Hallmark gene sets for human
hallmark <- msigdbr(species = "Homo sapiens", category = "H")
#> Warning: The `category` argument of `msigdbr()` is deprecated as of msigdbr 10.0.0.
#> ℹ Please use the `collection` argument instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

# Helper function to extract genes
get_hallmark_genes <- function(gs_name) {
  unique(hallmark$gene_symbol[hallmark$gs_name == gs_name])
}

# Get estrogen response genes
er_genes <- get_hallmark_genes("HALLMARK_ESTROGEN_RESPONSE_EARLY")
message(sprintf("Estrogen Response Early: %d genes", length(er_genes)))
#> Estrogen Response Early: 200 genes

Query for Estrogen Suppression

To find perturbations that suppress estrogen signaling, we use sign = -1:

# Define query: negative sign means we want perturbations where these genes go DOWN
query_er_down <- list(
  ER_SUPPRESSED = list(
    genes = er_genes,
    sign = -1,      # Looking for suppression
    weight = 1
  )
)

# Run search
out_er <- gpsa_search(db, query_er_down, return_components = TRUE)

# View top hits (perturbations that suppress estrogen response)
message("=== Top 10 Estrogen Suppressors ===")
#> === Top 10 Estrogen Suppressors ===
print(head(out_er$res[, c("signature_id", "pbgene", "CellLineName", 
                          "Score", "tau", "FDR_rank")], 10))
#>      signature_id pbgene CellLineName    Score      tau  FDR_rank
#> 4225       D24251  RBM39         MCF7 19.36561 99.98592 0.5000000
#> 3594       D23272 PIEZO1   MDA-MB-330 18.81724 99.95776 0.7500000
#> 2104       D21447   ESR1         MCF7 17.46870 99.92961 0.8333333
#> 3567       D23236   RAC1         MCF7 17.09327 99.90145 0.8750000
#> 3592       D23270 PIEZO1      HCC1428 15.91381 99.87329 0.9000000
#> 871        D20053 SMURF1         MCF7 14.33602 99.84514 0.9166667
#> 1898       D21221 ZNF213         MCF7 13.83765 99.81698 0.9285714
#> 1076       D20290  EP300         MCF7 13.76578 99.78882 0.9375000
#> 2025       D21362   AREG         MCF7 13.41164 99.76066 0.9444444
#> 3718       D23452 TRIM46         MCF7 13.11166 99.73251 0.9500000

Validate with GSEA Plot

# Get the logFC profile of the top hit
top_hit <- out_er$res$signature_id[1]
gl_top <- gpsa_get_signature(db, top_hit, dataset = "logFC")

# Plot GSEA running enrichment
gpsa_plot_gsea(gl_top, er_genes, 
               main = paste0(top_hit, " vs Estrogen Response Early"))
GSEA plot showing estrogen response genes enriched at the bottom (suppressed) in the top hit.

GSEA plot showing estrogen response genes enriched at the bottom (suppressed) in the top hit.

A negative enrichment score confirms that estrogen response genes are indeed down-regulated in this perturbation.

Example 2: Interferon Response (Activated)

Now let’s find perturbations that activate interferon signaling.

# Get interferon alpha response genes
ifn_genes <- get_hallmark_genes("HALLMARK_INTERFERON_ALPHA_RESPONSE")
message(sprintf("Interferon Alpha Response: %d genes", length(ifn_genes)))
#> Interferon Alpha Response: 97 genes

Query for Interferon Activation

To find perturbations that activate interferon signaling, we use sign = +1:

# Define query: positive sign means we want perturbations where these genes go UP
query_ifn_up <- list(
  IFN_ACTIVATED = list(
    genes = ifn_genes,
    sign = +1,      # Looking for activation
    weight = 1
  )
)

# Run search
out_ifn <- gpsa_search(db, query_ifn_up, return_components = TRUE)

# View top hits (perturbations that activate interferon response)
message("=== Top 10 Interferon Activators ===")
#> === Top 10 Interferon Activators ===
print(head(out_ifn$res[, c("signature_id", "pbgene", "CellLineName",
                           "Score", "tau", "FDR_rank")], 10))
#>      signature_id  pbgene CellLineName    Score      tau  FDR_rank
#> 5192       D25835  IFNLR1         A549 24.06465 99.98592 0.5000000
#> 5193       D25836  IFNLR1         A549 23.75224 99.95776 0.7500000
#> 1790       D21102    BTF3         PC-3 23.36150 99.92961 0.8333333
#> 4040       D23964    IMP3      HUVEC-C 23.05692 99.90145 0.8750000
#> 4041       D23965   PRKDC      HUVEC-C 22.50206 99.87329 0.9000000
#> 6441       D27531 SUV39H1         HMLE 22.34768 99.84514 0.9166667
#> 4136       D24114  HOTAIR        hASCs 22.22728 99.81698 0.9285714
#> 5852       D26728    LDHB         A549 22.18994 99.78882 0.9375000
#> 4331       D24432   SRSF7  RPTEC/TERT1 22.12325 99.76066 0.9444444
#> 4332       D24433   SRSF7  RPTEC/TERT1 22.11143 99.73251 0.9500000

Validate with GSEA Plot

# Get the logFC profile of the top hit
top_ifn <- out_ifn$res$signature_id[1]
gl_ifn <- gpsa_get_signature(db, top_ifn, dataset = "logFC")

# Plot GSEA running enrichment
gpsa_plot_gsea(gl_ifn, ifn_genes,
               main = paste0(top_ifn, " vs Interferon Alpha Response"))
GSEA plot showing interferon response genes enriched at the top (activated) in the top hit.

GSEA plot showing interferon response genes enriched at the top (activated) in the top hit.

A positive enrichment score confirms that interferon response genes are up-regulated.

Understanding the Results

The result table contains:

Column Description
signature_id Unique identifier for the perturbation
pbgene Perturbed gene name
CellLineName Cell line where perturbation was performed
Score Raw similarity score (higher = more similar to query)
tau Normalized score (percentile rank, -100 to +100)
p_rank Rank-based p-value
FDR_rank False discovery rate

Interpreting tau scores: - tau > 90: Strong positive connection (similar to query) - tau < -90: Strong negative connection (opposite of query) - tau ~ 0: No significant connection

Next Steps

This tutorial covered single gene set queries. GPSA supports many more advanced features:

Session Info

sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.2 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: Asia/Shanghai
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] msigdbr_25.1.1 GPSA_0.1.0    
#> 
#> loaded via a namespace (and not attached):
#>  [1] Matrix_1.6-4        babelgene_22.9      jsonlite_1.8.8     
#>  [4] highr_0.10          crayon_1.5.2        dplyr_1.1.4        
#>  [7] compiler_4.3.2      tidyselect_1.2.0    stringr_1.5.1      
#> [10] rhdf5filters_1.14.1 assertthat_0.2.1    jquerylib_0.1.4    
#> [13] systemfonts_1.0.5   textshaping_0.3.7   yaml_2.3.8         
#> [16] fastmap_1.1.1       lattice_0.22-5      R6_2.5.1           
#> [19] generics_0.1.3      curl_5.2.0          knitr_1.45         
#> [22] tibble_3.2.1        desc_1.4.3          bslib_0.6.1        
#> [25] pillar_1.9.0        rlang_1.1.2         utf8_1.2.4         
#> [28] cachem_1.0.8        stringi_1.8.3       xfun_0.41          
#> [31] fs_1.6.3            sass_0.4.8          memoise_2.0.1      
#> [34] cli_3.6.2           withr_2.5.2         pkgdown_2.0.7      
#> [37] magrittr_2.0.3      Rhdf5lib_1.24.1     digest_0.6.33      
#> [40] grid_4.3.2          rhdf5_2.46.1        lifecycle_1.0.4    
#> [43] vctrs_0.6.5         evaluate_0.23       glue_1.6.2         
#> [46] ragg_1.2.7          fansi_1.0.6         rmarkdown_2.25     
#> [49] purrr_1.0.2         pkgconfig_2.0.3     tools_4.3.2        
#> [52] htmltools_0.5.7