GSEApy plot TypeError
3
2
Entering edit mode
6 months ago
Emily ▴ 70

I'm using GSEApy to do my enrichment analysis. I sorted my pre_res based on nes. I was trying to get GSEA plot for the first term, which is the most enriched. The most enriched was 'Mitotic G2/M Transition Checkpoint (GO:0044818)'. Here is the code I attempted to generate the plot

gseaplot(pre_res.ranking,
         term='Mitotic G2/M Transition Checkpoint (GO:0044818)',
         **pre_res.results['Mitotic G2/M Transition Checkpoint (GO:0044818)'])

It gave me an error message saying this:

TypeError                                 Traceback (most recent call last)
Cell In[53], line 2
      1 # GSEA Plot
----> 2 gseaplot(pre_res.ranking,
      3          term='Mitotic G2/M Transition Checkpoint (GO:0044818)',
      4          **pre_res.results['Mitotic G2/M Transition Checkpoint (GO:0044818)'])

TypeError: gseaplot() got multiple values for argument 'term'

I even looked at the documentation but I'm not sure why it is giving me TypeError. Do I need to add something in the term=? Any help is much appreciated. Thank you.

gsea python DEG • 830 views
ADD COMMENT
1
Entering edit mode
6 months ago
Mark ★ 1.5k

There's something odd with your syntax. This is odd:

**pre_res.results['Mitotic G2/M Transition Checkpoint (GO:0044818)']

** only works in functions (kwargs). To unpack an object use *object.

Looking at this example:

# or use this to have more control on the plot
# from gseapy import gseaplot2
# terms = pre_res.res2d.Term[1:5]
# hits = [pre_res.results[t]['hits'] for t in terms]
# runes = [pre_res.results[t]['RES'] for t in terms]
# fig = gseaplot2(terms=terms, ress=runes, hits=hits,
#               rank_metric=gs_res.ranking,
#               legend_kws={'loc': (1.2, 0)}, # set the legend loc
#               figsize=(4,5)) # rank_metric=pre_res.ranking

If you want to specify many term then you need to provide the input as a list. The easiest way to do this is like this:

terms=['Mitotic G2/M Transition Checkpoint (GO:0044818)',
'Mitotic G2/M Transition Checkpoint (GO:0044818)']

Note the use of square brackets [ and ] to create a list. This is a python short hand syntax.

Your code to run the plot should look like this:

gseaplot(pre_res.ranking, term=terms)

Hope that helps

ADD COMMENT
1
Entering edit mode
5 months ago
John ▴ 10

Maybe you can try this:

gseaplot(term='Mitotic G2/M Transition Checkpoint (GO:0044818)', **pre_res.results['Mitotic G2/M Transition Checkpoint (GO:0044818)'])
ADD COMMENT

Login before adding your answer.

Traffic: 1606 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