Running Enrichr in python using a background gene list
1
0
Entering edit mode
15 months ago
Jen ▴ 80

I am trying to run Enrichr in python using a background gene list as per https://gseapy.readthedocs.io/en/latest/gseapy_example.html (2.3.2.2. Enrichr Web Service (with background input)). I got the following to work without specifying a background:

enr_bg = gp.enrichr(gene_list="3383CCGs.txt",
                 gene_sets=['KEGG_2019_Mouse'],
                 outdir=None
                )

But then I try add the background argument to the script and it doesn't work:

enr_bg_back_KEGG = gp.enrichr(gene_list="3383CCGs.txt",
                 gene_sets=['KEGG_2019_Mouse'],
                background="Background13569.txt",
                 outdir=None,
                )

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [23], in <cell line: 1>()
----> 1 enr_bg_back_KEGG = gp.enrichr(gene_list="3383CCGs.txt",
      2                  gene_sets=['KEGG_2019_Mouse'],
      3                 background="Background13569.txt",
      4                  outdir=None,
      5                 )

TypeError: enrichr() got an unexpected keyword argument 'background'

Any ideas on how to input the background list into the command??

gp.enrichr python Enrichr • 1.3k views
ADD COMMENT
0
Entering edit mode
15 months ago
bk11 ★ 3.0k

This is for human though. I just tested and it works fine. Please make sure to provide correct path to your gene_list and background

enr_bg = gp.enrichr(gene_list="gene_list.txt",
                 gene_sets=['MSigDB_Hallmark_2020','KEGG_2021_Human'],
                 # organism='human', # organism argment is ignored because user input a background
                 background= "all_human_genes.txt", #"hsapiens_gene_ensembl",
                 outdir=None, # don't write to disk
                )
enr_bg.results.head()
        Gene_set    Term    P-value Adjusted P-value    Old P-value Old adjusted P-value    Odds Ratio  Combined Score  Genes
0   MSigDB_Hallmark_2020    TNF-alpha Signaling via NF-kB   8.934977e-16    2.233744e-14    0   0   8.597135    297.902671  BTG2;BCL2A1;PLEK;IRS2;LITAF;IFIH1;PANX1;DRAM1;...
1   MSigDB_Hallmark_2020    Complement  8.934977e-16    2.233744e-14    0   0   8.597135    297.902671  FCN1;LRP1;PLEK;LIPA;CA2;CASP3;LAMP2;S100A12;FY...
2   MSigDB_Hallmark_2020    IL-6/JAK/STAT3 Signaling    1.891480e-15    3.152466e-14    0   0   15.259576   517.321263  IL4R;TGFB1;IL1R1;IFNGR1;IL10RB;ITGB3;IFNGR2;IL...
3   MSigDB_Hallmark_2020    Inflammatory Response   4.938414e-13    6.173017e-12    0   0   7.479140    211.933110  LYN;IFITM1;BTG2;IL4R;CD82;IL1R1;IFNGR2;ITGB3;F...
4   MSigDB_Hallmark_2020    heme Metabolism 3.693816e-12    3.693816e-11    0   0   7.116750    187.343901  SLC22A4;MPP1;BNIP3L;BTG2;ARHGEF12;NEK7;GDE1;FO...
ADD COMMENT
0
Entering edit mode

Paths are correct. I have no idea why it's not working. Very strange. Maybe it's something to do with it being mouse? Don't know why that should make a difference.

ADD REPLY
0
Entering edit mode

It should work no matter what species it is. I saw your corresponding R code in other POST. Please so spend some time in basic R and Python; you will get there.

Selecting MOUSE gene set libraries in Enrichr

ADD REPLY
0
Entering edit mode

The reason it was not working is because I had a previous version of gseapy installed (0.9.5) which does not allow use of background gene list. I upgraded gseapy to version '1.0.6' and it worked to solve my issue.

ADD REPLY

Login before adding your answer.

Traffic: 1553 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6