Dm-roX-codes / DEG_GO.ipynb
DEG_GO.ipynb
Raw
library(clusterProfiler)
library(org.Dm.eg.db)
library(dplyr)
library(ggplot2)

plotTheme = theme(
    axis.title = element_text(family = "Arial", face = "bold", size = 16),
    legend.title = element_text(family = "Arial", face = "bold", size = 16), 
    text = element_text(family = "Arial",size = 14))
clusterProfiler v4.6.2  For help: https://yulab-smu.top/biomedical-knowledge-mining-book/

If you use clusterProfiler in published research, please cite:
T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou, W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu. clusterProfiler 4.0: A universal enrichment tool for interpreting omics data. The Innovation. 2021, 2(3):100141


Attaching package: ‘clusterProfiler’


The following object is masked from ‘package:stats’:

    filter


Loading required package: AnnotationDbi

Loading required package: stats4

Loading required package: BiocGenerics


Attaching package: ‘BiocGenerics’


The following objects are masked from ‘package:stats’:

    IQR, mad, sd, var, xtabs


The following objects are masked from ‘package:base’:

    anyDuplicated, aperm, append, as.data.frame, basename, cbind,
    colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
    get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
    Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
    table, tapply, union, unique, unsplit, which.max, which.min


Loading required package: Biobase

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.


Loading required package: IRanges

Loading required package: S4Vectors


Attaching package: ‘S4Vectors’


The following object is masked from ‘package:clusterProfiler’:

    rename


The following objects are masked from ‘package:base’:

    expand.grid, I, unname



Attaching package: ‘IRanges’


The following object is masked from ‘package:clusterProfiler’:

    slice



Attaching package: ‘AnnotationDbi’


The following object is masked from ‘package:clusterProfiler’:

    select





Attaching package: ‘dplyr’


The following object is masked from ‘package:AnnotationDbi’:

    select


The following objects are masked from ‘package:IRanges’:

    collapse, desc, intersect, setdiff, slice, union


The following objects are masked from ‘package:S4Vectors’:

    first, intersect, rename, setdiff, setequal, union


The following object is masked from ‘package:Biobase’:

    combine


The following objects are masked from ‘package:BiocGenerics’:

    combine, intersect, setdiff, union


The following objects are masked from ‘package:stats’:

    filter, lag


The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union
anaGO = function(geneids,prefix){
    res = enrichGO(geneids,OrgDb = 'org.Dm.eg.db',keyType = 'ENTREZID',ont = 'ALL',readable = TRUE,maxGSSize = 300)
    if(!is.null(res)){
        write.csv(res@result,file = paste0('data/',prefix,'_GO.csv'))
        resTable = res@result[order(res@result$p.adjust),]
        resTable = resTable %>% group_by(ONTOLOGY) %>% top_n(-p.adjust,n = 10)
        p = ggplot(data = resTable,
                   aes(
                       x = reorder(Description,-p.adjust),
                       y = -log10(p.adjust),
                       fill = ONTOLOGY,
                       label = reorder(Count,-p.adjust)
                    )
            )+
            geom_bar(stat = 'identity')+
            geom_text(stat = 'identity',hjust = 1.2)+
            coord_flip()+
            facet_grid(ONTOLOGY~.,scales = 'free',space = 'free')+
            labs(x = '',fill = '')+
            theme_classic()+
            scale_fill_manual(
                breaks = c('BP','CC','MF'),
                labels = c('BP','CC','MF'),
                values = c('#ffc64b','#66CC33','#33ccff')
            )+
            theme(strip.text = element_blank(),
                  axis.line.y = element_blank(),
                  axis.ticks.y = element_blank(),
                  axis.title.x = element_text(size = 14),
                  text = element_text(size = 12),
                  axis.text = element_text(size = 12))+plotTheme
        ggsave(filename = paste0('pics/',prefix,'_GO.png'),plot = p,dpi = 300,width = 10,height = 8,bg = 'white')
        p
    }else{
        print(paste0('No GO terms enriched in ',prefix,'!!!!'))
    }
}
agingDEG = read.csv('data/aging_DEG.csv',header = TRUE,row.names = 1)
agingDEG
A data.frame: 9229 × 4
namespvals_adjlogfoldchangesstatus
<chr><dbl><dbl><chr>
0CG17224 0.000000e+001.6973903up
1Nazo 1.615661e-2492.8764238up
2CG32368 8.114678e-2462.3905106up
3Tsp42Ee 5.434852e-2242.2421365up
4Jupiter 4.728705e-1391.0476663up
5CG8620 4.454060e-1071.3999066up
6CG31324 1.315092e-1061.0036199up
7CG5910 3.305958e-951.2562097up
8CG17264 1.104081e-672.6234114up
9Nrt 7.987283e-671.1558428up
10Trx-2 1.364534e-650.4715681up
11hdly 8.152044e-610.9809336up
12CG5399 3.660944e-601.1431552up
13Tsp42Ed 2.051548e-470.4920316up
14pnt 6.444435e-440.7879507up
15CG18746 1.618540e-431.5451185up
16GstE6 6.619171e-420.7721213up
17Lmpt 9.531350e-420.6956778up
18CG13321 9.723534e-381.0427580up
19CG9801 1.103936e-351.0639198up
20CG6330 2.689387e-340.9662901up
21CG10383 1.122102e-320.4956225up
22GstD2 1.367670e-320.9692456up
23Cys 3.636264e-320.7153829up
24CG10140 8.949718e-321.9631165up
25Prosap 1.227746e-310.9397125up
26CG30460 1.398059e-310.4398054up
27PGRP-LB 1.624326e-310.4719896up
28mnb 2.575575e-310.3877865up
29l(1)G0193 3.537443e-300.5183096up
⋮⋮⋮⋮⋮
9199RpS15 0-0.3734362stable
9200RpS13 0-0.3945759down
9201RpL12 0-0.4025178down
9202RpS21 0-0.4593959down
9203RpL7 0-0.4154353down
9204RpL27 0-0.4279002down
9205RpS29 0-0.5267246down
9206sta 0-0.4334792down
9207RpL23 0-0.4408405down
9208RpS9 0-0.4727255down
9209RpL24 0-0.4231068down
9210RpL10Ab0-0.4069104down
9211RpL40 0-0.4460438down
9212RpL37A 0-0.4838491down
9213RpS28b 0-0.4849850down
9214RpL36 0-0.4457568down
9215RpL32 0-0.4167477down
9216RpL13A 0-0.4561919down
9217RpL14 0-0.4040156down
9218RpL27A 0-0.4384862down
9219RpS11 0-0.3979355down
9220RpS25 0-0.4061678down
9221RpL31 0-0.4973900down
9222RpL6 0-0.5047587down
9223RpS7 0-0.4620276down
9224RpL18A 0-0.4653904down
9225RpS27 0-0.5373447down
9226RpL29 0-0.7157094down
9227RpL41 0-0.7257034down
9228RpL39 0-0.8977373down
down = agingDEG$names[agingDEG$status=='down']
geneTmp = bitr(down,fromType = 'SYMBOL',toType = 'ENTREZID',OrgDb = 'org.Dm.eg.db',drop = FALSE)
numTmp = sum(is.na(geneTmp[,2]))
print(paste0(numTmp,' genes failed to map.'))
geneTmp[is.na(geneTmp[,2]),]
'select()' returned 1:1 mapping between keys and columns

Warning message in bitr(down, fromType = "SYMBOL", toType = "ENTREZID", OrgDb = "org.Dm.eg.db", :
“1.55% of input gene IDs are fail to map...”


[1] "19 genes failed to map."
A data.frame: 19 × 2
SYMBOLENTREZID
<chr><chr>
3CG2023 NA
24rev7 NA
85Ect4 NA
88CG4662 NA
152CG10880 NA
287CG11210 NA
340CG1968 NA
365CG1427 NA
406CG40178 NA
495CG5734 NA
540CG11781 NA
560CG17337 NA
651CG5844 NA
673CG15168 NA
752CG11137 NA
944CG5830 NA
1051CG6084 NA
1063lncRNA:CR43051NA
1075Thiolase NA
anaGO(na.omit(geneTmp[,2]),prefix = 'aging_down')

png

roxRNAiDEG = read.csv('data/roxRNAi_DEG.csv',header = TRUE,row.names = 1)
roxRNAiDEG
A data.frame: 10617 × 4
namespvals_adjlogfoldchangesstatus
<chr><dbl><dbl><chr>
0RpL41 00.8672693up
1RpL6 00.9240085up
2RpL29 00.8541424up
3RpL39 00.7917424up
4RpL36A 00.5807247up
5RpS27 00.6652983up
6RpS3A 00.8740644up
7RpL23 00.5391975up
8RpLP2 00.5191165up
9RpL3 00.6862599up
10RpS21 00.5687185up
11sta 00.5394719up
12RpS28b 00.5419880up
13RpL38 00.7244318up
14RpS25 00.4637499up
15eEF1alpha100.6608823up
16RpS15 00.4678238up
17RpL31 00.5004458up
18RpL7A 00.4909970up
19RpL28 00.4519229up
20RpS7 00.4774412up
21RpLP0 00.5450004up
22RpS27A 00.4693967up
23RpL23A 00.5290492up
24RpL21 00.5283418up
25RpL10Ab 00.4704212up
26RpL30 00.6655344up
27RpL13A 00.4490866up
28RpL32 00.4287512up
29RpL4 00.5160415up
⋮⋮⋮⋮⋮
10587CG7530 2.107083e-05 -0.22145392stable
10588CG6295 1.256653e-05 -1.41538950down
10589CG3906 5.263416e-06 -2.56632520down
10590betaTry 4.496641e-06 -0.34810814stable
10591lin-28 2.627823e-06 -0.09023929stable
10592GstT4 2.600907e-06 -0.17426874stable
10593CG12825 2.582079e-06 -0.46683140down
10594hbs 2.514691e-06 -1.52056440down
10595udd 9.024231e-07 -0.27895895stable
10596CG16898 6.053737e-07 -0.41750434down
10597asRNA:CR45133 2.162506e-07 -1.32371020down
10598CG9568 1.102348e-10 -0.26687202stable
10599CG18180 1.742257e-11 -2.50549770down
10600SppL 2.784648e-13 -0.43451230down
10601CG13323 5.946100e-14 -0.60004400down
10602CG12374 5.613197e-20 -1.21417770down
10603CG6287 5.983022e-21 -0.30937186stable
10604CG15093 8.275431e-28 -0.48336902down
10605Syt4 6.003154e-28-25.76675800down
10606CG12643 6.371326e-35 -0.60031690down
10607CG5618 7.937363e-44 -1.27941370down
10608CG34324 1.987713e-44 -2.95863400down
10609CG1943 1.252692e-45 -0.30524910stable
10610LysD 7.476423e-59 -1.31639480down
10611CG34220 2.217905e-64 -2.50974320down
10612CG15784 6.841909e-66 -0.32780537stable
10613CG6357 8.741521e-71 -0.44514420down
10614Arc1 2.629337e-82 -0.51360625down
10615Arc2 2.031097e-127 -0.64902300down
10616CG14645 2.615122e-183 -3.04298040down
up = roxRNAiDEG$names[roxRNAiDEG$status=='up']
geneTmp = bitr(up,fromType = 'SYMBOL',toType = 'ENTREZID',OrgDb = 'org.Dm.eg.db',drop = FALSE)
numTmp = sum(is.na(geneTmp[,2]))
print(paste0(numTmp,' genes failed to map.'))
geneTmp[is.na(geneTmp[,2]),]
'select()' returned 1:1 mapping between keys and columns

Warning message in bitr(up, fromType = "SYMBOL", toType = "ENTREZID", OrgDb = "org.Dm.eg.db", :
“1.26% of input gene IDs are fail to map...”


[1] "63 genes failed to map."
A data.frame: 63 × 2
SYMBOLENTREZID
<chr><chr>
240CG17514 NA
471CG6767 NA
529CG2862 NA
614CG8602 NA
708CG5830 NA
921CG8184 NA
973CG9425 NA
1066CG32441 NA
1243CG42684 NA
1317Lsm12 NA
1360CG5045 NA
1521CG15168 NA
1529CG1882 NA
1563CG34449 NA
1580CG11137 NA
1617ThiolaseNA
1637Ect4 NA
1673CG8177 NA
1738CG32758 NA
1791CG40178 NA
1846CG7971 NA
1885SelD NA
1890CG8397 NA
2040CG14057 NA
2112CG6084 NA
2207CG17265 NA
2252CG7946 NA
2319CG5844 NA
2355CG17337 NA
2362CG4552 NA
⋮⋮⋮
2537CG5694 NA
2558SRm160 NA
2713CG9248 NA
2860CG14806 NA
3116CG9422 NA
3207CG3678 NA
3448Itp-r83A NA
3749lncRNA:CR42875NA
3756CG34383 NA
3765CG9186 NA
3815CG11210 NA
3842Adck NA
3851CDC45L NA
3895CG2046 NA
3897CG15440 NA
4022CG9125 NA
4154CG8786 NA
4281CG10915 NA
4293prominin-like NA
4332CG4662 NA
4404CG10889 NA
4481CG4825 NA
4659Strumpellin NA
4845Eip71CD NA
4916CG12018 NA
4919CG7616 NA
4926CG12772 NA
4930l(1)G0045 NA
4960CG14117 NA
5007CG2023 NA
anaGO(na.omit(geneTmp[,2]),prefix = 'roxRNAi_up')

png

inter = intersect(down,up)
geneTmp = bitr(inter,fromType = 'SYMBOL',toType = 'ENTREZID',OrgDb = 'org.Dm.eg.db',drop = FALSE)
numTmp = sum(is.na(geneTmp[,2]))
print(paste0(numTmp,' genes failed to map.'))
geneTmp[is.na(geneTmp[,2]),]
'select()' returned 1:1 mapping between keys and columns

Warning message in bitr(inter, fromType = "SYMBOL", toType = "ENTREZID", OrgDb = "org.Dm.eg.db", :
“1.25% of input gene IDs are fail to map...”


[1] "13 genes failed to map."
A data.frame: 13 × 2
SYMBOLENTREZID
<chr><chr>
2CG2023 NA
57Ect4 NA
59CG4662 NA
222CG11210 NA
320CG40178 NA
436CG11781 NA
456CG17337 NA
536CG5844 NA
553CG15168 NA
623CG11137 NA
790CG5830 NA
885CG6084 NA
907ThiolaseNA
anaGO(na.omit(geneTmp[,2]),prefix = 'intersection')

png

write(inter,file = 'inter.txt')
sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /usr/local/lib64/R/lib/libRblas.so
LAPACK: /usr/local/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] jsonlite_1.8.7        formatR_1.14          ggplot2_3.4.1        
 [4] dplyr_1.1.1           org.Dm.eg.db_3.16.0   AnnotationDbi_1.60.2 
 [7] IRanges_2.32.0        S4Vectors_0.36.2      Biobase_2.58.0       
[10] BiocGenerics_0.44.0   clusterProfiler_4.6.2

loaded via a namespace (and not attached):
  [1] fgsea_1.24.0           colorspace_2.1-0       ggtree_3.6.2          
  [4] gson_0.1.0             IRdisplay_1.1          qvalue_2.30.0         
  [7] XVector_0.38.0         base64enc_0.1-3        aplot_0.1.10          
 [10] farver_2.1.1           graphlayouts_0.8.4     ggrepel_0.9.3         
 [13] bit64_4.0.5            fansi_1.0.4            scatterpie_0.1.8      
 [16] codetools_0.2-18       splines_4.2.2          cachem_1.0.8          
 [19] GOSemSim_2.24.0        polyclip_1.10-4        IRkernel_1.3.2.9000   
 [22] Cairo_1.6-0            GO.db_3.16.0           png_0.1-8             
 [25] ggforce_0.4.1          compiler_4.2.2         httr_1.4.6            
 [28] Matrix_1.5-4           fastmap_1.1.1          lazyeval_0.2.2        
 [31] cli_3.6.1              tweenr_2.0.2           htmltools_0.5.5       
 [34] tools_4.2.2            igraph_1.5.0           gtable_0.3.3          
 [37] glue_1.6.2             GenomeInfoDbData_1.2.9 reshape2_1.4.4        
 [40] fastmatch_1.1-3        Rcpp_1.0.11            enrichplot_1.18.3     
 [43] vctrs_0.6.0            Biostrings_2.66.0      ape_5.7-1             
 [46] nlme_3.1-160           ggraph_2.1.0           stringr_1.5.0         
 [49] lifecycle_1.0.3        DOSE_3.24.2            zlibbioc_1.44.0       
 [52] MASS_7.3-58.1          scales_1.2.1           tidygraph_1.2.3       
 [55] ragg_1.2.4             parallel_4.2.2         RColorBrewer_1.1-3    
 [58] memoise_2.0.1          gridExtra_2.3          downloader_0.4        
 [61] ggfun_0.0.9            HDO.db_0.99.1          yulab.utils_0.0.6     
 [64] stringi_1.7.12         RSQLite_2.3.0          tidytree_0.4.2        
 [67] BiocParallel_1.32.6    repr_1.1.6             GenomeInfoDb_1.34.9   
 [70] rlang_1.1.1            pkgconfig_2.0.3        systemfonts_1.0.4     
 [73] bitops_1.0-7           evaluate_0.21          lattice_0.20-45       
 [76] purrr_1.0.1            treeio_1.22.0          patchwork_1.1.2       
 [79] labeling_0.4.2         cowplot_1.1.1          shadowtext_0.1.2      
 [82] bit_4.0.5              tidyselect_1.2.0       plyr_1.8.8            
 [85] magrittr_2.0.3         R6_2.5.1               generics_0.1.3        
 [88] pbdZMQ_0.3-9           DBI_1.1.3              pillar_1.9.0          
 [91] withr_2.5.0            KEGGREST_1.38.0        RCurl_1.98-1.12       
 [94] tibble_3.2.1           crayon_1.5.2           uuid_1.1-0            
 [97] utf8_1.2.3             viridis_0.6.2          grid_4.2.2            
[100] data.table_1.14.8      blob_1.2.4             digest_0.6.33         
[103] tidyr_1.3.0            gridGraphics_0.5-1     textshaping_0.3.6     
[106] munsell_0.5.0          viridisLite_0.4.2      ggplotify_0.1.0