Package: gseapy
GSEApy: Gene Set Enrichment Analysis in Python.Release notes:https://github.com/zqfang/GSEApy/releasesTutorial for scRNA-seq datasetsTutorial for general usageCitationZhuoqing Fang, Xinyuan Liu, Gary Peltz, GSEApy: a comprehensive package for performing gene set enrichment analysis in Python,
Bioinformatics, 2022;, btac757, https://doi.org/10.1093/bioinformatics/btac757GSEApy is a Python/Rust implementation forGSEAand wrapper forEnrichr.GSEApy can be used forRNA-seq, ChIP-seq, Microarraydata. It can be used for convenient GO enrichment and to producepublication quality figuresin python.GSEApy has 7 sub-commands available:gsea,prerank,ssgsea,gsva,replotenrichr,biomart.gsea:Thegseamodule producesGSEAresults.  The input requries a txt file(FPKM, Expected Counts, TPM, et.al), a cls file, and gene_sets file in gmt format.prerank:Theprerankmodule producesPrerank toolresults.  The input expects a pre-ranked gene list dataset with correlation values, provided in .rnk format, and gene_sets file in gmt format.prerankmodule is an API toGSEApre-rank tools.ssgsea:Thessgseamodule performssingle sample GSEA(ssGSEA)analysis.  The input expects a pd.Series (indexed by gene name), or a pd.DataFrame (includeGCTfile) with expression values and aGMTfile. For multiple sample input, ssGSEA reconigzes gct format, too. ssGSEA enrichment score for the gene set is described byD. Barbie et al 2009.gsva:Thegsvamodule performsGSVAmethod byHänzelmann et al. The input is same to ssgsea.replot:Thereplotmodule reproduce GSEA desktop version results.  The only input for GSEApy is the location toGSEADesktop output results.enrichr:Theenrichrmodule enable you perform gene set enrichment analysis usingEnrichrAPI. Enrichr is open source and freely available online at:http://amp.pharm.mssm.edu/Enrichr. It runs very fast.biomart:Thebiomartmodule helps you convert gene ids using BioMart API.Please use ‘gseapy COMMAND -h’ to see the detail description for each option of each module.The fullGSEAis far too extensive to describe here; seeGSEAdocumentation for more information. All files’ formats for GSEApy are identical toGSEAdesktop version.Why GSEApyI would like to use Pandas to explore my data, but I did not find a convenient tool to
do gene set enrichment analysis in python. So, here are my reasons:Ability to run inside python interactive console without having to switch to R!!!User friendly for both wet and dry lab users.Produce or reproduce publishable figures.Perform batch jobs easy.Easy to use in bash shell or your data analysis workflow, e.g. snakemake.GSEApy vs GSEA(Broad) outputUsing the same data forGSEAPreranked, andGSEApyreproduce similar results.See more output here:ExampleInstallationInstall gseapy package from bioconda or pip.# if you have conda (MacOS_x86-64 and Linux only)$condainstall-cbiocondagseapy# Windows and MacOS_ARM64(M1/2-Chip)$pipinstallgseapyIf pip install failed, use# you need to install rust first to compile the codecurlhttps://sh.rustup.rs-sSf|sh-s---y# export rust compilerexportPATH="$PATH:$HOME/.cargo/bin"# install$pipinstallgit+git://github.com/zqfang/gseapy.git#egg=gseapyDependencyPython 3.7+MandatorybuildRust: For gseapy > 0.11.0, Rust compiler is neededsetuptools-rustrunNumpy >= 1.13.0ScipyPandasMatplotlibRequestsRun GSEApyFor command line usage:# An example to reproduce figures using replot module.$gseapyreplot-i./Gsea.reports-otest# An example to run GSEA using gseapy gsea module$gseapygsea-dexptable.txt-ctest.cls-ggene_sets.gmt-otest# An example to run Prerank using gseapy prerank module$gseapyprerank-rgsea_data.rnk-ggene_sets.gmt-otest# An example to run ssGSEA using gseapy ssgsea module$gseapyssgsea-dexpression.txt-ggene_sets.gmt-otest# An example to run GSVA using gseapy ssgsea module$gseapygsva-dexpression.txt-ggene_sets.gmt-otest# An example to use enrichr api
# see details for -g input -> ``get_library_name``$gseapyenrichr-igene_list.txt-gKEGG_2016-otestRun gseapy inside python console:Prepare expression.txt, gene_sets.gmt and test.cls required by GSEA, you could do thisimportgseapy# run GSEA.gseapy.gsea(data='expression.txt',gene_sets='gene_sets.gmt',cls='test.cls',outdir='test')# run prerankgseapy.prerank(rnk='gsea_data.rnk',gene_sets='gene_sets.gmt',outdir='test')# run ssGSEAgseapy.ssgsea(data="expression.txt",gene_sets="gene_sets.gmt",outdir='test')# run GSVAgseapy.gsva(data="expression.txt",gene_sets="gene_sets.gmt",outdir='test')# An example to reproduce figures using replot module.gseapy.replot(indir='./Gsea.reports',outdir='test')If you prefer to use Dataframe, dict, list in interactive python console, you could do this.see detail here:Example# assign dataframe, and use enrichr library data set 'KEGG_2016'expression_dataframe=pd.DataFrame()sample_name=['A','A','A','B','B','B']# always only two group,any names you like# assign gene_sets parameter with enrichr library name or gmt file on your local computer.gseapy.gsea(data=expression_dataframe,gene_sets='KEGG_2016',cls=sample_names,outdir='test')# prerank toolgene_ranked_dataframe=pd.DataFrame()gseapy.prerank(rnk=gene_ranked_dataframe,gene_sets='KEGG_2016',outdir='test')# ssGSEAgseapy.ssgsea(data=expression_dataframe,gene_sets='KEGG_2016',outdir='test')# gsvagseapy.gsva(data=expression_dataframe,gene_sets='KEGG_2016',outdir='test')Forenrichr, you could assign a list, pd.Series, pd.DataFrame object, or a txt file (should be one gene name per row.)# assign a list object to enrichrgl=['SCARA3','LOC100044683','CMBL','CLIC6','IL13RA1','TACSTD2','DKKL1','CSF1','SYNPO2L','TINAGL1','PTX3','BGN','HERC1','EFNA1','CIB2','PMP22','TMEM173']gseapy.enrichr(gene_list=gl,gene_sets='KEGG_2016',outdir='test')# or a txt file path.gseapy.enrichr(gene_list='gene_list.txt',gene_sets='KEGG_2016',outdir='test',cutoff=0.05,format='png')GSEApy supported gene set libaries :To see the full list of gseapy supported gene set libraries, please click here:LibraryOr useget_library_namefunction inside python console.#see full list of latest enrichr library names, which will pass to -g parameter:names=gseapy.get_library_name()# show top 20 entries.print(names[:20])['Genome_Browser_PWMs','TRANSFAC_and_JASPAR_PWMs','ChEA_2013','Drug_Perturbations_from_GEO_2014','ENCODE_TF_ChIP-seq_2014','BioCarta_2013','Reactome_2013','WikiPathways_2013','Disease_Signatures_from_GEO_up_2014','KEGG_2016','TF-LOF_Expression_from_GEO','TargetScan_microRNA','PPI_Hub_Proteins','GO_Molecular_Function_2015','GeneSigDB','Chromosome_Location','Human_Gene_Atlas','Mouse_Gene_Atlas','GO_Cellular_Component_2015','GO_Biological_Process_2015','Human_Phenotype_Ontology',]Dev# test rust extension onlycargotest--features=extension-module# test whole packagepythonsetup.pytestBug ReportIf you would like to report any bugs when use gseapy, don’t hesitate to create an issue on github here.To get help of GSEApySeeFrequently Asked QuestionsVisit the document site atExamplesThe GSEApy discussion channel:Q&A