Package: gsea-incontext
GSEA-InContext: Gene Set Enrichment Analysis In ContextGene 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 ofGSEApy(original documentationhere. We have added a new toolGSEA_InContextwhich 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-InContextCurrently, 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 theincontextsubcommand. Additional subcommands can be run as in the original GSEApy, including:gsea,prerank,ssgsea,replotenrichr. See the originalGSEApy <https://github.com/BioNinja/GSEApy>_ repository.The fullGSEAis described in:GSEAdocumentation. All file formats for GSEApy are identical toGSEAdesktop version.Data & AvailabilityThe data, results and analysis described inour preprintare hosted in a Synapse project availablehere(doi:10.7303/syn11804693).Dependencies & RequirementsPython 3.4+Numpy >= 1.13.0PandasMatplotlibBeautifulsoup4Requests (for enrichr API)You may also need to install lxml and html5lib to parse xml files.Running GSEApy and GSEA-InContextBefore you start:Convert all gene symbol names to uppercase. The ranked lists input toprerankorincontextcan be supplied as file paths (.rnk) or a two-column Pandas DataFrame (columnsgene_nameandfold_change). The background ranked lists input toincontextis 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 themake_background_dist()function.Run GSEAPY inside Python console:| Running GSEAPreranked and GSEA-InContext in Python using file paths as inputimport 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 inrun_example.py. The full analysis of Kegg and Hallmarks gene sets was run withrun_all_442.py.Bug ReportsIf you would like to report any bugs when you running theincontextmodule, please create an issue on GitHubhere. For issues relating to other modules, you may wish to visit theoriginal GSEAPY repo.