Deleted:How to use gseapy after scanpy?
0
0
Entering edit mode
8 weeks ago
bioinfo ▴ 50

Hello,

I analyzed some data using scanpy and now I want to do some pathway analysis.

I have done DE analysis between each cluster and the rest and I want to do the pathway analysis for each cluster but I have a few questions. I initially followed the instructions from here (https://nbisweden.github.io/workshop-scRNAseq/labs/compiled/scanpy/scanpy_05_dge.html) and did the enrichment and then I also wanted to do GSEA so I used gseapy.prerank. However, then I was trying to find a way to visualize the network so I ended up going to the gseapy documentation.

The steps of the enrichment analysis seemed the same but then I got confused with the GSEA portion. The first tutorial I found used gseapy.prerank but the second one uses gp.gsea. I was trying to understand the difference and it seems that since I already have the DE analysis I should be using the gseapy.prerank right? I tried to plot the network using the results for gseapy.prerank but I am having issues.

My two questions are:

1. How do I decide between using gs.prerank and gs.gsea?
2. Is the reason why I am having issues plotting the network the fact that I used the gs.prerank output?

Please see the code below.

Thank you

fig, ax = plt.subplots(figsize=(8, 8))
# init node cooridnates
pos=nx.layout.spiral_layout(G)
#node_size = nx.get_node_attributes()
# draw node
nx.draw_networkx_nodes(G,
pos=pos,
cmap=plt.cm.RdYlBu,
node_color=list(nodes.NES),
node_size=list(nodes.Hits_ratio *1000))
# draw node label
nx.draw_networkx_labels(G,
pos=pos,
labels=nodes.Term.to_dict())
# draw edge
edge_weight = nx.get_edge_attributes(G, 'jaccard_coef').values()
nx.draw_networkx_edges(G,
pos=pos,
width=list(map(lambda x: x*10, edge_weight)),
edge_color='#CDDBD4')
plt.show()


The error I am getting is :

KeyError                                  Traceback (most recent call last)
<ipython-input-162-f8b5069fd046> in <module>
10 node_size=list(nodes.Hits_ratio *1000))
11 # draw node label
---> 12 nx.draw_networkx_labels(G,
13 pos=pos,
14 labels=nodes.Term.to_dict())

/usr/local/lib/python3.8/dist-packages/networkx/drawing/nx_pylab.py in draw_networkx_labels(G, pos, labels, font_size, font_color, font_family, font_weight, alpha, bbox, horizontalalignment, verticalalignment, ax, clip_on)
1018     text_items = {}  # there is no text collection so we'll fake one
1019     for n, label in labels.items():
-> 1020         (x, y) = pos[n]
1021         if not isinstance(label, str):
1022             label = str(label)  # this makes "1" and 1 labeled the same

KeyError: 0

gsea single cell enrichR gseapy • 312 views