Error with merge_result with dataframes using clusterprofiler
0
1
Entering edit mode
5.8 years ago
Vasu ▴ 790

I'm using clusterprofiler for pathway analysis for two datasets and want to plot the results both in same plot. I have seen an example to merge the results here from GuangchuangYu github

But here it is merging of enrichmentesults. In my case I have results in dataframes. Below I gave a n example of two dataframes A4 and B4

head(A4)

                             ID                   Description GeneRatio  BgRatio
1         HALLMARK_ADIPOGENESIS         HALLMARK_ADIPOGENESIS     10/60 200/4386
2  HALLMARK_ALLOGRAFT_REJECTION  HALLMARK_ALLOGRAFT_REJECTION     33/55 200/4386
3         HALLMARK_ANGIOGENESIS         HALLMARK_ANGIOGENESIS     9/105  36/4386
4      HALLMARK_APICAL_JUNCTION      HALLMARK_APICAL_JUNCTION       3/9 200/4386
5            HALLMARK_APOPTOSIS            HALLMARK_APOPTOSIS      7/54 161/4386
6 HALLMARK_BILE_ACID_METABOLISM HALLMARK_BILE_ACID_METABOLISM      3/10 112/4386
        pvalue     p.adjust       qvalue
1 3.172592e-04 4.230123e-03 3.784847e-03
2 2.161865e-31 3.675170e-30 2.275647e-30
3 1.005961e-07 1.911325e-06 1.694250e-06
4 6.398199e-03 2.559279e-02 2.020484e-02
5 3.261885e-03 3.914262e-02 3.204659e-02
6 1.706706e-03 2.218718e-02 1.616879e-02
                                                                                                                                                                                    geneID
1                                                                                                                            ALDOA/ANGPTL4/CMPK1/CYP4B1/ETFB/HSPB8/PPM1B/RIOK3/SLC19A1/UBC
2 CCL19/CCR2/CD2/CD247/CD28/CD3D/CD3E/CD3G/CD40/CD40LG/CD8A/CD96/CRTAM/CXCL13/CXCL9/CXCR3/FASLG/GZMA/GZMB/IL12RB1/IL16/IL18RAP/IL2RB/IL2RG/ITGAL/ITK/LCK/PRF1/PRKCB/SIT1/STAT4/TRAT1/ZAP70
3                                                                                                                                    CCND2/COL3A1/COL5A2/FSTL1/LUM/NRP1/POSTN/SLCO2A1/VCAN
4                                                                                                                                                                        DHX16/MAPK13/PBX2
5                                                                                                                                           CAV1/CDKN1A/FEZ1/GADD45A/IGFBP6/PLAT/TNFRSF12A
6                                                                                                                                                                     PEX6/SLC29A1/SLC35B2
  Count   
1    10        
2    33             
3     9        
4     3 
5     7            
6     3

head(B4)

                            ID                  Description GeneRatio  BgRatio
1        HALLMARK_ADIPOGENESIS        HALLMARK_ADIPOGENESIS      3/10 200/4386
2 HALLMARK_ALLOGRAFT_REJECTION HALLMARK_ALLOGRAFT_REJECTION     16/54 200/4386
3        HALLMARK_ANGIOGENESIS        HALLMARK_ANGIOGENESIS      4/99  36/4386
4     HALLMARK_APICAL_JUNCTION     HALLMARK_APICAL_JUNCTION       2/5 200/4386
5         HALLMARK_COAGULATION         HALLMARK_COAGULATION      8/70 138/4386
6          HALLMARK_COMPLEMENT          HALLMARK_COMPLEMENT     13/54 200/4386
        pvalue     p.adjust       qvalue
1 8.836224e-03 4.418112e-02 3.720515e-02
2 8.785433e-10 1.186033e-08 8.323041e-09
3 8.268709e-03 6.118844e-02 4.874186e-02
4 1.888702e-02 5.666106e-02 3.976215e-02
5 1.425831e-03 8.554987e-03 6.003500e-03
6 5.303804e-07 3.580067e-06 2.512328e-06
                                                                                    geneID
1                                                                        CD151/PFKL/TALDO1
2 CD1D/CD28/CD7/CD80/CD86/CSF1/CTSS/CXCL9/FCGR2B/GPR65/HLA-DMA/IGSF6/IL2RA/ITGB2/LCK/NLRP3
3                                                                     FSTL1/MSX1/NRP1/VCAN
4                                                                               CRAT/GNAI2
5                                                    ACOX2/C1R/C1S/C3/CTSB/F10/F3/SERPINA1
6        APOBEC3G/CASP1/CASP10/CTSS/DOCK10/GP1BA/IRF1/ITGAM/LCK/OLR1/PIK3CG/PIK3R5/TNFAIP3
  Count   
1     3        
2    16             
3     4        
4     2 
5     8             
6    13

I tried using the merge_result function but it gave me an error.

merge_result(list(Dataset1=A4, Dataset2=B4)) %>%
    plot(., showCategory=10)

Error in as.double(y) : 
  cannot coerce type 'S4' to vector of type 'double'

Is there a way to convert dataframe into enrichmentresult for plotting?

R clusterprofiler RNA-Seq enrichment • 3.2k views
ADD COMMENT
0
Entering edit mode

How did you obtain A4 & B4? What does class(A4) and class(B4) return?

ADD REPLY
0
Entering edit mode

After using enrichr function from clusterprofiler I saved the result in a dataframe.

class(A4) and class(B4) is "data.frame".

But I see that merge_result function from clusterprofiler uses only enrichmentresult for plotting.

ADD REPLY
0
Entering edit mode

So you got the answer - save them as original enrichmentresult object in a variable without coercing them as data.frame

ADD REPLY
3
Entering edit mode

Coercing a dataframe results again into enrichmentresult object is not possible I guess.

But Anyways from GuangchuangYu github I see an example showing Upregulated and downregulated dotplots side by side. So, I followed that.

First I created a new column Dataset in both dataframes A4 and B4.

A4$Dataset <- "Dataset1"
B4$Dataset <- "Dataset2"

I merged both the dataframes.

D <- merge(A4,B4, all=TRUE)

With the code mentioned in above link I used ggplot.

p <- ggplot(D, aes(x = Count, y = fct_reorder(ID, Count))) + 
  geom_point(aes(size = Count, color = p.adjust)) +
  theme_bw(base_size = 14) +
  scale_colour_gradient(limits=c(0, 0.10), low="red") +
  ylab(NULL) +
  ggtitle("Hallmark Genesets")

p + facet_grid(.~Dataset)

I got the plot like below.

Multiple dotplot in single plot

ADD REPLY

Login before adding your answer.

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