Skip to main content

GSEA-InContext Gene Set Enrichment Analysis in Python

Project description

GSEA-InContext: Gene Set Enrichment Analysis In Context

Gene Set Enrichment Analysis (GSEA) is routinely used to analyze and interpret coordinate changes in transcriptomics experiments. For an experiment where less than seven samples per condition are compared, GSEA employs a competitive null hypothesis to test significance. A gene set enrichment score is tested against a null distribution of enrichment scores generated from permuted gene sets, where genes are randomly selected from the input experiment. Looking across a variety of biological conditions, however, genes are not randomly distributed with many showing consistent patterns of up- or down-regulation. As a result, common patterns of positively and negatively enriched gene sets are observed across experiments. Placing a single experiment into the context of a relevant set of background experiments allows us to identify both the common and experiment-specific patterns of gene set enrichment. We developed the GSEA-InContext method to allow a user to account for gene expression patterns within a defined background set of experiments to identify statistically significantly enriched gene sets in their own experiment.

See below for examples on running the GSEA-InContext algorithm.

This repo is a fork of GSEApy (original documentation here. We have added a new tool GSEA_InContext which runs the GSEAPreranked algorithm but uses a background set of ranked lists to calculate an empirical null distribution for informing the permutation procedure. For examples using the original GSEApy library, visit this page.

About GSEA-InContext

Currently, there are no methods available for a user to easily compare their GSEA results to GSEA results obtained in other experiments to discern similar and/or distinct patterns affected across experiments. GSEA-InContext accounts for gene-specific variation estimated from an experimental background. Whereas GSEA identifies all signiificantly enriched gene sets in an experiment, this method allows the user to ask a complementary question; namely, which gene sets are uniquely enriched in a single experiment compared to many other, independent experiments.

Our method applies the same approach as GSEA to calculate the nominal p-value. However, in contrast to GSEAPreranked, GSEA-InContext employs an alternative significance testing procedure to generate the null distribution, in which permuted gene sets are generated using the density of gene ranks estimated from a set of user-defined background experiments. We estimate a gene's probability density using a Gaussian kernel over the experiments in the background set.

The GSEA-InContext algorithm can be run using the incontext subcommand. Additional subcommands can be run as in the original GSEApy, including: gsea, prerank, ssgsea, replot enrichr. See the original GSEApy <https://github.com/BioNinja/GSEApy>_ repository.

The full GSEA is described in: GSEA documentation. All file formats for GSEApy are identical to GSEA desktop version.

Data & Availability

The data, results and analysis described in our preprint are hosted in a Synapse project available here(doi:10.7303/syn11804693).

Dependencies & Requirements

  • Python 3.4+
  • Numpy >= 1.13.0
  • Pandas
  • Matplotlib
  • Beautifulsoup4
  • Requests (for enrichr API)

You may also need to install lxml and html5lib to parse xml files.

Running GSEApy and GSEA-InContext

Before you start:

Convert all gene symbol names to uppercase. The ranked lists input to prerank or incontext can be supplied as file paths (.rnk) or a two-column Pandas DataFrame (columns gene_name and fold_change). The background ranked lists input to incontext is supplied as a text file containing the list of .rnk files to use in permutation, or as a .csv file containing pre-permuted gene lists created with the make_background_dist() function.

Run GSEAPY inside Python console:

| Running GSEAPreranked and GSEA-InContext in Python using file paths as input


    import gseapy

    # Run GSEA Prerank
    gseapy.prerank(rnk='gsea_data.rnk', gene_sets='gene_sets.gmt', outdir='out')

    # Run GSEA-InContext
    gseapy.incontext(rnk='gsea_data.rnk', gene_sets='gene_sets.gmt', backround_rnks = 'permuted_background.csv', outdir='out')

A full example can be seen in run_example.py. The full analysis of Kegg and Hallmarks gene sets was run with run_all_442.py.

Bug Reports

If you would like to report any bugs when you running the incontext module, please create an issue on GitHub here. For issues relating to other modules, you may wish to visit theoriginal GSEAPY repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gsea_incontext_notk-0.1.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

gsea_incontext_notk-0.1.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file gsea_incontext_notk-0.1.0.tar.gz.

File metadata

  • Download URL: gsea_incontext_notk-0.1.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.0

File hashes

Hashes for gsea_incontext_notk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 32124eacbdb3babbe57948fa79d7066a6fee0f805e81207dad953aa1ff4ecc6d
MD5 3fb7e0e2b24a612996d2d1f4bb67dafb
BLAKE2b-256 58d808c4369c36daa86f0e964223a4d838e4c7fd3b24c7d92e7b81b815ebcd9d

See more details on using hashes here.

File details

Details for the file gsea_incontext_notk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gsea_incontext_notk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.0

File hashes

Hashes for gsea_incontext_notk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de74ea1f63ff833e3ce21c7c7e858417511b5a268607f4d975742d76fc1aaeb5
MD5 d3dab01e6e8491f67bf10c18b94828b1
BLAKE2b-256 8eca4d3ef9de5c014d907e29d0a7eec6d96068952b23fe853bada9d7416e0b05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page