Introduction to pathfindR

Ege Ulgen


pathfindR is a tool for enrichment analysis via active subnetworks. The package also offers functionality to cluster the enriched terms and identify representative terms in each cluster, to score the enriched terms per sample and to visualize analysis results.

The functionality suite of pathfindR is described in detail in Ulgen E, Ozisik O, Sezerman OU. 2019. pathfindR: An R Package for Comprehensive Identification of Enriched Pathways in Omics Data Through Active Subnetworks. Front. Genet.


The observation that motivated us to develop pathfindR was that direct enrichment analysis of differential RNA/protein expression or DNA methylation results may not provide the researcher with the full picture. That is to say: enrichment analysis of only a list of significant genes alone may not be informative enough to explain the underlying disease mechanisms. Therefore, we considered leveraging interaction information from a protein-protein interaction network (PIN) to identify distinct active subnetworks and then perform enrichment analyses on these subnetworks.

An active subnetwork can be defined as a group of interconnected genes in a PIN that predominantly consists of significantly altered genes. In other words, active subnetworks define distinct disease-associated sets of interacting genes, whether discovered through the original analysis or discovered because of being in interaction with a significant gene.

The active-subnetwork-oriented enrichment analysis approach of pathfindR can be summarized as follows: Mapping the input genes with the associated p values onto the PIN (after processing the input), active subnetwork search is performed. The resulting active subnetworks are then filtered based on their scores and the number of significant genes they contain. This filtered list of active subnetworks are then used for enrichment analyses, i.e. using the genes in each of the active subnetworks, the significantly enriched terms (pathways/gene sets) are identified. Enriched terms with adjusted p values larger than the given threshold are discarded and the lowest adjusted p value (over all active subnetworks) for each term is kept. This process of active subnetwork search + enrichment analyses is repeated for a selected number of iterations, performed in parallel. Over all iterations, the lowest and the highest adjusted-p values, as well as number of occurrences over all iterations are reported for each significantly enriched term in the resulting data frame. This active-subnetwork-oriented enrichment approach is demonstrated in the section Active-subnetwork-oriented Enrichment Analysis of this vignette.

The enrichment analysis usually yields a great number of enriched terms whose biological functions are related. Therefore, we implemented two clustering approaches using a pairwise distance matrix based on the kappa statistics between the enriched terms (as proposed by Huang et al. 1). Based on this distance metric, the user can perform either hierarchical (default) or fuzzy clustering of the enriched terms. Details of clustering and partitioning of enriched terms are presented in the Clustering Enriched Terms section of this vignette.

Other functionality of pathfindR includes:

Active-subnetwork-oriented Enrichment Analysis

For convenience, we provide the wrapper function run_pathfindR() to be used for the active-subnetwork-oriented enrichment analysis. The input for this function must be a data frame consisting of the columns containing: Gene Symbols, Change Values (optional) and p values. The example data frame used in this vignette (example_pathfindR_input) is the dataset containing the differentially-expressed genes for the GEO dataset GSE15573 comparing 18 rheumatoid arthritis (RA) patients versus 15 healthy subjects.

The first 6 rows of the example input data frame are displayed below:

Gene.symbol logFC adj.P.Val
FAM110A -0.6939359 0.0000034
RNASE2 1.3535040 0.0000101
S100A8 1.5448338 0.0000347
S100A9 1.0280904 0.0002263
TEX261 -0.3235994 0.0002263
ARHGAP17 -0.6919330 0.0002708

For a detailed step-by-step explanation and an unwrapped demonstration of the active-subnetwork-oriented enrichment analysis, see the vignette Step-by-Step Execution of the pathfindR Enrichment Workflow

Executing the workflow is straightforward (but does typically take several minutes):

output_df <- run_pathfindR(example_pathfindR_input)

Useful arguments

This subsection demonstrates some (selected) useful arguments of run_pathfindR(). For a full list of arguments, see ?run_pathfindR or visit our GitHub wiki.

Filtering Input Genes

By default, run_pathfindR() uses the input genes with p-values < 0.05. To change this threshold, use p_val_threshold:

output_df <- run_pathfindR(example_pathfindR_input, p_val_threshold = 0.01)

Output Directory

By default, run_pathfindR() creates a temporary directory for writing the output files, including active subnetwork search results and a HTML report. To set the output directory, use output_dir:

output_df <- run_pathfindR(example_pathfindR_input, output_dir = "this_is_my_output_directory")

This creates "this_is_my_output_directory" under the current working directory.

In essence, this argument is treated as a path so it can be used to create the output directory anywhere. For example, to create the directory "my_dir" under "~/Desktop" and run the analysis there, you may run:

output_df <- run_pathfindR(example_pathfindR_input, output_dir = "~/Desktop/my_dir")

Note: If the output directory (e.g. "my_dir") already exists, run_pathfindR() creates and works under "my_dir(1)". If that exists also exists, it creates "my_dir(2)" and so on. This was intentionally implemented so that any previous pathfindR results are not overwritten.

Gene Sets for Enrichment

The active-subnetwork-oriented enrichment analyses can be performed on any gene sets (biological pathways, gene ontology terms, transcription factor target genes, miRNA target genes etc.). The available gene sets in pathfindR are “KEGG”, “Reactome”, “BioCarta”, “GO-All”, “GO-BP”, “GO-CC” and “GO-MF” (all for Homo sapiens). For changing the default gene sets for enrichment analysis (hsa KEGG pathways), use the argument gene_sets

output_df <- run_pathfindR(example_pathfindR_input, gene_sets = "GO-MF")

By default, run_pathfindR() filters the gene sets by including only the terms containing at least 10 and at most 300 genes. To change the default behavior, you may change min_gset_size and max_gset_size:

## Including more terms for enrichment analysis
output_df <- run_pathfindR(example_pathfindR_input,
  gene_sets = "GO-MF",
  min_gset_size = 5,
  max_gset_size = 500

Note that increasing the number of terms for enrichment analysis may result in significantly longer run time.

If the user prefers to use another gene set source, the gene_sets argument should be set to "Custom" and the custom gene sets (list) and the custom gene set descriptions (named vector) should be supplied via the arguments custom_genes and custom_descriptions, respectively. See ?fetch_gene_set for more details and Analysis with Custom Gene Sets for a simple demonstration.

For details on obtaining organism-specific Gene Sets and PIN data, see the vignette Obtaining PIN and Gene Sets Data.

Filtering Enriched Terms by Adjusted-p Values

By default, run_pathfindR() adjusts the enrichment p values via the “bonferroni” method and filters the enriched terms by adjusted-p value < 0.05. To change this adjustment method and the threshold, set adj_method and enrichment_threshold, respectively:

output_df <- run_pathfindR(example_pathfindR_input,
  adj_method = "fdr",
  enrichment_threshold = 0.01

Protein-protein Interaction Network

For the active subnetwork search process, a protein-protein interaction network (PIN) is used. run_pathfindR() maps the input genes onto this PIN and identifies active subnetworks which are then be used for enrichment analyses. To change the default PIN (“Biogrid”), use the pin_name_path argument:

output_df <- run_pathfindR(example_pathfindR_input, pin_name_path = "IntAct")

The pin_name_path argument can be one of “Biogrid”, “STRING”, “GeneMania”, “IntAct”, “KEGG”, “mmu_STRING” or it can be the path to a custom PIN file provided by the user.

# to use an external PIN of your choice
output_df <- run_pathfindR(example_pathfindR_input, pin_name_path = "/path/to/myPIN.sif")

NOTE: the PIN is also used for generating the background genes (in this case, all unique genes in the PIN) during hypergeometric-distribution-based tests in enrichment analyses. Therefore, a large PIN will generally result in better results.

Active Subnetwork Search Method

Currently, there are three algorithms implemented in pathfindR for active subnetwork search: Greedy Algorithm (default, based on Ideker et al. 2), Simulated Annealing Algorithm (based on Ideker et al. 3) and Genetic Algorithm (based on Ozisik et al. 4). For a detailed discussion on which algorithm to use see this wiki entry

# for simulated annealing:
output_df <- run_pathfindR(example_pathfindR_input, search_method = "SA")
# for genetic algorithm:
output_df <- run_pathfindR(example_pathfindR_input, search_method = "GA")

Other Arguments

Because the active subnetwork search algorithms are stochastic, run_pathfindR() may be set to iterate the active subnetwork identification and enrichment steps multiple times (by default 1 time). To change this number, set iterations:

output_df <- run_pathfindR(example_pathfindR_input, iterations = 25)

run_pathfindR() uses a parallel loop (using the package foreach) for performing these iterations in parallel. By default, the number of processes to be used is determined automatically. To override, change n_processes:

# if not set, `n_processes` defaults to (number of detected cores - 1)
output_df <- run_pathfindR(example_pathfindR_input, iterations = 5, n_processes = 2)


Enriched Terms Data Frame

run_pathfindR() returns a data frame of enriched terms. Columns are:

  • ID: ID of the enriched term
  • Term_Description: Description of the enriched term
  • Fold_Enrichment: Fold enrichment value for the enriched term (Calculated using ONLY the input genes)
  • occurrence: The number of iterations that the given term was found to enriched over all iterations
  • lowest_p: the lowest adjusted-p value of the given term over all iterations
  • highest_p: the highest adjusted-p value of the given term over all iterations
  • non_Signif_Snw_Genes (OPTIONAL): the non-significant active subnetwork genes, comma-separated (controlled by list_active_snw_genes, default is FALSE)
  • Up_regulated: the up-regulated genes (as determined by change value > 0, if the change column was provided) in the input involved in the given term’s gene set, comma-separated. If change column was not provided, all affected input genes are listed here.
  • Down_regulated: the down-regulated genes (as determined by change value < 0, if the change column was provided) in the input involved in the given term’s gene set, comma-separated

The first 2 rows of the output data frame of the example analysis on the rheumatoid arthritis gene-level differential expression input data (example_pathfindR_input) is shown below:

knitr::kable(head(example_pathfindR_output, 2))
ID Term_Description Fold_Enrichment occurrence support lowest_p highest_p Up_regulated Down_regulated
hsa05415 Diabetic cardiomyopathy 3.333277 10 0.0452452 0 0.0000000 NCF4, MMP9, NDUFA1, NDUFB3, UQCRQ, COX6A1, COX7A2, COX7C, GAPDH ATP2A2, MTOR, PDHA1, PDHB, VDAC1, SLC25A5, PARP1
hsa04130 SNARE interactions in vesicular transport 4.772647 10 0.0143519 0 0.0011701 STX6 STX2, BET1L, SNAP23

By default, run_pathfindR() also produces a graphical summary of enrichment results for top 10 enriched terms, which can also be later produced by enrichment_chart():

You may also disable plotting this chart by setting plot_enrichment_chart=FALSE and later produce this plot via the function enrichment_chart():

# change number of top terms plotted (default = 10)
  result_df = example_pathfindR_output,
  top_terms = 15

HTML Report (created when output_dir is set)

The function also creates an HTML report results.html that is saved in the output directory if it’s set. This report contains links to two other HTML files:

1. enriched_terms.html

This document contains the table of the active subnetwork-oriented enrichment results (same as the returned data frame).

2. conversion_table.html

This document contains the table of converted gene symbols. Columns are:

  • Old Symbol: the original gene symbol
  • Converted Symbol: the alias symbol that was found in the PIN
  • Change: the provided change value
  • p-value: the provided adjusted p value

During input processing, gene symbols that are not in the PIN are identified and excluded. For human genes, if aliases of these missing gene symbols are found in the PIN, these symbols are converted to the corresponding aliases (controlled by the argument convert2alias). This step is performed to best map the input data onto the PIN.

The document contains a second table of genes for which no interactions were identified after checking for alias symbols (so these could not be used during the analysis).

Enriched Term Diagrams

For H.sapiens KEGG enrichment analyses, visualize_terms() can be used to generate KEGG pathway diagrams that are saved as PNG files in a directory called “term_visualizations” under the current working directory:

input_processed <- input_processing(example_pathfindR_input)
  result_df = example_pathfindR_output,
  input_processed = input_processed,
  hsa_KEGG = TRUE

Alternatively (i.e., for other types of non-KEGG/non-H.sapiens enrichment analyses), an interaction diagram per enriched term can be generated again via visualize_terms(). These diagrams are also saved as PNG files in a directory called “term_visualizations” under the current working directory:

input_processed <- input_processing(example_pathfindR_input)
  result_df = example_pathfindR_output,
  input_processed = input_processed,
  hsa_KEGG = FALSE,
  pin_name_path = "Biogrid"

Clustering Enriched Terms

The wrapper function cluster_enriched_terms() can be used to perform clustering of enriched terms and partitioning the terms into biologically-relevant groups. Clustering can be performed either via hierarchical or fuzzy method using the pairwise kappa statistics (a chance-corrected measure of co-occurrence between two sets of categorized data) matrix between all enriched terms.

Hierarchical Clustering

By default, cluster_enriched_terms() performs hierarchical clustering of the terms (using \(1 - \kappa\) as the distance metric). Iterating over \(2,3,...n\) clusters (where \(n\) is the number of terms), cluster_enriched_terms() determines the optimal number of clusters by maximizing the average silhouette width, partitions the data into this optimal number of clusters and returns a data frame with cluster assignments.

example_pathfindR_output_clustered <- cluster_enriched_terms(example_pathfindR_output, plot_dend = FALSE, plot_clusters_graph = FALSE)
## First 2 rows of clustered data frame
knitr::kable(head(example_pathfindR_output_clustered, 2))
ID Term_Description Fold_Enrichment occurrence support lowest_p highest_p Up_regulated Down_regulated Cluster Status
1 hsa05415 Diabetic cardiomyopathy 3.333277 10 0.0452452 0 0e+00 NCF4, MMP9, NDUFA1, NDUFB3, UQCRQ, COX6A1, COX7A2, COX7C, GAPDH ATP2A2, MTOR, PDHA1, PDHB, VDAC1, SLC25A5, PARP1 1 Representative
3 hsa00190 Oxidative phosphorylation 3.003128 10 0.0237693 0 1e-07 NDUFA1, NDUFB3, UQCRQ, COX6A1, COX7A2, COX7C, ATP6V1D, ATP6V0E1 ATP6V0E2 1 Member
## The representative terms
knitr::kable(example_pathfindR_output_clustered[example_pathfindR_output_clustered$Status == "Representative", ])
ID Term_Description Fold_Enrichment occurrence support lowest_p highest_p Up_regulated Down_regulated Cluster Status
1 hsa05415 Diabetic cardiomyopathy 3.333277 10 0.0452452 0.0000000 0.0000000 NCF4, MMP9, NDUFA1, NDUFB3, UQCRQ, COX6A1, COX7A2, COX7C, GAPDH ATP2A2, MTOR, PDHA1, PDHB, VDAC1, SLC25A5, PARP1 1 Representative
2 hsa04130 SNARE interactions in vesicular transport 4.772647 10 0.0143519 0.0000000 0.0011701 STX6 STX2, BET1L, SNAP23 2 Representative
5 hsa04714 Thermogenesis 2.563911 10 0.0286079 0.0000000 0.0000026 NDUFA1, NDUFB3, UQCRQ, COX6A1, COX7A2, COX7C ADCY7, CREB1, KDM1A, SMARCA4, ACTG1, ACTB, ARID1A, MTOR 3 Representative
9 hsa04921 Oxytocin signaling pathway 2.624956 10 0.0516402 0.0000001 0.0016542 MYL6B, MYL6 EEF2K, EEF2, CALM3, CALM1, NFATC3, ACTG1, ACTB, ADCY7 4 Representative
10 hsa04064 NF-kappa B signaling pathway 3.058201 10 0.0412376 0.0000002 0.0000002 LY96 PRKCQ, CARD11, TICAM1, IKBKB, PARP1, UBE2I, CSNK2A2 5 Representative
11 hsa03040 Spliceosome 3.854831 10 0.0148701 0.0000003 0.0000119 SF3B6, LSM3, BUD31 SNRPB, SF3B2, U2AF2, PUF60, SNU13, DDX23, EIF4A3, HNRNPA1, PCBP1, SRSF8, SRSF5 6 Representative
12 hsa03013 Nucleocytoplasmic transport 3.822751 10 0.0148148 0.0000011 0.0008081 NUP214 RANGAP1, UBE2I, SUMO3, NUP62, NUP93, TNPO1, EIF4A3, RNPS1, SRRM1 7 Representative
18 hsa04141 Protein processing in endoplasmic reticulum 1.458309 10 0.0160341 0.0000165 0.0000165 CKAP4, DDIT3 DDOST, EDEM1, PDIA4, UBE2G1 8 Representative
35 hsa00020 Citrate cycle (TCA cycle) 3.937434 10 0.0138410 0.0001922 0.0008873 MDH2, PDHA1, PDHB 9 Representative
43 hsa04110 Cell cycle 1.550171 10 0.0206188 0.0004008 0.0005321 RBL2, ABL1, HDAC1, CDKN1C, ANAPC1 10 Representative
49 hsa03010 Ribosome 1.837469 10 0.0068729 0.0005741 0.0483668 MRPS18C, RPS24, MRPL33, RPL26, RPL31, RPL39 RPLP2 11 Representative
51 hsa03050 Proteasome 1.749971 10 0.0074074 0.0006684 0.0018936 PSMD7, PSMB10 12 Representative
52 hsa03420 Nucleotide excision repair 4.279820 1 0.0050000 0.0007148 0.0007148 GTF2H5, POLE4 XPC, RPA1, POLD2 13 Representative
56 hsa03022 Basal transcription factors 4.374927 6 0.0065892 0.0008495 0.0059660 GTF2B, GTF2H5 TAF1L, TAF4, TAF15 14 Representative
64 hsa00270 Cysteine and methionine metabolism 4.921793 1 0.0100000 0.0013470 0.0013470 MAT2B, MRI1, DNMT1, AHCYL2, GOT1, MDH2 15 Representative
87 hsa00650 Butanoate metabolism 4.543193 1 0.0050000 0.0087153 0.0087153 HADH, ECHS1, HMGCL 16 Representative
88 hsa04144 Endocytosis 1.138927 1 0.0050000 0.0088568 0.0088568 AP2B1, VPS25, ASAP1 IST1, IL2RB, RAB11FIP3, ARF1 17 Representative
117 hsa03060 Protein export 1.789743 2 0.0058333 0.0300181 0.0300181 SRP54 18 Representative

After clustering, you may again plot the summary enrichment chart and display the enriched terms by clusters:

# plotting only selected clusters for better visualization
selected_clusters <- subset(example_pathfindR_output_clustered, Cluster %in% 5:7)
enrichment_chart(selected_clusters, plot_by_cluster = TRUE)
#> Plotting the enrichment bubble chart

For details, see ?hierarchical_term_clustering

Heuristic Fuzzy Multiple-linkage Partitioning

Alternatively, the fuzzy clustering method (as described by Huang et al.5) can be used:

clustered_fuzzy <- cluster_enriched_terms(example_pathfindR_output, method = "fuzzy")

For details, see ?fuzzy_term_clustering

Term-Gene Heatmap

The function term_gene_heatmap() can be used to visualize the heatmap of genes that are involved in the enriched terms. This heatmap allows visual identification of the input genes involved in the enriched terms, as well as the common or distinct genes between different terms. If the input data frame (same as in run_pathfindR()) is supplied, the tile colors indicate the change values.

term_gene_heatmap(result_df = example_pathfindR_output, genes_df = example_pathfindR_input)

See the vignette Visualization of pathfindR Enrichment Results for more details.

Term-Gene Graph

The visualization function term_gene_graph() (adapted from the “Gene-Concept network visualization” by the R package enrichplot) can be utilized to visualize which genes are involved in the enriched terms. The function creates a term-gene graph which shows the connections between genes and biological terms (enriched pathways or gene sets). This allows for the investigation of multiple terms to which significant genes are related. This graph also enables visual determination of the degree of overlap between the enriched terms by identifying shared and/or distinct significant genes.

term_gene_graph(result_df = example_pathfindR_output, use_description = TRUE)