├── .Rbuildignore ├── .gitignore ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── 10_survival_cut_cox_km.R ├── 11_surv_box_plot.R ├── 12_cor_and_hyper.R ├── 13_network_edge_node.R ├── 14_dumd_all.R ├── 1_plots.R ├── 2_geo_id.R ├── 3_get_deg.R ├── 4_multi_deg.R ├── 5_get_deg_all.R ├── 6_multi_deg_all.R ├── 7_quick_double_enrich.R ├── 8_tcga_group_trans_exp.R ├── 9_cor_t_choose.R ├── data.R └── start_massage.R ├── README.md ├── cran-comments.md ├── data ├── cod.rda ├── deg.rda ├── deseq_data.rda ├── exists_anno_list.rda ├── exp_hub1.rda ├── exprSet_hub1.rda ├── genes.rda ├── lnc_anno.rda ├── lnc_annov23.rda ├── mRNA_anno.rda ├── mRNA_annov23.rda ├── meta1.rda └── pkg_all.rda ├── man ├── box_surv.Rd ├── cod.Rd ├── cor.full.Rd ├── cor.one.Rd ├── corheatmap.Rd ├── corscatterplot.Rd ├── deg.Rd ├── deseq_data.Rd ├── double_enrich.Rd ├── draw_KM.Rd ├── draw_boxplot.Rd ├── draw_heatmap.Rd ├── draw_heatmap2.Rd ├── draw_pca.Rd ├── draw_tsne.Rd ├── draw_venn.Rd ├── draw_volcano.Rd ├── draw_volcano2.Rd ├── dumd.Rd ├── edges_to_nodes.Rd ├── exists_anno_list.Rd ├── exp_boxplot.Rd ├── exp_hub1.Rd ├── exp_surv.Rd ├── exprSet_hub1.Rd ├── find_anno.Rd ├── genes.Rd ├── geo_download.Rd ├── get_cgs.Rd ├── get_count_txt.Rd ├── get_deg.Rd ├── get_deg_all.Rd ├── get_gpl_txt.Rd ├── ggheat.Rd ├── hypertest.Rd ├── interaction_to_edges.Rd ├── intersect_all.Rd ├── lnc_anno.Rd ├── lnc_annov23.Rd ├── mRNA_anno.Rd ├── mRNA_annov23.Rd ├── make_tcga_group.Rd ├── match_exp_cl.Rd ├── meta1.Rd ├── multi_deg.Rd ├── multi_deg_all.Rd ├── pkg_all.Rd ├── plcortest.Rd ├── plot_deg.Rd ├── point_cut.Rd ├── quick_enrich.Rd ├── risk_plot.Rd ├── sam_filter.Rd ├── surv_KM.Rd ├── surv_cox.Rd ├── t_choose.Rd ├── trans_array.Rd ├── trans_entrezexp.Rd ├── trans_exp.Rd ├── trans_exp_new.Rd └── union_all.Rd └── tinyarray.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^cran-comments\.md$ 4 | ^LICENSE\.md$ 5 | ^CRAN-SUBMISSION$ 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | inst/doc 6 | .Rdata 7 | .httr-oauth 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 2.4.2 2 | Date: 2024-06-13 10:50:54 UTC 3 | SHA: d485761cb9ae28496a860435c9614cf0aa5cc549 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tinyarray 2 | Type: Package 3 | Title: Expression Data Analysis and Visualization 4 | Version: 2.4.2 5 | Authors@R:person("Xiaojie", "Sun", email = "18763899370@163.com", role = c("aut", "cre")) 6 | Maintainer: Xiaojie Sun <18763899370@163.com> 7 | Description: The Gene Expression Omnibus () and The Cancer Genome Atlas () are widely used medical public databases. Our platform integrates routine analysis and visualization tools for expression data to provide concise and intuitive data analysis and presentation. 8 | License: MIT + file LICENSE 9 | Encoding: UTF-8 10 | LazyData: true 11 | Imports: 12 | BiocManager, 13 | clusterProfiler, 14 | dplyr, 15 | limma, 16 | stringr, 17 | tibble, 18 | pheatmap, 19 | ggplot2, 20 | survival, 21 | Hmisc, 22 | survminer, 23 | patchwork 24 | Suggests: testthat, AnnoProbe, GEOquery, Biobase, VennDiagram, 25 | FactoMineR, factoextra, knitr, rmarkdown, cowplot, ggpubr, 26 | ggplotify, tidyr, labeling, Rtsne, scatterplot3d, 27 | ComplexHeatmap, circlize,org.Rn.eg.db,org.Mm.eg.db,org.Hs.eg.db 28 | URL: https://github.com/xjsun1221/tinyarray 29 | BugReports: https://github.com/xjsun1221/tinyarray/issues 30 | Depends: R (>= 4.1.0) 31 | RoxygenNote: 7.3.1 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2024 2 | COPYRIGHT HOLDER: tinyarray authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2024 tinyarray authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(box_surv) 4 | export(cor.full) 5 | export(cor.one) 6 | export(corheatmap) 7 | export(corscatterplot) 8 | export(double_enrich) 9 | export(draw_KM) 10 | export(draw_boxplot) 11 | export(draw_heatmap) 12 | export(draw_heatmap2) 13 | export(draw_pca) 14 | export(draw_tsne) 15 | export(draw_venn) 16 | export(draw_volcano) 17 | export(draw_volcano2) 18 | export(dumd) 19 | export(edges_to_nodes) 20 | export(exp_boxplot) 21 | export(exp_surv) 22 | export(find_anno) 23 | export(geo_download) 24 | export(get_cgs) 25 | export(get_count_txt) 26 | export(get_deg) 27 | export(get_deg_all) 28 | export(get_gpl_txt) 29 | export(ggheat) 30 | export(hypertest) 31 | export(interaction_to_edges) 32 | export(intersect_all) 33 | export(make_tcga_group) 34 | export(match_exp_cl) 35 | export(multi_deg) 36 | export(multi_deg_all) 37 | export(plcortest) 38 | export(plot_deg) 39 | export(point_cut) 40 | export(quick_enrich) 41 | export(risk_plot) 42 | export(sam_filter) 43 | export(surv_KM) 44 | export(surv_cox) 45 | export(t_choose) 46 | export(trans_array) 47 | export(trans_entrezexp) 48 | export(trans_exp) 49 | export(trans_exp_new) 50 | export(union_all) 51 | importFrom(BiocManager,install) 52 | importFrom(Hmisc,rcorr) 53 | importFrom(clusterProfiler,bitr) 54 | importFrom(clusterProfiler,dotplot) 55 | importFrom(clusterProfiler,enrichGO) 56 | importFrom(clusterProfiler,enrichKEGG) 57 | importFrom(clusterProfiler,setReadable) 58 | importFrom(dplyr,arrange) 59 | importFrom(dplyr,case_when) 60 | importFrom(dplyr,desc) 61 | importFrom(dplyr,distinct) 62 | importFrom(dplyr,inner_join) 63 | importFrom(dplyr,mutate) 64 | importFrom(dplyr,union_all) 65 | importFrom(ggplot2,aes) 66 | importFrom(ggplot2,aes_string) 67 | importFrom(ggplot2,after_stat) 68 | importFrom(ggplot2,coord_flip) 69 | importFrom(ggplot2,element_blank) 70 | importFrom(ggplot2,element_line) 71 | importFrom(ggplot2,element_rect) 72 | importFrom(ggplot2,element_text) 73 | importFrom(ggplot2,facet_grid) 74 | importFrom(ggplot2,geom_bar) 75 | importFrom(ggplot2,geom_boxplot) 76 | importFrom(ggplot2,geom_density) 77 | importFrom(ggplot2,geom_histogram) 78 | importFrom(ggplot2,geom_hline) 79 | importFrom(ggplot2,geom_point) 80 | importFrom(ggplot2,geom_tile) 81 | importFrom(ggplot2,geom_vline) 82 | importFrom(ggplot2,ggplot) 83 | importFrom(ggplot2,ggsave) 84 | importFrom(ggplot2,labs) 85 | importFrom(ggplot2,scale_color_manual) 86 | importFrom(ggplot2,scale_fill_gradient2) 87 | importFrom(ggplot2,scale_fill_manual) 88 | importFrom(ggplot2,scale_x_continuous) 89 | importFrom(ggplot2,scale_x_discrete) 90 | importFrom(ggplot2,scale_y_continuous) 91 | importFrom(ggplot2,stat_boxplot) 92 | importFrom(ggplot2,stat_ellipse) 93 | importFrom(ggplot2,theme) 94 | importFrom(ggplot2,theme_bw) 95 | importFrom(ggplot2,theme_classic) 96 | importFrom(ggplot2,theme_light) 97 | importFrom(ggplot2,theme_void) 98 | importFrom(ggplot2,unit) 99 | importFrom(ggplot2,ylim) 100 | importFrom(limma,contrasts.fit) 101 | importFrom(limma,eBayes) 102 | importFrom(limma,lmFit) 103 | importFrom(limma,makeContrasts) 104 | importFrom(limma,topTable) 105 | importFrom(patchwork,plot_layout) 106 | importFrom(patchwork,plot_spacer) 107 | importFrom(patchwork,wrap_plots) 108 | importFrom(pheatmap,pheatmap) 109 | importFrom(stringr,str_detect) 110 | importFrom(stringr,str_remove) 111 | importFrom(stringr,str_remove_all) 112 | importFrom(stringr,str_split) 113 | importFrom(stringr,str_starts) 114 | importFrom(stringr,str_sub) 115 | importFrom(stringr,str_to_lower) 116 | importFrom(stringr,str_to_upper) 117 | importFrom(stringr,str_wrap) 118 | importFrom(survival,Surv) 119 | importFrom(survival,coxph) 120 | importFrom(survival,survdiff) 121 | importFrom(survival,survfit) 122 | importFrom(survminer,ggsurvplot) 123 | importFrom(survminer,surv_cutpoint) 124 | importFrom(tibble,rownames_to_column) 125 | importFrom(tibble,tibble) 126 | importFrom(utils,packageDescription) 127 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | ### 更新日志: 2 | 3 | 写于2021.1.26 4 | 5 | #### 2.1.1 6 | limma如果表达矩阵有重复行名,则第一列为ID,随之改了get_deg和draw_volcano 7 | 8 | ggplot2更新,手动指定颜色必须加values=,已加 9 | 10 | ifelse更新,允许矩阵数据,生成结果也为矩阵,为此改了表达矩阵箱线图、KM图系列 11 | 12 | 表达矩阵与分组信息的匹配 13 | 14 | #### 2.1.2 15 | mRNA与lncRNA都有时矩阵去重 16 | 17 | #### 2.1.5 18 | 19 | GEO下载的表达矩阵有异常值时不再报错,而是只给个warning啦 20 | 21 | #### 2.1.6 22 | 23 | 解决mac tab键编码方式报错问题 24 | 25 | #### 2.1.7 26 | 27 | draw_heatmap 添加参数scale,F即为原矩阵画图,不scale. 28 | 29 | #### 2.1.8 30 | 31 | draw_heatmap 添加参数main,标题 32 | 33 | #### 2.1.9 34 | 35 | surv_cox 输出结果小数点位数不限制(因为有些p值太小,会变成零) 36 | 37 | #### 2.2.0 38 | 39 | 检查了exp_boxplot之前的所有函数及其帮助文档,quickenrich和make_tcga_group不再报warning 40 | 41 | #### 2.2.1 42 | 43 | 检查了exp_boxplot之后的所有函数及其帮助文档,调整了脚本里的函数顺序,加上编号以后方便查找。 44 | 45 | 去掉了加载R包时的提示信息,整理了所有的seealso 46 | 47 | 我要整理整理投放到cran咯,用CMD check检查发现: 48 | 49 | 帮助文档里的示例逻辑值必须写TRUE,FALSE ,不能写T和F 50 | 51 | 示例需要保证运行正确,示例代码里library的包也需要写进依赖包。 52 | 53 | 写函数的代码里的require用requireNamespace()代替。 54 | 55 | data用use_data生成,不自己保存,避免错误的编码方式 56 | 57 | #### 2.2.2 58 | 59 | geo_download支持指定下载读取的目录,支持去除重复的ch1列 60 | 61 | 添加draw_tsne、draw_KM。ggsurvplot传参问题在:https://github.com/kassambara/survminer/issues/342 62 | 63 | 删掉了split_list函数,cran不让使用全局变量 64 | 65 | match_exp_cl以列表形式输出,也取消了全局变量。需要赋值然后取子集。 66 | 67 | 修改了默认配色。 68 | 69 | 帮助文档的文件输出路径改为临时路径。消除全部note啦!!! 70 | 71 | #### 2.2.3 72 | 73 | 合并了get_deg和multi_deg,用同样的代码完成二组和多组的差异分析。 74 | 75 | cg的组织方式简化一些 76 | 77 | #### 2.2.4和2.2.5 78 | 79 | 帮助文档所有destdir设置为临时路径,大于5s的示例加上donttest 80 | 81 | #### 2.2.6 82 | 83 | cran 人工返回修改意见: 84 | 85 | 1.标题 缩写 86 | 87 | 2.包的功能详细说明 88 | 89 | 3.使用的方法参考资料,doi或者链接,可以有标题 90 | 91 | 4.TF换成TRUE FALSE 92 | 93 | 5.message代替print 94 | 95 | 6.示例里面删掉rm(list= ls()) 96 | 97 | ### 2.2.8 98 | 99 | 1.exp_surv添加了cut.point参数,默认值false,即以中位数为截断值画图。修改了配色。 100 | 101 | 2.解决了sur_cox的NA报错问题 102 | 103 | 3.解决了quick_enrich画图横坐标消失的问题。 104 | 105 | 4.新增函数risk_plot,画风险因子三图联动 106 | 107 | 5.修改了suggest的包安装提示 108 | 109 | 6.内置数据exprSet_hub1改为了logcpm,不再是原来的count 110 | 111 | ### 2.2.9 112 | 113 | 1.删除heat_id 和gene_number两个参数,用my_genes代替 114 | 115 | 2.随ggplot2更新了 linewidth参数和 after_stat(p.format) 116 | 117 | 3.作图函数,加上...过渡参数 118 | 119 | 4.cor.one 和cor.full添加过滤0值参数 120 | 121 | 5.更新trans_exp函数 122 | 123 | ### 2.3.1 124 | 125 | 1.差异分析、富集分析、id转换的函数支持人,小鼠,大鼠三个物种 126 | 127 | 2.修复get_deg_all不显示差异基因、logFC阈值设置无效的bug 128 | 129 | 3.trans_exp_new改到支持数据框 130 | 131 | ### 2.3.2 132 | 133 | 增加3个函数 134 | 135 | 1.trans_entrezexp 136 | 137 | 2.get_count_txt 138 | 139 | 3.get_gpl_txt 140 | 141 | ### 2.3.3 142 | 143 | 增加2个函数 144 | 145 | 1.corscatterplot 146 | 147 | 2.corheatmap 148 | 149 | -------------------------------------------------------------------------------- /R/10_survival_cut_cox_km.R: -------------------------------------------------------------------------------- 1 | ##' point_cut 2 | ##' 3 | ##' calculate cut point for multiple genes 4 | ##' 5 | ##' @param exprSet_hub a tumor expression set for hubgenes 6 | ##' @param meta meta data corresponds to expression set 7 | ##' @importFrom survminer surv_cutpoint 8 | ##' @export 9 | ##' @return a vector with cutpoint for genes 10 | ##' @author Xiaojie Sun 11 | ##' @examples 12 | ##' point_cut(exprSet_hub1,meta1) 13 | ##' @seealso 14 | ##' \code{\link{surv_KM}};\code{\link{surv_cox}} 15 | 16 | point_cut <- function(exprSet_hub,meta){ 17 | if(ncol(exprSet_hub)!=nrow(meta))stop("your exprSet_hub is not corresponds to meta") 18 | kp = apply(exprSet_hub, 1, function(x)length(unique(unique(x))) > 4) 19 | message(paste0(sum(kp)," rows with less than 5 values were ignored in cut.point calculations")) 20 | exprSet_hub = exprSet_hub[kp,] 21 | dat = cbind(t(exprSet_hub),meta) 22 | cut.point = c() 23 | for(i in 1:nrow(exprSet_hub)){ 24 | cut = surv_cutpoint( 25 | dat, 26 | time = "time", 27 | event = "event", 28 | variables = rownames(exprSet_hub)[i] 29 | ) 30 | cut.point[[i]] = cut[["cutpoint"]][1,1] 31 | } 32 | names(cut.point) = rownames(exprSet_hub) 33 | return(cut.point) 34 | } 35 | 36 | ##' surv_KM 37 | ##' 38 | ##' calculate log_rank test p values for genes 39 | ##' 40 | ##' @inheritParams point_cut 41 | ##' @inheritParams t_choose 42 | ##' @param cut.point logical , use cut_point or not, if FALSE,use median by defult 43 | ##' @param min_gn Depending on the expression of a gene, there may be a large difference in the number of samples between the two groups, and if a smaller group of samples is less than 10 percent (default) of all, the gene will be discarded 44 | ##' @importFrom survival Surv 45 | ##' @importFrom survival survdiff 46 | ##' @export 47 | ##' @return a vector with gene names and log_rank p value 48 | ##' @author Xiaojie Sun 49 | ##' @examples 50 | ##' surv_KM(exprSet_hub1,meta1) 51 | ##' surv_KM(exprSet_hub1,meta1,pvalue_cutoff = 1) 52 | ##' surv_KM(exprSet_hub1,meta1,cut.point = TRUE) 53 | ##' @seealso 54 | ##' \code{\link{point_cut}};\code{\link{surv_cox}} 55 | 56 | 57 | surv_KM <- function(exprSet_hub,meta,cut.point = FALSE,pvalue_cutoff = 0.05,min_gn = 0.1){ 58 | if(cut.point)cut_point = point_cut(exprSet_hub,meta) 59 | log_rank_p = c() 60 | for(i in 1:nrow(exprSet_hub)){ 61 | gene = as.numeric(exprSet_hub[i,]) 62 | if(cut.point){ 63 | meta$group=ifelse(gene>cut_point[i],'high','low') 64 | }else{ 65 | meta$group=ifelse(gene>stats::median(gene),'high','low') 66 | } 67 | data.survdiff=survdiff(Surv(time, event)~group,data=meta) 68 | log_rank_p[[i]] = 1 - stats::pchisq(data.survdiff$chisq, length(data.survdiff$n) - 1) 69 | nn = min(table(meta$group))<= min_gn * nrow(meta) 70 | if(nn) log_rank_p[[i]] = 1 71 | } 72 | if(is.list(log_rank_p)) log_rank_p = unlist(log_rank_p) 73 | names(log_rank_p) = rownames(exprSet_hub) 74 | log_rank_p=sort(log_rank_p) 75 | tp = log_rank_p[log_rank_pcut_point[i],'high','low') 113 | }else{ 114 | meta$group=ifelse(gene>stats::median(gene),'high','low') 115 | } 116 | meta$group = factor(meta$group,levels = c("low","high")) 117 | m=coxph(Surv(time, event)~group, data = meta) 118 | } 119 | beta <- stats::coef(m) 120 | se <- sqrt(diag(stats::vcov(m))) 121 | HR <- exp(beta) 122 | HRse <- HR * se 123 | 124 | #summary(m) 125 | tmp <- cbind(coef = beta, se = se, z = beta/se, p = 1 - stats::pchisq((beta/se)^2, 1), 126 | HR = HR, HRse = HRse, 127 | HRz = (HR - 1) / HRse, HRp = 1 - stats::pchisq(((HR - 1)/HRse)^2, 1), 128 | HRCILL = exp(beta - stats::qnorm(.975, 0, 1) * se), 129 | HRCIUL = exp(beta + stats::qnorm(.975, 0, 1) * se)) 130 | if(continuous){ 131 | cox_results[[i]] = tmp['gene',] 132 | }else{ 133 | cox_results[[i]] = tmp['grouphigh',] 134 | nn = min(table(meta$group))<= min_gn * nrow(meta) 135 | if(nn) cox_results[[i]] = rep(NA,times = length(cox_results[[i]])) 136 | } 137 | } 138 | cox_results = do.call(cbind,cox_results) 139 | cox_results=t(cox_results) 140 | rownames(cox_results)= rownames(exprSet_hub) 141 | nn2 = apply(cox_results,1,function(x){all(is.na(x))}) 142 | cox_results = cox_results[!nn2,] 143 | k = cox_results[,4]1 163 | return(cox_results[k]) 164 | message(paste0(sum(k)," of ",nrow(exprSet_hub)," genes selected")) 165 | }else if(!(HRkeep %in% c("all","protect","risk"))){ 166 | stop('HRkeep should be one of "all","protect"or"risk"') 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /R/11_surv_box_plot.R: -------------------------------------------------------------------------------- 1 | ##' exp_surv 2 | ##' 3 | ##' draw surv plot for a hub gene expression matrix for tumor samples 4 | ##' 5 | ##' @inheritParams surv_KM 6 | ##' @inheritParams exp_boxplot 7 | ##' @importFrom survival survfit 8 | ##' @importFrom survival Surv 9 | ##' @importFrom survminer ggsurvplot 10 | ##' @importFrom ggplot2 theme 11 | ##' @importFrom ggplot2 element_text 12 | ##' @export 13 | ##' @return survival plots list for all genes 14 | ##' @author Xiaojie Sun 15 | ##' @examples 16 | ##' tmp = exp_surv(exprSet_hub1,meta1) 17 | ##' patchwork::wrap_plots(tmp)+patchwork::plot_layout(guides = "collect") 18 | ##' tmp2 = exp_surv(exprSet_hub1,meta1,cut.point = TRUE) 19 | ##' patchwork::wrap_plots(tmp2)+patchwork::plot_layout(guides = "collect") 20 | ##' @seealso 21 | ##' \code{\link{exp_boxplot}};\code{\link{box_surv}};\code{\link{draw_venn}} 22 | 23 | 24 | exp_surv <- function(exprSet_hub,meta,cut.point = FALSE,color = c("#2874C5", "#f87669")){ 25 | if(cut.point)cut_point = point_cut(exprSet_hub,meta) 26 | 27 | splots <- lapply(rownames(exprSet_hub), function(g){ 28 | i = which(rownames(exprSet_hub)== g) 29 | if(cut.point){ 30 | meta$gene=ifelse(as.numeric(exprSet_hub[g,]) > cut_point[[i]],'high','low') 31 | }else{ 32 | meta$gene=ifelse(as.numeric(exprSet_hub[g,]) > stats::median(as.numeric(exprSet_hub[g,])),'high','low') 33 | } 34 | if(length(unique(meta$gene))==1) stop(paste0("gene",g,"with too low expression")) 35 | sfit1=survfit(Surv(time, event)~gene, data=meta) 36 | p = ggsurvplot(sfit1,pval =TRUE, 37 | palette = rev(color), 38 | data = meta, 39 | legend = c(0.8,0.8), 40 | title = rownames(exprSet_hub)[[i]] 41 | ) 42 | p2 = p$plot+ 43 | theme(plot.title = element_text(hjust = 0.5)) 44 | return(p2) 45 | }) 46 | return(splots) 47 | } 48 | 49 | ##' exp_boxplot 50 | ##' 51 | ##' draw box plot for a hub gene expression matrix 52 | ##' 53 | ##' @param exp_hub an expression matrix for hubgenes 54 | ##' @param color color for boxplot 55 | ##' @importFrom ggplot2 ggplot 56 | ##' @importFrom ggplot2 aes_string 57 | ##' @importFrom ggplot2 geom_boxplot 58 | ##' @importFrom ggplot2 scale_fill_manual 59 | ##' @importFrom ggplot2 theme_classic 60 | ##' @importFrom ggplot2 theme 61 | ##' @export 62 | ##' @return box plots list for all genes in the matrix 63 | ##' @author Xiaojie Sun 64 | ##' @examples 65 | ##'if(requireNamespace("ggpubr",quietly = TRUE)) { 66 | ##' k = exp_boxplot(log2(exp_hub1+1));k[[1]] 67 | ##'}else{ 68 | ##' warning("Package 'ggpubr' needed for this function to work. 69 | ##' Please install it by install.packages('ggpubr')") 70 | ##'} 71 | ##' @seealso 72 | ##' \code{\link{exp_surv}};\code{\link{box_surv}} 73 | 74 | exp_boxplot <- function(exp_hub,color = c("#2fa1dd","#f87669")){ 75 | if(nrow(exp_hub)>15)warning(paste0(nrow(exp_hub)," figures will be produced")) 76 | if(!requireNamespace("ggpubr",quietly = TRUE)) { 77 | stop("Package \"ggpubr\" needed for this function to work. 78 | Please install it by install.packages('ggpubr')",call. = FALSE) 79 | } 80 | group_list = make_tcga_group(exp_hub) 81 | k = rownames(exp_hub) 82 | rownames(exp_hub) = paste0("gene",1:nrow(exp_hub)) 83 | dat = as.data.frame(t(exp_hub)) 84 | dat$group_list = group_list 85 | color = color[1:length(levels(group_list))] 86 | names(color) = levels(group_list) 87 | bplots = lapply(1:nrow(exp_hub),function(i){ 88 | ggplot(dat, 89 | aes_string(x = "group_list", 90 | y = rownames(exp_hub)[[i]], 91 | fill = "group_list"))+ 92 | geom_boxplot()+ 93 | scale_fill_manual(values = color)+ 94 | labs(y = k[[i]])+ 95 | ggpubr::stat_compare_means(method = "t.test")+ 96 | #stat_compare_means(label.y = 15) + 97 | theme_classic()+ 98 | theme(legend.position = "none") 99 | }) 100 | return(bplots) 101 | } 102 | 103 | ##' box_surv 104 | ##' 105 | ##' draw box plot for a hub gene expression matrix 106 | ##' 107 | ##' @inheritParams exp_boxplot 108 | ##' @inheritParams exp_surv 109 | ##' @importFrom patchwork plot_layout 110 | ##' @importFrom ggplot2 theme 111 | ##' @export 112 | ##' @return patchwork result for hub genes boxplot and survival plot 113 | ##' @author Xiaojie Sun 114 | ##' @examples 115 | ##'if(requireNamespace("ggpubr",quietly = TRUE)) { 116 | ##' k = box_surv(log2(exp_hub1+1),exprSet_hub1,meta1);k[[1]] 117 | ##'}else{ 118 | ##' warning("Package 'ggpubr' needed for this function to work. 119 | ##' Please install it by install.packages('ggpubr')") 120 | ##'} 121 | ##' @seealso 122 | ##' \code{\link{exp_boxplot}};\code{\link{exp_surv}} 123 | 124 | box_surv <-function(exp_hub,exprSet_hub,meta){ 125 | splots = exp_surv(exprSet_hub,meta) 126 | boxplots = exp_boxplot(exp_hub) 127 | layout <- ' 128 | ABB 129 | ' 130 | wp = lapply(1:nrow(exprSet_hub),function(i){ 131 | boxplots[[i]]+splots[[i]]+ 132 | plot_layout(design = layout)& theme(legend.position = "none") 133 | }) 134 | return(wp) 135 | } 136 | 137 | 138 | 139 | ##' risk_plot 140 | ##' 141 | ##' draw risk plot 142 | ##' 143 | ##' @inheritParams exp_surv 144 | ##' @inheritParams draw_heatmap 145 | ##' @param riskscore a numeric vector of riskscore 146 | ##' @importFrom survminer surv_cutpoint 147 | ##' @importFrom ggplot2 ggplot 148 | ##' @importFrom ggplot2 aes 149 | ##' @importFrom ggplot2 geom_point 150 | ##' @importFrom ggplot2 scale_color_manual 151 | ##' @importFrom ggplot2 geom_vline 152 | ##' @importFrom ggplot2 scale_x_continuous 153 | ##' @importFrom ggplot2 theme_bw 154 | ##' @importFrom ggplot2 theme 155 | ##' @importFrom ggplot2 element_blank 156 | ##' @importFrom ggplot2 labs 157 | ##' @importFrom ggplot2 scale_color_manual 158 | ##' @importFrom ggplot2 scale_y_continuous 159 | ##' @importFrom ggplot2 element_line 160 | ##' @importFrom patchwork wrap_plots 161 | ##' @export 162 | ##' @return risk plot 163 | ##' @author Xiaojie Sun 164 | ##' @examples 165 | ##' risk_plot(exprSet_hub1,meta1,riskscore = rnorm(nrow(meta1))) 166 | ##' @seealso 167 | ##' \code{\link{exp_boxplot}};\code{\link{box_surv}};\code{\link{draw_venn}} 168 | 169 | risk_plot = function(exprSet_hub,meta,riskscore, 170 | cut.point = FALSE,color = c("#2fa1dd","#f87669"),n_cutoff = 3){ 171 | if(ncol(exprSet_hub) != nrow(meta))stop("your exprSet_hub is not corresponds to meta") 172 | if(length(riskscore) != nrow(meta))stop("riskscore is not corresponds to meta") 173 | if (nrow(exprSet_hub)>30) { 174 | warning("seems too many of genes in heatmap") 175 | } 176 | if (nrow(exprSet_hub)>100) { 177 | stop("too many of genes in heatmap") 178 | } 179 | meta$riskscorefp = riskscore 180 | if(cut.point){ 181 | cut = surv_cutpoint( 182 | meta, 183 | time = "time", 184 | event = "event", 185 | variables = "riskscorefp")[["cutpoint"]][1,1] 186 | }else{ 187 | cut = stats::median(riskscore) 188 | } 189 | meta$Risk = ifelse(riskscore>cut,'high','low') 190 | meta$Risk = factor(meta$Risk,levels = c("low","high")) 191 | fp_dat=data.frame(patientid=1:length(riskscore), 192 | riskscore=as.numeric(sort(riskscore)), 193 | ri = meta$Risk[order(riskscore)]) 194 | sur_dat=data.frame(patientid=1:length(riskscore), 195 | time=meta[order(riskscore),'time'] , 196 | event=meta[order(riskscore),'event']) 197 | sur_dat$event=ifelse(sur_dat$event==0,'alive','death') 198 | 199 | # exp 200 | 201 | exp_dat = scale(t(exprSet_hub[,order(riskscore)])) 202 | exp_dat[exp_dat > n_cutoff] = n_cutoff 203 | exp_dat[exp_dat < -n_cutoff] = -n_cutoff 204 | ###第一个图---- 205 | p1=ggplot(fp_dat,aes(x=patientid,y=riskscore,color = ri))+ 206 | geom_point()+ 207 | scale_color_manual(values = color)+ 208 | geom_vline(xintercept = sum(riskscorecor_cutoff 23 | if(k&k2){jp[[i]] = c(jp[[i]],colnames(x)[[j]])} 24 | } 25 | } 26 | names(jp) = rownames(lnc_exp) 27 | return(jp) 28 | } 29 | 30 | 31 | ##' hypertest 32 | ##' 33 | ##' make hypertest for given lncRNA and mRNA common miRNAs 34 | ##' @param lnc lncRNA names 35 | ##' @param pc mRNA names 36 | ##' @param deMIR miRNA names , default NULL 37 | ##' @param lnctarget a data.frame with two column,lncRNA in the first column ,miRNA in the second column 38 | ##' @param pctarget a data.frame with two column,mRNA in the first column ,miRNA in the second column 39 | ##' @export 40 | ##' @return a data.frame with hypertest result 41 | ##' @author Xiaojie Sun 42 | ##' @examples 43 | ##' # to update 44 | ##' @seealso 45 | ##' \code{\link{plcortest}} 46 | 47 | hypertest = function(lnc,pc,deMIR = NULL,lnctarget,pctarget){ 48 | pcs = unique(pctarget[,1]) 49 | pctarget = lapply(unique(pctarget[,1]), function(x){ 50 | pctarget[,2][pctarget[,1]==x] 51 | }) 52 | names(pctarget) = unique(pcs) 53 | 54 | lncs = unique(lnctarget[,1]) 55 | lnctarget = lapply(unique(lnctarget[,1]), function(x){ 56 | lnctarget[,2][lnctarget[,1]==x] 57 | }) 58 | names(lnctarget) = lncs 59 | 60 | mir1 <- unique(unlist(lnctarget)) 61 | mir2 <- unique(unlist(pctarget)) 62 | 63 | mirs <- union(mir1,mir2) #合集 64 | popTotal <- length(mirs) #合集长度 65 | 66 | ceLNC <- lnc[lnc %in% names(lnctarget)] #有miRNA的lnc 67 | cePC <- pc[pc %in% names(pctarget)] #有miRNA的pc 68 | #ceMIR <- mir[mir %in% mirs] 69 | 70 | hyperOutput <- list() 71 | i <- 0 72 | for (lncID in ceLNC) { 73 | listTotal <- length(lnctarget[[lncID]]) #lnc 的miRNA数量 74 | for (gene in cePC) { 75 | i = i + 1 76 | ovlp <- intersect(lnctarget[[lncID]], pctarget[[gene]]) #交集 77 | 78 | popHits <- length(pctarget[[gene]]) 79 | Counts <- length(ovlp) 80 | 81 | ovlpMIRs <- paste(ovlp, collapse = ',') 82 | foldEnrichment <- Counts/listTotal*popTotal/popHits 83 | pValue <- stats::phyper(Counts-1, popHits, popTotal-popHits, 84 | listTotal, lower.tail=FALSE, log.p=FALSE) 85 | 86 | ceMIR <- Reduce(intersect, list(ovlp, deMIR)) 87 | deMIRs <- paste(ceMIR, collapse = ',') 88 | deMIRCounts <- length(ceMIR) 89 | 90 | hyperOutput[[i]] <- c(lncID, gene, Counts, listTotal, 91 | popHits,popTotal,foldEnrichment,pValue,ovlpMIRs, 92 | deMIRCounts, deMIRs) 93 | 94 | } 95 | } 96 | 97 | #hyperOutput <- Reduce(rbind, hyperOutput) ## slower 98 | hyperOutput <- do.call(rbind, hyperOutput) 99 | #hyperOutput <- rbind_list(hyperOutput) ## not test 100 | 101 | colnames(hyperOutput) <- c('lncRNAs','Genes','Counts','listTotal', 102 | 'popHits','popTotal','foldEnrichment','hyperPValue','miRNAs', 103 | 'deMIRCounts','deMIRs') 104 | hyperOutput <- as.data.frame(as.matrix(hyperOutput), 105 | stringsAsFactors=FALSE) 106 | hyperOutput <- hyperOutput[as.numeric(hyperOutput$Counts)>0,] 107 | 108 | #hyperOutput$FDR <- p.adjust(as.numeric(as.character(hyperOutput$pValue)), 109 | #method = 'fdr') 110 | #hyperOutput <- hyperOutput[hyperOutput$Counts>0,] 111 | #hyperOutput$lncRNAs <- ensembl2symbolFun(hyperOutput$lncRNAs) 112 | #hyperOutput$gene <- ensembl2symbolFun(hyperOutput$gene) 113 | 114 | if (is.null(deMIR)) { 115 | hyperOutput <- hyperOutput[,! colnames(hyperOutput) %in% 116 | c('deMIRCounts','deMIRs')] 117 | } 118 | hyperOutput = hyperOutput[order(hyperOutput$hyperPValue),] 119 | return (hyperOutput) 120 | message(paste0(sum(hyperOutput$hyperPValue<0.05)," pairs p<0.05")) 121 | } 122 | -------------------------------------------------------------------------------- /R/13_network_edge_node.R: -------------------------------------------------------------------------------- 1 | ##' interaction_to_edges 2 | ##' 3 | ##' split interactions by sep paramter,return edges data.frame 4 | ##' 5 | ##' @param df interactions data.frame 6 | ##' @param a column to replicate 7 | ##' @param b column to split 8 | ##' @param sep a character string to separate b column 9 | ##' @importFrom stringr str_split 10 | ##' @importFrom dplyr distinct 11 | ##' @export 12 | ##' @return a new data.frame with two column ,one interaction by one rows 13 | ##' @author Xiaojie Sun 14 | ##' @examples 15 | ##' df = data.frame(a = c("gene1","gene2","gene3"), 16 | ##' b = c("d,f,a,b", 17 | ##' "c,e,g", 18 | ##' "a,b,d")) 19 | ##' interaction_to_edges(df) 20 | ##' @seealso 21 | ##' \code{\link{edges_to_nodes}} 22 | 23 | interaction_to_edges = function(df,a = 1,b = 2,sep = ","){ 24 | gs = str_split(df[,b],sep) 25 | edges = data.frame(a1 = rep(df[,a],times = sapply(gs,length)), 26 | a2 = unlist(gs)) 27 | edges = distinct(edges,a1,a2) 28 | return(edges) 29 | } 30 | utils::globalVariables(c("a1","a2")) 31 | 32 | ##' edges_to_nodes 33 | ##' 34 | ##' get nodes from edges 35 | ##' 36 | ##' @param edges data.frame 37 | ##' @importFrom stringr str_split 38 | ##' @importFrom dplyr distinct 39 | ##' @export 40 | ##' @return nodes data.frame 41 | ##' @author Xiaojie Sun 42 | ##' @examples 43 | ##' df = data.frame(a = c("gene1","gene2","gene3"), 44 | ##' b = c("d,f,a,b", 45 | ##' "c,e,g", 46 | ##' "a,b,d")) 47 | ##' edges = interaction_to_edges(df) 48 | ##' nodes = edges_to_nodes(edges) 49 | ##' @seealso 50 | ##' \code{\link{interaction_to_edges}} 51 | 52 | edges_to_nodes = function(edges){ 53 | if(!is.null(colnames(edges))){ 54 | m = colnames(edges) 55 | }else{ 56 | m = c("A1","A2") 57 | } 58 | a = unique(edges[,1]) 59 | b = unique(edges[,2]) 60 | nodes = data.frame(gene = c(a,b), 61 | type = c(rep(m[1],times = length(a)), 62 | rep(m[2],times = length(b)))) 63 | return(nodes) 64 | } 65 | -------------------------------------------------------------------------------- /R/14_dumd_all.R: -------------------------------------------------------------------------------- 1 | ##' count unique values in every columns for data.frame 2 | ##' 3 | ##' in geo analysis,this function can help you simplify pdata, delete columns with unique values,which can't be used as group vector 4 | ##' @param x A data.frame. 5 | ##' @return The simple data.frame of columns unique values count in \code{x} 6 | ##' @importFrom dplyr arrange 7 | ##' @importFrom dplyr desc 8 | ##' @importFrom tibble tibble 9 | ##' @export 10 | ##' @examples 11 | ##' dumd(iris) 12 | ##' data(ToothGrowth) 13 | ##' x = ToothGrowth 14 | ##' dumd(ToothGrowth) 15 | 16 | dumd <- function(x){ 17 | colname <- vector("character") 18 | count <- vector("integer") 19 | for(i in 1:ncol(x)){ 20 | colname[i] = colnames(x)[[i]] 21 | count[i]=nrow(x[!duplicated(x[,i]),]) 22 | } 23 | df <- tibble(colname,count) |> 24 | arrange(desc(count)) 25 | return(df) 26 | } 27 | 28 | ##' intersect_all 29 | ##' 30 | ##' calculate intersect set for two or more elements 31 | ##' 32 | ##' @param ... some vectors or a list with some vectors 33 | ##' @export 34 | ##' @return vector 35 | ##' @author Xiaojie Sun 36 | ##' @examples 37 | ##' x1 = letters[1:4] 38 | ##' x2 = letters[3:6] 39 | ##' x3 = letters[3:4] 40 | ##' re =intersect_all(x1,x2,x3) 41 | ##' re2 = intersect_all(list(x1,x2,x3)) 42 | ##' re3 = union_all(x1,x2,x3) 43 | ##' @seealso 44 | ##' \code{\link{union_all}} 45 | intersect_all <- function(...){ 46 | li = list(...) 47 | if(length(li)==1 & is.list(li[[1]])) li = li[[1]] 48 | result = li[[1]] 49 | for(k in 1:length(li)){ 50 | result = intersect(result,li[[k]]) 51 | } 52 | return(result) 53 | } 54 | 55 | ##' union_all 56 | ##' 57 | ##' calculate union set for two or more elements 58 | ##' 59 | ##' @param ... some vectors or a list with some vectors 60 | ##' @export 61 | ##' @return vector 62 | ##' @author Xiaojie Sun 63 | ##' @examples 64 | ##' x1 = letters[1:4] 65 | ##' x2 = letters[3:6] 66 | ##' x3 = letters[3:4] 67 | ##' re =intersect_all(x1,x2,x3) 68 | ##' re2 = intersect_all(list(x1,x2,x3)) 69 | ##' re3 = union_all(x1,x2,x3) 70 | ##' @seealso 71 | ##' \code{\link{intersect_all}} 72 | union_all <- function(...){ 73 | li = list(...) 74 | if(length(li)==1 & is.list(li[[1]])) li = li[[1]] 75 | result = li[[1]] 76 | for(k in 1:length(li)){ 77 | result = union(result,li[[k]]) 78 | } 79 | return(result) 80 | } 81 | -------------------------------------------------------------------------------- /R/2_geo_id.R: -------------------------------------------------------------------------------- 1 | ##' geo_download 2 | ##' 3 | ##' download gse data and get informations 4 | ##' 5 | ##' @param gse gse assession number 6 | ##' @param by_annopbrobe download data by geoquery or annoprobe 7 | ##' @param simpd get simplified pdata,drop out columns with all same values 8 | ##' @param colon_remove whether to remove duplicated columns with colons 9 | ##' @param destdir The destination directory for data downloads. 10 | ##' @param n For data with more than one ExpressionSet, specify which one to analyze 11 | ##' @return a list with exp,pd and gpl 12 | ##' @author Xiaojie Sun 13 | ##' @export 14 | ##' @examples 15 | ##' \dontrun{ 16 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 17 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 18 | ##' gse = "GSE42872" 19 | ##' a = geo_download(gse,destdir=tempdir()) 20 | ##' }else{ 21 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 22 | ##' print("Package 'AnnoProbe' needed for this function to work. 23 | ##' Please install it by install.packages('AnnoProbe')"print) 24 | ##' } 25 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 26 | ##' print("Package 'Biobase' needed for this function to work. 27 | ##' Please install it by BiocManager::install('Biobase')"print) 28 | ##' } 29 | ##' } 30 | ##' } 31 | ##' @seealso 32 | ##' \code{\link{find_anno}} 33 | 34 | geo_download <- function(gse,by_annopbrobe = TRUE, 35 | simpd = TRUE,colon_remove = FALSE, 36 | destdir = getwd(),n = 1){ 37 | if(by_annopbrobe){ 38 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 39 | stop("Package \"Biobase\" needed for this function to work. 40 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 41 | } 42 | if(!file.exists(paste0(destdir,"/",gse,"_eSet.Rdata"))){ 43 | eSet <- tryCatch({AnnoProbe::geoChina(gse, destdir = destdir) 44 | },error = function(e){555}) 45 | 46 | if(!is.list(eSet)){ 47 | warning("This data is not indexed by AnnoProbe, downloaded by GEOquery") 48 | eSet <- GEOquery::getGEO(gse,destdir = destdir,getGPL = FALSE) 49 | gset = eSet 50 | save(gset,file = paste0(destdir,"/",gse,"_eSet.Rdata")) 51 | } 52 | }else{ 53 | suppressWarnings(load(paste0(destdir,"/",gse,"_eSet.Rdata"))) 54 | eSet = gset 55 | rm(gset) 56 | } 57 | }else{ 58 | if((!by_annopbrobe) & !requireNamespace("GEOquery",quietly = TRUE)) { 59 | stop("Package \"GEOquery\" needed for this function to work. 60 | Please install it by BiocManager::install('GEOquery')",call. = FALSE) 61 | } 62 | eSet <- GEOquery::getGEO(gse,destdir = destdir,getGPL = FALSE) 63 | } 64 | if(length(n)!=1) stop("only one ExpresssionSet can be analyzed") 65 | if(length(eSet)==1 & n!=1) { 66 | n = 1 67 | warning("this data only have one ExpresssionSet object") 68 | } 69 | if(!requireNamespace("Biobase",quietly = TRUE)) { 70 | stop("Package \"Biobase\" needed for this function to work. 71 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 72 | } 73 | exp <- Biobase::exprs(eSet[[n]]) 74 | pd <- Biobase::pData(eSet[[n]]) 75 | if(simpd){ 76 | colname <- vector("character") 77 | count <- vector("integer") 78 | for (i in 1:ncol(pd)) { 79 | colname[i] = colnames(pd)[[i]] 80 | count[i] = nrow(pd[!duplicated(pd[, i]), ]) 81 | } 82 | df <- data.frame(colname, count) |> 83 | dplyr::arrange(desc(count)) |> dplyr::filter(count >1) 84 | pd <- pd[,df$colname] 85 | pd <- pd[,!(colnames(pd) %in% c("geo_accession", "supplementary_file"))] 86 | if(colon_remove){ 87 | pd = pd[,!apply(pd, 2, function(x){all(stringr::str_detect(x,": |https|www")|is.na(x)|x=="")})] 88 | colnames(pd) = stringr::str_remove(colnames(pd),":ch1") 89 | } 90 | } 91 | p1 = identical(rownames(pd),colnames(exp)) 92 | p2 = all(rownames(pd) %in% colnames(exp) & colnames(exp) %in% rownames(pd)) 93 | if(!p1) { 94 | exp = exp[,match(rownames(pd),colnames(exp))] 95 | if(!p2) { 96 | exp = exp[,intersect(rownames(pd),colnames(exp))] 97 | pd = pd[intersect(rownames(pd),colnames(exp)),] 98 | } 99 | } 100 | gpl <- eSet[[n]]@annotation 101 | pd2 = apply(pd,2,as.character) |> as.data.frame() 102 | rownames(pd2) = rownames(pd) 103 | re = list(exp=exp,pd=pd2,gpl=gpl) 104 | if(is.null(dim(exp)) | nrow(exp)==0){ 105 | warning("exp is empty") 106 | } else if (any(is.na(exp)|is.nan(exp))) { 107 | warning("NA or NAN values detected") 108 | }else if (any(exp<0)) { 109 | warning("nagtive values detected") 110 | } else{ 111 | message(paste(nrow(exp),"probes,", 112 | ncol(exp),"samples", 113 | "from",min(exp), 114 | "to",max(exp)))} 115 | return(re) 116 | } 117 | 118 | ##' find annotation package or files 119 | ##' 120 | ##' find gpl annotation package or files 121 | ##' 122 | ##' @param gpl a gpl accession 123 | ##' @param install whether to install and library the package 124 | ##' @param update whether to update the package 125 | ##' @return a list with deg data.frame, volcano plot and a list with DEGs. 126 | ##' @author Xiaojie Sun 127 | ##' @importFrom stringr str_remove_all 128 | ##' @importFrom stringr str_to_upper 129 | ##' @importFrom BiocManager install 130 | ##' @export 131 | ##' @examples 132 | ##' find_anno("GPL570") 133 | ##' @seealso 134 | ##' \code{\link{geo_download}} 135 | 136 | find_anno <-function(gpl,install = FALSE,update = FALSE){ 137 | gpl = str_to_upper(gpl) 138 | if(!any(pkg_all$gpl==gpl)) { 139 | if(gpl %in% setdiff(exists_anno_list,pkg_all$gpl)){ 140 | ml1 = str_remove_all(paste0("`ids <- AnnoProbe::idmap\\(","\\'",gpl,"\\'","\\)`"),"\\\\") 141 | message(paste0("no annotation packages avliable,please use ",ml1)) 142 | message("if you get error by this code ,please try different `type` parameters") 143 | }else{ 144 | message("no annotation avliable in Bioconductor and AnnoProbe") 145 | } 146 | }else { 147 | qz = pkg_all$bioc_package[pkg_all$gpl== gpl] 148 | ml1 = str_remove_all(paste0("`ids <- AnnoProbe::idmap\\(","\\'",gpl,"\\'","\\)`"),"\\\\") 149 | ml2 = str_remove_all(paste0("`library\\(",qz,".db","\\)",";","ids <- toTable\\(",qz,"SYMBOL\\)`"),"\\\\") 150 | if(install){ 151 | if(!suppressMessages(requireNamespace(paste0(qz,".db")))){ 152 | BiocManager::install(paste0(qz,".db"),update = update,ask = FALSE) 153 | suppressMessages(requireNamespace(paste0(qz,".db"))) 154 | } 155 | } 156 | if(!(gpl %in% exists_anno_list)) { 157 | message(paste0(ml2," is avaliable")) 158 | }else { 159 | message(paste0(ml2," and ",ml1 ," are both avaliable")) 160 | message("if you get error by idmap, please try different `type` parameters") 161 | } 162 | } 163 | } 164 | 165 | ##' get count from GEO 166 | ##' 167 | ##' get RNA-seq count file from GEO database 168 | ##' 169 | ##' @inheritParams geo_download 170 | ##' @param download download the txt file or not 171 | ##' @importFrom stringr str_starts 172 | ##' @importFrom stringr str_to_upper 173 | ##' @return a list with deg data.frame, volcano plot and a list with DEGs. 174 | ##' @author Xiaojie Sun 175 | ##' @export 176 | ##' @examples 177 | ##' get_count_txt("GSE162550",destdir = tempdir()) 178 | ##' @seealso 179 | ##' \code{\link{geo_download}} 180 | 181 | get_count_txt <- function(gse,destdir = getwd(),download = FALSE){ 182 | if(!str_starts(gse,"GSE|gse"))stop("wrong GSE accession") 183 | gse = str_to_upper(gse) 184 | url = paste0("https://www.ncbi.nlm.nih.gov/geo/download/?type=rnaseq_counts&acc=", 185 | gse, 186 | "&format=file&file=", 187 | gse, 188 | "_raw_counts_GRCh38.p13_NCBI.tsv.gz") 189 | message(url) 190 | 191 | if(download){utils::download.file(url,destfile = paste0(destdir,gse,"_raw_counts_GRCh38.p13_NCBI.tsv.gz")) 192 | message("If the download fails, check that your data is RNA-seq data.")} 193 | } 194 | 195 | 196 | ##' get gpl txt from GEO 197 | ##' 198 | ##' get gpl annotation txt file from GEO database 199 | ##' 200 | ##' @inheritParams geo_download 201 | ##' @inheritParams get_count_txt 202 | ##' @param gpl gpl accession from GEO database 203 | ##' @importFrom stringr str_starts 204 | ##' @importFrom stringr str_to_upper 205 | ##' @return a list with deg data.frame, volcano plot and a list with DEGs. 206 | ##' @author Xiaojie Sun 207 | ##' @export 208 | ##' @examples 209 | ##' get_gpl_txt("GPL23270",destdir = tempdir()) 210 | ##' @seealso 211 | ##' \code{\link{geo_download}} 212 | 213 | get_gpl_txt = function(gpl,destdir = getwd(),download = FALSE){ 214 | if(!str_starts(gpl,"GPL|gpl"))stop("wrong GPL accession") 215 | gpl = str_to_upper(gpl) 216 | url = paste0("https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=", 217 | gpl, 218 | "&targ=self&form=text&view=data") 219 | message(url) 220 | if(download){utils::download.file(url,destfile = paste0(gpl,".txt")) 221 | message("If the download fails, check that your data is microarray data.")} 222 | } 223 | 224 | 225 | utils::globalVariables(c("pkg_all","exists_anno_list","gset")) 226 | -------------------------------------------------------------------------------- /R/3_get_deg.R: -------------------------------------------------------------------------------- 1 | ##' get_deg 2 | ##' 3 | ##' do differential analysis according to expression set and group information 4 | ##' 5 | ##' @inheritParams draw_pca 6 | ##' @inheritParams draw_volcano 7 | ##' @inheritParams trans_exp_new 8 | ##' @param entriz whether convert symbols to entriz ids 9 | ##' @param ids a data.frame with 2 columns,including probe_id and symbol 10 | ##' @return a deg data.frame with 10 columns 11 | ##' @author Xiaojie Sun 12 | ##' @importFrom limma lmFit 13 | ##' @importFrom limma eBayes 14 | ##' @importFrom limma topTable 15 | ##' @importFrom clusterProfiler bitr 16 | ##' @importFrom dplyr mutate 17 | ##' @importFrom dplyr inner_join 18 | ##' @export 19 | ##' @examples 20 | ##' \dontrun{ 21 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 22 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 23 | ##' gse = "GSE42872" 24 | ##' a = geo_download(gse,destdir=tempdir()) 25 | ##' find_anno(geo$gpl) 26 | ##' ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 27 | ##' Group = rep(c("control","treat"),each = 3) 28 | ##' Group = factor(Group) 29 | ##' deg = get_deg(geo$exp,Group,ids,entriz = FALSE) 30 | ##' head(deg) 31 | ##' }else{ 32 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 33 | ##' warning("Package 'AnnoProbe' needed for this function to work. 34 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 35 | ##' } 36 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 37 | ##' warning("Package 'Biobase' needed for this function to work. 38 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 39 | ##' } 40 | ##' } 41 | ##' } 42 | ##' @seealso 43 | ##' \code{\link{multi_deg}};\code{\link{get_deg_all}} 44 | 45 | get_deg <- function(exp, 46 | group_list, 47 | ids, 48 | logFC_cutoff=1, 49 | pvalue_cutoff=0.05, 50 | adjust = FALSE, 51 | entriz = TRUE, 52 | species = "human") { 53 | p3 <- is.factor(group_list) 54 | if(!p3) { 55 | group_list = factor(group_list) 56 | warning("group_list was covert to factor") 57 | } 58 | if(nlevels(group_list)==2){ 59 | if(ncol(exp)!=length(group_list))stop("wrong group_list or exp") 60 | if(ncol(ids)!=2)stop("wrong ids pramater,it should be a data.frame with probe_id and symbol") 61 | colnames(ids) = c("probe_id","symbol") 62 | if(!is.character(ids$probe_id)) ids$probe_id = as.character(ids$probe_id) 63 | 64 | design=stats::model.matrix(~group_list) 65 | fit=lmFit(exp,design) 66 | fit=eBayes(fit) 67 | deg=topTable(fit,coef=2,number = Inf) 68 | 69 | if("ID" %in% colnames(deg)){ 70 | deg <- mutate(deg,probe_id=deg$ID) 71 | }else{ 72 | deg <- mutate(deg,probe_id=rownames(deg)) 73 | } 74 | ids = stats::na.omit(ids) 75 | ids = ids[!duplicated(ids$symbol),] 76 | deg <- inner_join(deg,ids,by="probe_id") 77 | if(adjust){ 78 | k1 = (deg$adj.P.Val < pvalue_cutoff)&(deg$logFC < -logFC_cutoff) 79 | k2 = (deg$adj.P.Val < pvalue_cutoff)&(deg$logFC > logFC_cutoff) 80 | }else{ 81 | k1 = (deg$P.Value < pvalue_cutoff)&(deg$logFC < -logFC_cutoff) 82 | k2 = (deg$P.Value < pvalue_cutoff)&(deg$logFC > logFC_cutoff) 83 | } 84 | 85 | change = ifelse(k1, 86 | "down", 87 | ifelse(k2, 88 | "up", 89 | "stable")) 90 | deg <- mutate(deg,change) 91 | 92 | if(entriz){ 93 | if(species == "human"){ 94 | if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 95 | stop("Package \"org.Hs.eg.db\" needed for this function to work. 96 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 97 | } 98 | or = org.Hs.eg.db::org.Hs.eg.db 99 | } 100 | if(species == "mouse"){ 101 | if(!requireNamespace("org.Mm.eg.db",quietly = TRUE)) { 102 | warning("Package \"org.Mm.eg.db\" needed for this function to work. 103 | Please install it by BiocManager::install('org.Mm.eg.db')",call. = FALSE) 104 | } 105 | or = org.Mm.eg.db::org.Mm.eg.db 106 | } 107 | if(species == "rat"){ 108 | if(!requireNamespace("org.Rn.eg.db",quietly = TRUE)) { 109 | warning("Package \"org.Rn.eg.db\" needed for this function to work. 110 | Please install it by BiocManager::install('org.Rn.eg.db')",call. = FALSE) 111 | } 112 | or = org.Rn.eg.db::org.Rn.eg.db 113 | } 114 | 115 | s2e <- tryCatch({ 116 | bitr(deg$symbol,fromType = "SYMBOL",toType = "ENTREZID",OrgDb = or) 117 | },error = function(e){666}) 118 | if(!is.character(s2e)){ 119 | deg <- inner_join(deg,s2e,by=c("symbol"="SYMBOL")) 120 | deg <- deg[!duplicated(deg$symbol),] 121 | }else{ 122 | warning("Entriz ID conversion failed, please check the previous warning.") 123 | } 124 | } 125 | }else{ 126 | deg <-multi_deg(exp = exp, 127 | group_list = group_list, 128 | ids = ids, 129 | logFC_cutoff = logFC_cutoff, 130 | pvalue_cutoff = pvalue_cutoff, 131 | adjust = adjust, 132 | entriz = entriz, 133 | species = species) 134 | } 135 | return(deg) 136 | } 137 | -------------------------------------------------------------------------------- /R/4_multi_deg.R: -------------------------------------------------------------------------------- 1 | ##' multi_deg 2 | ##' 3 | ##' do diffiential analysis according to expression set and group information 4 | ##' 5 | ##' @inheritParams get_deg 6 | ##' @param ids a data.frame with 2 columns,including probe_id and symbol 7 | ##' @return a deg data.frame with 10 columns 8 | ##' @author Xiaojie Sun 9 | ##' @importFrom limma lmFit 10 | ##' @importFrom limma eBayes 11 | ##' @importFrom limma topTable 12 | ##' @importFrom limma makeContrasts 13 | ##' @importFrom limma contrasts.fit 14 | ##' @importFrom clusterProfiler bitr 15 | ##' @importFrom dplyr mutate 16 | ##' @importFrom dplyr inner_join 17 | ##' @export 18 | ##' @examples 19 | ##' \dontrun{ 20 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 21 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 22 | ##' gse = "GSE474" 23 | ##' geo = geo_download(gse,destdir=tempdir()) 24 | ##' geo$exp[1:4,1:4] 25 | ##' geo$exp=log2(geo$exp+1) 26 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"), 27 | ##' "MObese",ifelse(stringr::str_detect(geo$pd$title,"NonObese"), 28 | ##' "NonObese","Obese")) 29 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 30 | ##' find_anno(geo$gpl) 31 | ##' ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 32 | ##' deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 33 | ##' names(deg) 34 | ##' head(deg[[1]]) 35 | ##' head(deg[[2]]) 36 | ##' head(deg[[3]]) 37 | ##' }else{ 38 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 39 | ##' warning("Package 'AnnoProbe' needed for this function to work. 40 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 41 | ##' } 42 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 43 | ##' warning("Package 'Biobase' needed for this function to work. 44 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 45 | ##' } 46 | ##' } 47 | ##' } 48 | ##' @seealso 49 | ##' \code{\link{get_deg}};\code{\link{multi_deg_all}} 50 | 51 | multi_deg <- function(exp, 52 | group_list, 53 | ids, 54 | logFC_cutoff = 1, 55 | pvalue_cutoff = 0.05, 56 | adjust = FALSE, 57 | species = "human", 58 | entriz = TRUE) { 59 | p1 <- all(apply(exp,2,is.numeric)) 60 | if(!p1) stop("exp must be a numeric matrix") 61 | p2 <- (sum(!duplicated(group_list)) > 1) 62 | if(!p2) stop("group_list must more than 1") 63 | p3 <- is.factor(group_list) 64 | if(!p3) stop("group_list must be a factor") 65 | if(ncol(exp)!=length(group_list))stop("wrong group_list or exp") 66 | if(ncol(ids)!=2)stop("wrong ids pramater,it should be a data.frame with probe_id and symbol") 67 | colnames(ids) = c("probe_id","symbol") 68 | px <- levels(group_list) 69 | if(length(px)==3){ 70 | design=stats::model.matrix(~0+group_list) 71 | colnames(design)=c("x1","x2","x3") 72 | px <- levels(group_list) 73 | contrast.matrix <- makeContrasts("x2-x1", 74 | "x3-x1", 75 | "x3-x2", 76 | levels=design) 77 | rownames(contrast.matrix) = levels(group_list) 78 | colnames(contrast.matrix) = c(paste0(px[2],"-",px[1]), 79 | paste0(px[3],"-",px[1]), 80 | paste0(px[3],"-",px[2])) 81 | colnames(design) = levels(group_list) 82 | }else if(length(px)==4){ 83 | design=stats::model.matrix(~0+group_list) 84 | colnames(design)=c("x1","x2","x3","x4") 85 | px <- levels(group_list) 86 | contrast.matrix <- makeContrasts("x2-x1", 87 | "x3-x1", 88 | "x4-x1", 89 | levels=design) 90 | rownames(contrast.matrix) = levels(group_list) 91 | colnames(contrast.matrix) = c(paste0(px[2],"-",px[1]), 92 | paste0(px[3],"-",px[1]), 93 | paste0(px[4],"-",px[1])) 94 | colnames(design) = levels(group_list) 95 | }else if(length(px)==5){ 96 | design=stats::model.matrix(~0+group_list) 97 | colnames(design)=c("x1","x2","x3","x4","x5") 98 | px <- levels(group_list) 99 | contrast.matrix <- makeContrasts("x2-x1", 100 | "x3-x1", 101 | "x4-x1", 102 | "x5-x1", 103 | levels=design) 104 | rownames(contrast.matrix) = levels(group_list) 105 | colnames(contrast.matrix) = c(paste0(px[2],"-",px[1]), 106 | paste0(px[3],"-",px[1]), 107 | paste0(px[4],"-",px[1]), 108 | paste0(px[5],"-",px[1])) 109 | colnames(design) = levels(group_list) 110 | } 111 | fit <- lmFit(exp, design) 112 | fit2 <- contrasts.fit(fit, contrast.matrix) 113 | fit2 <- eBayes(fit2) 114 | if(length(px)>3) n = 1:(length(px)-1) else{n = 1:length(px)} 115 | deg = lapply(n, function(i){ 116 | topTable(fit2,coef = i,number = Inf) 117 | }) 118 | names(deg) = colnames(contrast.matrix) 119 | 120 | for(i in 1:length(deg)){ 121 | deg[[i]] <- mutate(deg[[i]],probe_id=rownames(deg[[i]])) 122 | ids = stats::na.omit(ids) 123 | if(!is.character(ids$probe_id)) ids$probe_id = as.character(ids$probe_id) 124 | ids = ids[!duplicated(ids$symbol),] 125 | ids = ids[!duplicated(ids$probe_id),] 126 | deg[[i]] <- inner_join(deg[[i]],ids,by="probe_id") 127 | if(adjust){ 128 | k1 = (deg[[i]]$adj.P.Val < pvalue_cutoff)&(deg[[i]]$logFC < -logFC_cutoff) 129 | k2 = (deg[[i]]$adj.P.Val < pvalue_cutoff)&(deg[[i]]$logFC > logFC_cutoff) 130 | }else{ 131 | k1 = (deg[[i]]$P.Value < pvalue_cutoff)&(deg[[i]]$logFC < -logFC_cutoff) 132 | k2 = (deg[[i]]$P.Value < pvalue_cutoff)&(deg[[i]]$logFC > logFC_cutoff) 133 | } 134 | change = ifelse(k1,"down",ifelse(k2,"up","stable")) 135 | deg[[i]] <- mutate(deg[[i]],change) 136 | if(entriz){ 137 | if(species == "human"){ 138 | if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 139 | stop("Package \"org.Hs.eg.db\" needed for this function to work. 140 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 141 | } 142 | or = org.Hs.eg.db::org.Hs.eg.db 143 | } 144 | if(species == "mouse"){ 145 | if(!requireNamespace("org.Mm.eg.db",quietly = TRUE)) { 146 | stop("Package \"org.Mm.eg.db\" needed for this function to work. 147 | Please install it by BiocManager::install('org.Mm.eg.db')",call. = FALSE) 148 | } 149 | or = org.Mm.eg.db::org.Mm.eg.db 150 | } 151 | if(species == "rat"){ 152 | if(!requireNamespace("org.Rn.eg.db",quietly = TRUE)) { 153 | stop("Package \"org.Rn.eg.db\" needed for this function to work. 154 | Please install it by BiocManager::install('org.Rn.eg.db')",call. = FALSE) 155 | } 156 | or = org.Rn.eg.db::org.Rn.eg.db 157 | } 158 | s2e <- tryCatch({ 159 | bitr(unique(deg[[i]]$symbol), fromType = "SYMBOL", 160 | toType = c( "ENTREZID"), 161 | OrgDb = or) 162 | },error = function(e){666}) 163 | if(!is.character(s2e)){ 164 | s2e <- s2e[!duplicated(s2e$SYMBOL),] 165 | deg[[i]] <- inner_join(deg[[i]],s2e,by=c("symbol"="SYMBOL")) 166 | }else{ 167 | warning("Entriz ID conversion failed, please check the previous warning.") 168 | } 169 | } 170 | } 171 | return(deg) 172 | } 173 | -------------------------------------------------------------------------------- /R/5_get_deg_all.R: -------------------------------------------------------------------------------- 1 | ##' get_deg_all 2 | ##' 3 | ##' do diffiencial analysis according to exprission set and group information 4 | ##' 5 | ##' @inheritParams draw_pca 6 | ##' @inheritParams draw_volcano 7 | ##' @inheritParams draw_heatmap 8 | ##' @inheritParams multi_deg_all 9 | ##' @param ids a data.frame with 2 columns,including probe_id and symbol 10 | ##' @param entriz logical , if TRUE ,convert symbol to entriz id. 11 | ##' @return a list with deg data.frame, volcano plot ,pca plot ,heatmap and a list with DEGs. 12 | ##' @author Xiaojie Sun 13 | ##' @importFrom patchwork wrap_plots 14 | ##' @importFrom ggplot2 ggsave 15 | ##' @importFrom stringr str_split 16 | ##' @export 17 | ##' @examples 18 | ##' \dontrun{ 19 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 20 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 21 | ##' gse = "GSE42872" 22 | ##' geo = geo_download(gse,destdir=tempdir()) 23 | ##' group_list = rep(c("A","B"),each = 3) 24 | ##' group_list = factor(group_list) 25 | ##' find_anno(geo$gpl) 26 | ##' ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 27 | ##' dcp = get_deg_all(geo$exp,group_list,ids,entriz = FALSE) 28 | ##' head(dcp$deg) 29 | ##' dcp$plots 30 | ##' }else{ 31 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 32 | ##' warning("Package 'AnnoProbe' needed for this function to work. 33 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 34 | ##' } 35 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 36 | ##' warning("Package 'Biobase' needed for this function to work. 37 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 38 | ##' } 39 | ##' } 40 | ##' } 41 | ##' @seealso 42 | ##' \code{\link{get_deg}};\code{\link{multi_deg_all}} 43 | 44 | get_deg_all <- function(exp, 45 | group_list, 46 | ids, 47 | symmetry = TRUE, 48 | my_genes = NULL, 49 | show_rownames = FALSE, 50 | cluster_cols = TRUE, 51 | color_volcano = c("#2874C5", "grey", "#f87669"), 52 | logFC_cutoff=1, 53 | pvalue_cutoff=0.05, 54 | adjust = FALSE, 55 | entriz = TRUE, 56 | n_cutoff = 2, 57 | annotation_legend = FALSE, 58 | lab = NA, 59 | species = "human") { 60 | if(nlevels(group_list)==2){ 61 | deg <- get_deg(exp,group_list,ids, 62 | logFC_cutoff=logFC_cutoff, 63 | pvalue_cutoff=pvalue_cutoff, 64 | adjust = adjust, 65 | entriz = entriz, 66 | species = species) 67 | cgs = get_cgs(deg) 68 | volcano_plot = draw_volcano(deg,pkg=4, 69 | lab =lab, 70 | pvalue_cutoff = pvalue_cutoff, 71 | logFC_cutoff=logFC_cutoff, 72 | adjust = adjust, 73 | symmetry = symmetry) 74 | pca_plot = draw_pca(exp,group_list) 75 | heatmap = draw_heatmap2(exp,group_list,deg,my_genes, 76 | show_rownames = show_rownames, 77 | n_cutoff = n_cutoff, 78 | cluster_cols = cluster_cols, 79 | annotation_legend=annotation_legend) 80 | if(as.numeric(grDevices::dev.cur())!=1) grDevices::graphics.off() 81 | result = list( 82 | deg = deg, 83 | cgs = cgs, 84 | plots = wrap_plots(heatmap,pca_plot,volcano_plot)+plot_layout(guides = 'collect') 85 | ) 86 | message(paste0(nrow(cgs$deg$down)," down genes,",nrow(cgs$deg$up)," up genes")) 87 | }else{ 88 | result <- multi_deg_all(exp, 89 | group_list, 90 | ids, 91 | logFC_cutoff = logFC_cutoff, 92 | pvalue_cutoff = pvalue_cutoff, 93 | symmetry = symmetry, 94 | my_genes = my_genes, 95 | show_rownames = show_rownames, 96 | cluster_cols = cluster_cols, 97 | color_volcano = color_volcano, 98 | adjust = adjust, 99 | entriz = entriz, 100 | species = species) 101 | } 102 | return(result) 103 | } 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /R/6_multi_deg_all.R: -------------------------------------------------------------------------------- 1 | ##' get_cgs 2 | ##' 3 | ##' extract DEGs from deg data.frame 4 | ##' 5 | ##' @inheritParams draw_volcano 6 | ##' @return a list with upgenes,downgenes,diffgenes. 7 | ##' @author Xiaojie Sun 8 | ##' @export 9 | ##' @examples 10 | ##' \dontrun{ 11 | ##' #two group 12 | ##' gse = "GSE42872" 13 | ##' geo = geo_download(gse,destdir=tempdir()) 14 | ##' group_list = rep(c("A","B"),each = 3) 15 | ##' ids = AnnoProbe::idmap('GPL6244',destdir=tempdir()) 16 | ##' deg = get_deg(geo$exp,group_list,ids) 17 | ##' cgs = get_cgs(deg) 18 | ##' #mutigroup 19 | ##' gse = "GSE474" 20 | ##' geo = geo_download(gse,destdir=tempdir()) 21 | ##' geo$exp[1:4,1:4] 22 | ##' geo$exp=log2(geo$exp+1) 23 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 24 | ##' ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 25 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 26 | ##' find_anno(geo$gpl) 27 | ##' ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 28 | ##' deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE) 29 | ##' cgs = get_cgs(deg) 30 | ##' } 31 | ##' @seealso 32 | ##' \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 33 | 34 | 35 | get_cgs <- function(deg){ 36 | if(!is.list(deg) & is.data.frame(deg))stop("deg is a data.frame or list returned by limma") 37 | cgs = list() 38 | if(is.data.frame(deg)) deg = list(deg = deg) 39 | for(i in 1:length(deg)){ 40 | cgs[[i]] = list(up = data.frame(upgenes =deg[[i]]$symbol[deg[[i]]$change=="up"], 41 | upprobes = deg[[i]]$probe_id[deg[[i]]$change=="up"], 42 | stringsAsFactors = FALSE), 43 | down = data.frame(downgenes = deg[[i]]$symbol[deg[[i]]$change=="down"], 44 | downprobes = deg[[i]]$probe_id[deg[[i]]$change=="down"], 45 | stringsAsFactors = FALSE), 46 | diff = data.frame(diffgenes = deg[[i]]$symbol[deg[[i]]$change!="stable"], 47 | diffprobes = deg[[i]]$probe_id[deg[[i]]$change!="stable"], 48 | stringsAsFactors = FALSE) 49 | ) 50 | } 51 | names(cgs) = names(deg) 52 | return(cgs) 53 | } 54 | 55 | ##' draw_volcano2 56 | ##' 57 | ##' print one or more volcano plot for Differential analysis result in data.frame fomat. 58 | ##' 59 | ##' @inheritParams draw_volcano 60 | ##' @param ... other parameters from draw_volcano 61 | ##' @return one or more volcano plot 62 | ##' @author Xiaojie Sun 63 | ##' @importFrom patchwork wrap_plots 64 | ##' @importFrom patchwork plot_layout 65 | ##' @export 66 | ##' @examples 67 | ##' \dontrun{ 68 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 69 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 70 | ##' #two group 71 | ##' gse = "GSE42872" 72 | ##' geo = geo_download(gse,destdir=tempdir()) 73 | ##' group_list = rep(c("A","B"),each = 3) 74 | ##' ids = AnnoProbe::idmap('GPL6244',destdir = tempdir()) 75 | ##' deg = get_deg(geo$exp,group_list,ids) 76 | ##' draw_volcano2(deg) 77 | ##' #multigroup 78 | ##' gse = "GSE474" 79 | ##' geo = geo_download(gse,destdir=tempdir()) 80 | ##' geo$exp[1:4,1:4] 81 | ##' geo$exp=log2(geo$exp+1) 82 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 83 | ##' ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 84 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 85 | ##' find_anno(geo$gpl) 86 | ##' ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 87 | ##' deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 88 | ##' draw_volcano2(deg) 89 | ##' draw_volcano2(deg,color = c("darkgreen","grey","darkred")) 90 | ##' }else{ 91 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 92 | ##' warning("Package 'AnnoProbe' needed for this function to work. 93 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 94 | ##' } 95 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 96 | ##' warning("Package 'Biobase' needed for this function to work. 97 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 98 | ##' } 99 | ##' } 100 | ##' } 101 | ##' @seealso 102 | ##' \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 103 | 104 | draw_volcano2 = function(deg, 105 | pkg=4, 106 | lab, 107 | ... 108 | ){ 109 | if(!is.list(deg) & is.data.frame(deg))stop("deg is a data.frame or list returned by limma") 110 | if(is.data.frame(deg)) { 111 | volcano_plots = draw_volcano( 112 | deg , 113 | pkg = pkg, 114 | lab = "logFC", 115 | ... 116 | ) 117 | }else{ 118 | volcano_plots <- lapply(1:length(deg), 119 | function(k) { 120 | draw_volcano( 121 | deg[[k]] , 122 | pkg = pkg, 123 | lab = names(deg)[k], 124 | ... 125 | ) 126 | }) 127 | volcano_plots = wrap_plots(volcano_plots)+ 128 | plot_layout(design = paste(rep(LETTERS[1:length(deg)]),collapse = "")) + 129 | plot_layout(guides = 'collect') 130 | } 131 | return(volcano_plots) 132 | } 133 | 134 | ##' draw heatmap plots 135 | ##' 136 | ##' print heatmap plots for expression matrix and group by group_list paramter 137 | ##' 138 | ##' @inheritParams draw_volcano 139 | ##' @inheritParams draw_heatmap 140 | ##' @inheritParams draw_pca 141 | ##' @param heat_union logical ,use union or intersect DEGs for heatmap 142 | ##' @param my_genes genes for pheatmap 143 | ##' @param ... other parameters from draw_heatmap 144 | ##' @return a heatmap plot according to \code{exp} and grouped by \code{group}. 145 | ##' @author Xiaojie Sun 146 | ##' @importFrom pheatmap pheatmap 147 | ##' @export 148 | ##' @examples 149 | ##' \dontrun{ 150 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 151 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 152 | ##' gse = "GSE474" 153 | ##' geo = geo_download(gse,destdir=tempdir()) 154 | ##' geo$exp[1:4,1:4] 155 | ##' geo$exp=log2(geo$exp+1) 156 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 157 | ##' ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 158 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 159 | ##' find_anno(geo$gpl) 160 | ##' ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 161 | ##' deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 162 | ##' draw_heatmap2(geo$exp,group_list,deg) 163 | ##' }else{ 164 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 165 | ##' warning("Package 'AnnoProbe' needed for this function to work. 166 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 167 | ##' } 168 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 169 | ##' warning("Package 'Biobase' needed for this function to work. 170 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 171 | ##' } 172 | ##' } 173 | ##' } 174 | ##' @seealso 175 | ##' \code{\link{draw_pca}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 176 | 177 | draw_heatmap2 <- function(exp, 178 | group_list, 179 | deg, 180 | my_genes = NULL, 181 | heat_union = TRUE,... 182 | ){ 183 | if(!is.data.frame(deg)){ 184 | m = deg[[1]] 185 | }else{ 186 | m = deg 187 | } 188 | if(all(m$probe_id %in% rownames(exp))){ 189 | exp = exp[m$probe_id,] 190 | rownames(exp) = m$symbol 191 | }else if(all(m$symbol %in% rownames(exp))) { 192 | exp = exp[m$symbol,] 193 | } 194 | if(is.null(my_genes)){ 195 | cgs = get_cgs(deg) 196 | if(length(cgs)==1){ 197 | cg = cgs[[1]]$diff$diffgenes 198 | }else{ 199 | if(heat_union){ 200 | cg = union_all(lapply(cgs,function(x)x$diff$diffgenes)) 201 | }else{ 202 | cg = intersect_all(lapply(cgs,function(x)x$diff$diffgenes)) 203 | } 204 | } 205 | }else{ 206 | cg = m$symbol[m$symbol %in% my_genes] 207 | } 208 | heatmap = draw_heatmap(exp[cg,], 209 | group_list, 210 | ...) 211 | return(heatmap) 212 | } 213 | 214 | ##' plot_deg 215 | ##' 216 | ##' plot pca plot,volcano plot,heatmap,and venn plot for Differential analysis result 217 | ##' 218 | ##' @inheritParams multi_deg_all 219 | ##' @param deg result of multi_deg or get_deg function 220 | ##' @return plots 221 | ##' @author Xiaojie Sun 222 | ##' @export 223 | ##' @examples 224 | ##' \dontrun{ 225 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 226 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 227 | ##' gse = "GSE474" 228 | ##' geo = geo_download(gse,destdir=tempdir()) 229 | ##' geo$exp[1:4,1:4] 230 | ##' geo$exp=log2(geo$exp+1) 231 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 232 | ##' ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 233 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 234 | ##' find_anno(geo$gpl) 235 | ##' ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 236 | ##' deg = get_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 237 | ##' plot_deg(geo$exp,group_list,deg) 238 | ##' }else{ 239 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 240 | ##' warning("Package 'AnnoProbe' needed for this function to work. 241 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 242 | ##' } 243 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 244 | ##' warning("Package 'Biobase' needed for this function to work. 245 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 246 | ##' } 247 | ##' } 248 | ##' } 249 | plot_deg = function(exp, 250 | group_list, 251 | deg, 252 | symmetry = TRUE, 253 | my_genes = NULL, 254 | show_rownames = FALSE, 255 | cluster_cols = TRUE, 256 | color_volcano = c("#2874C5", "grey", "#f87669"), 257 | pvalue_cutoff = 0.05, 258 | logFC_cutoff = 1, 259 | adjust = FALSE, 260 | annotation_legend = FALSE, 261 | lab = NA, 262 | species = "human" 263 | ){ 264 | cgs = get_cgs(deg) 265 | volcano_plot = draw_volcano2(deg, 266 | pkg = 4, 267 | symmetry = symmetry, 268 | color = color_volcano, 269 | pvalue_cutoff = pvalue_cutoff, 270 | logFC_cutoff = logFC_cutoff, 271 | adjust = adjust 272 | ) 273 | pca_plot = draw_pca(exp,group_list) 274 | heatmap = draw_heatmap2(exp,group_list,deg,my_genes, 275 | show_rownames = show_rownames, 276 | cluster_cols = cluster_cols) 277 | x = lapply(cgs,function(x)x$diff$diffprobes) 278 | venn = draw_venn(x," ") 279 | if(as.numeric(grDevices::dev.cur())!=1) grDevices::graphics.off() 280 | plotlist = list(heatmap,pca_plot,venn,volcano_plot) 281 | layout <- ' 282 | AABBCC 283 | AABBCC 284 | DDDDDD 285 | DDDDDD 286 | ' 287 | plots = wrap_plots(plotlist) + 288 | plot_layout(design = layout) + 289 | plot_layout(guides = 'collect') 290 | return(plots) 291 | } 292 | 293 | ##' multi_deg_all 294 | ##' 295 | ##' do diffiencial analysis according to exprission set and group information 296 | ##' 297 | ##' @inheritParams draw_pca 298 | ##' @inheritParams draw_volcano 299 | ##' @inheritParams pheatmap::pheatmap 300 | ##' @inheritParams draw_heatmap 301 | ##' @inheritParams draw_heatmap2 302 | ##' @inheritParams multi_deg 303 | ##' @param color_volcano color for volcano 304 | ##' @return a list with deg data.frame, volcano plot and a list with DEGs. 305 | ##' @author Xiaojie Sun 306 | ##' @importFrom patchwork wrap_plots 307 | ##' @importFrom stringr str_split 308 | ##' @importFrom dplyr union_all 309 | ##' @importFrom patchwork plot_layout 310 | ##' @export 311 | ##' @examples 312 | ##' \dontrun{ 313 | ##' if(requireNamespace("Biobase",quietly = TRUE)& 314 | ##' requireNamespace("AnnoProbe",quietly = TRUE)){ 315 | ##' gse = "GSE474" 316 | ##' geo = geo_download(gse,destdir=tempdir()) 317 | ##' geo$exp[1:4,1:4] 318 | ##' geo$exp=log2(geo$exp+1) 319 | ##' group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 320 | ##' ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 321 | ##' group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 322 | ##' find_anno(geo$gpl) 323 | ##' ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 324 | ##' dcp = multi_deg_all(geo$exp, 325 | ##' group_list,ids,adjust = FALSE,entriz = FALSE) 326 | ##' dcp[[3]] 327 | ##' }else{ 328 | ##' if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 329 | ##' warning("Package 'AnnoProbe' needed for this function to work. 330 | ##' Please install it by install.packages('AnnoProbe')",call. = FALSE) 331 | ##' } 332 | ##' if(!requireNamespace("Biobase",quietly = TRUE)) { 333 | ##' warning("Package 'Biobase' needed for this function to work. 334 | ##' Please install it by BiocManager::install('Biobase')",call. = FALSE) 335 | ##' } 336 | ##' } 337 | ##' } 338 | ##' @seealso 339 | ##' \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 340 | 341 | multi_deg_all <- function(exp, 342 | group_list, 343 | ids, 344 | symmetry = TRUE, 345 | my_genes = NULL, 346 | show_rownames = FALSE, 347 | cluster_cols = TRUE, 348 | color_volcano = c("#2874C5", "grey", "#f87669"), 349 | pvalue_cutoff = 0.05, 350 | logFC_cutoff = 1, 351 | adjust = FALSE, 352 | entriz = TRUE, 353 | annotation_legend = FALSE, 354 | lab = NA, 355 | species = "human" 356 | ) { 357 | deg = multi_deg( 358 | exp, 359 | group_list, 360 | ids, 361 | logFC_cutoff = logFC_cutoff, 362 | pvalue_cutoff = pvalue_cutoff, 363 | adjust = adjust, 364 | entriz = entriz, 365 | species = species 366 | ) 367 | #exp = data.frame(exp) 368 | #exp = exp[match(deg[[1]]$probe_id,rownames(exp)),] 369 | cgs = get_cgs(deg) 370 | volcano_plot = draw_volcano2(deg, 371 | pkg = 4, 372 | symmetry = symmetry, 373 | color = color_volcano, 374 | pvalue_cutoff = pvalue_cutoff, 375 | logFC_cutoff = logFC_cutoff, 376 | adjust = adjust 377 | ) 378 | pca_plot = draw_pca(exp,group_list) 379 | heatmap = draw_heatmap2(exp,group_list,deg,my_genes, 380 | show_rownames = show_rownames, 381 | cluster_cols = cluster_cols) 382 | x = lapply(cgs,function(x)x$diff$diffprobes) 383 | venn = draw_venn(x," ") 384 | if(as.numeric(grDevices::dev.cur())!=1) grDevices::graphics.off() 385 | plotlist = list(heatmap,pca_plot,venn,volcano_plot) 386 | layout <- ' 387 | AABBCC 388 | AABBCC 389 | DDDDDD 390 | DDDDDD 391 | ' 392 | result = list( 393 | deg = deg, 394 | cgs = cgs, 395 | plots = wrap_plots(plotlist) + 396 | plot_layout(design = layout) + 397 | plot_layout(guides = 'collect') 398 | ) 399 | diffprobes = lapply(cgs,function(x)x$diff$diffprobes) 400 | message(paste0(length(union_all(diffprobes))," DEGs in all,",length(intersect_all(diffprobes))," DEGs in common.")) 401 | return(result) 402 | } 403 | -------------------------------------------------------------------------------- /R/7_quick_double_enrich.R: -------------------------------------------------------------------------------- 1 | ##' quick_enrich 2 | ##' 3 | ##' do diffiencial analysis according to exprission set and group information,for human only 4 | ##' 5 | ##' @param genes a gene symbol or entrizid vector 6 | ##' @param kkgo_file Rdata filename for kegg and go result 7 | ##' @param destdir destdir to save kkgofile 8 | ##' @inheritParams trans_exp_new 9 | ##' @return enrichment results and dotplots 10 | ##' @author Xiaojie Sun 11 | ##' @importFrom clusterProfiler bitr 12 | ##' @importFrom clusterProfiler enrichKEGG 13 | ##' @importFrom clusterProfiler enrichGO 14 | ##' @importFrom clusterProfiler dotplot 15 | ##' @importFrom clusterProfiler setReadable 16 | ##' @importFrom ggplot2 facet_grid 17 | ##' @export 18 | ##' @examples 19 | ##' \dontrun{ 20 | ##' if(requireNamespace("org.Hs.eg.db",quietly = TRUE)){ 21 | ##' head(genes) 22 | ##' g = quick_enrich(genes,destdir = tempdir()) 23 | ##' names(g) 24 | ##' g[[1]][1:4,1:4] 25 | ##' g[[3]] 26 | ##' g[[4]] 27 | ##' }else{ 28 | ##' warning("Package 'org.Hs.eg.db' needed for this function to work. 29 | ##' Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 30 | ##' } 31 | ##' } 32 | ##' @seealso 33 | ##' \code{\link{double_enrich}} 34 | 35 | quick_enrich <- function(genes, 36 | kkgo_file = "kkgo_file.Rdata", 37 | destdir = getwd(), 38 | species = "human"){ 39 | if(any(is.na(suppressWarnings(as.numeric(genes))))){ 40 | if(species == "human"){ 41 | if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 42 | stop("Package \"org.Hs.eg.db\" needed for this function to work. 43 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 44 | } 45 | or = org.Hs.eg.db::org.Hs.eg.db 46 | } 47 | if(species == "mouse"){ 48 | if(!requireNamespace("org.Mm.eg.db",quietly = TRUE)) { 49 | stop("Package \"org.Mm.eg.db\" needed for this function to work. 50 | Please install it by BiocManager::install('org.Mm.eg.db')",call. = FALSE) 51 | } 52 | or = org.Mm.eg.db::org.Mm.eg.db 53 | } 54 | if(species == "rat"){ 55 | if(!requireNamespace("org.Rn.eg.db",quietly = TRUE)) { 56 | stop("Package \"org.Rn.eg.db\" needed for this function to work. 57 | Please install it by BiocManager::install('org.Rn.eg.db')",call. = FALSE) 58 | } 59 | or = org.Rn.eg.db::org.Rn.eg.db 60 | } 61 | s2e <- bitr(genes, fromType = "SYMBOL", 62 | toType = "ENTREZID", 63 | OrgDb = or) 64 | s2e <- s2e[!duplicated(s2e$SYMBOL),] 65 | genes = s2e$ENTREZID 66 | } 67 | f = paste0(destdir,"/",kkgo_file) 68 | if(!file.exists(f)){ 69 | if(species == "human"){ 70 | or = "org.Hs.eg.db" 71 | orgs = 'hsa' 72 | }else if(species == 'mouse'){ 73 | or = "org.Mm.eg.db" 74 | orgs = 'mmu' 75 | }else if(species == 'rat'){ 76 | or = "org.Rn.eg.db" 77 | orgs = 'rno' 78 | } 79 | kk <- enrichKEGG(gene = genes, 80 | organism = orgs, 81 | pvalueCutoff = 0.05) 82 | if(!is.null(kk)){kk = setReadable(kk,OrgDb = or,keyType = "ENTREZID")} 83 | go <- enrichGO(genes, 84 | OrgDb = or, 85 | ont="all", 86 | readable = TRUE) 87 | save(kk,go,file = f) 88 | } 89 | load(f) 90 | k1 = sum(kk@result$p.adjust <0.05) 91 | k2 = sum(go@result$p.adjust <0.05) 92 | if (k1 == 0|is.null(k1)) { 93 | kk.dot = "no pathway enriched" 94 | } else{ 95 | kk.dot = dotplot(kk) 96 | } 97 | 98 | if (k2 == 0|is.null(k2)) { 99 | go.dot = "no terms enriched" 100 | } else{ 101 | go.dot = dotplot(go, split="ONTOLOGY",font.size =10,showCategory = 5)+ 102 | facet_grid(ONTOLOGY~., scales="free") 103 | } 104 | result = list(kk = kk,go = go,kk.dot = kk.dot,go.dot = go.dot) 105 | return(result) 106 | } 107 | 108 | ##' draw enrichment bar plots for both up and down genes 109 | ##' 110 | ##' draw enrichment bar plots for both up and down genes,for human only. 111 | ##' 112 | ##' @param deg a data.frame contains at least two columns:"ENTREZID" and "change" 113 | ##' @param n how many terms will you perform for up and down genes respectively 114 | ##' @param color color for bar plot 115 | ##' @return a list with kegg and go bar plot according to up and down genes enrichment result. 116 | ##' @author Xiaojie Sun 117 | ##' @importFrom stringr str_to_lower 118 | ##' @importFrom stringr str_wrap 119 | ##' @importFrom dplyr mutate 120 | ##' @importFrom dplyr arrange 121 | ##' @importFrom ggplot2 ggplot 122 | ##' @importFrom ggplot2 geom_bar 123 | ##' @importFrom ggplot2 coord_flip 124 | ##' @importFrom ggplot2 theme_light 125 | ##' @importFrom ggplot2 ylim 126 | ##' @importFrom ggplot2 scale_x_discrete 127 | ##' @importFrom ggplot2 scale_y_continuous 128 | ##' @importFrom ggplot2 theme 129 | ##' @export 130 | ##' @examples 131 | ##' \dontrun{ 132 | ##' if(requireNamespace("org.Hs.eg.db",quietly = TRUE)& 133 | ##' requireNamespace("labeling",quietly = TRUE)){ 134 | ##' double_enrich(deg) 135 | ##' }else{ 136 | ##' if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 137 | ##' warning("Package 'org.Hs.eg.db' needed for this function to work. 138 | ##' Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 139 | ##' } 140 | ##' if(!requireNamespace("labeling",quietly = TRUE)) { 141 | ##' warning("Package 'labeling' needed for this function to work. 142 | ##' Please install it by install.packages('labeling')",call. = FALSE) 143 | ##' } 144 | ##' } 145 | ##' } 146 | ##' @seealso 147 | ##' \code{\link{quick_enrich}} 148 | 149 | double_enrich <- function(deg,n = 10,color = c("#2874C5", "#f87669")){ 150 | 151 | if(!requireNamespace("labeling",quietly = TRUE)) { 152 | stop("Package \"labeling\" needed for this function to work. Please install it byby install.packages('labeling')",call. = FALSE) 153 | } 154 | deg$change = str_to_lower(deg$change) 155 | up = quick_enrich(deg$ENTREZID[deg$change=="up"],"up.rdata",destdir = tempdir()) 156 | down = quick_enrich(deg$ENTREZID[deg$change=="down"],"down.rdata",destdir = tempdir()) 157 | if(!is.null(up$kk) & !is.null(down$kk) &!is.null(up$go) &!is.null(up$go)){ 158 | up$kk@result = mutate(up$kk@result,change = "up") 159 | down$kk@result = mutate(down$kk@result,change = "down") 160 | 161 | kk = rbind(up$kk@result[1:n,],down$kk@result[1:n,]) 162 | up$go@result = mutate(up$go@result,change = "up") 163 | down$go@result = mutate(down$go@result,change = "down") 164 | go = rbind(up$go@result[1:n,],down$go@result[1:n,]) 165 | ud_enrich = function(df){ 166 | df$pl = ifelse(df$change == "up",-log10(df$p.adjust),log10(df$p.adjust)) 167 | df = arrange(df,change,pl) 168 | df$Description = factor(df$Description,levels = unique(df$Description),ordered = TRUE) 169 | tmp = with(df, labeling::extended(range(pl)[1], range(pl)[2], m = 5)) 170 | lm = tmp[c(1,length(tmp))] 171 | lm = c(floor(min(df$pl)),ceiling(max(df$pl))) 172 | ggplot(df, aes(x=Description, y= pl)) + 173 | geom_bar(stat='identity', aes(fill=change), width=.7)+ 174 | scale_fill_manual(values = color)+ 175 | coord_flip()+ 176 | theme_light() + 177 | ylim(lm)+ 178 | scale_x_discrete(labels=function(x) str_wrap(x, width=30))+ 179 | scale_y_continuous(breaks = tmp, 180 | labels = abs(tmp))+ 181 | theme( 182 | panel.border = element_blank() 183 | ) 184 | } 185 | result = list(kp = ud_enrich(kk), 186 | gp = ud_enrich(go)) 187 | return(result) 188 | }else { 189 | warning("no pathway enriched in kegg or go,return results from quick_enrich") 190 | result = list(up = up, 191 | down = down) 192 | return(result) 193 | } 194 | 195 | } 196 | 197 | utils::globalVariables(c("change","pl","Description")) 198 | 199 | 200 | -------------------------------------------------------------------------------- /R/8_tcga_group_trans_exp.R: -------------------------------------------------------------------------------- 1 | ##' make_tcga_group 2 | ##' 3 | ##' make tcga group for given tcga expression matrix 4 | ##' 5 | ##' @inheritParams trans_exp 6 | ##' @importFrom stringr str_starts 7 | ##' @importFrom stringr str_sub 8 | ##' @export 9 | ##' @return a group factor with normal and tumor ,correspond to colnames for expression matrix 10 | ##' @author Xiaojie Sun 11 | ##' @examples 12 | ##' k = make_tcga_group(exp_hub1);table(k) 13 | ##' @seealso 14 | ##' \code{\link{sam_filter}};\code{\link{match_exp_cl}} 15 | 16 | make_tcga_group <- function(exp){ 17 | k1 = stringr::str_starts(colnames(exp),"TCGA") 18 | if(!any(k1))stop("no TCGA samples detected,please check it") 19 | k2 = suppressWarnings(as.numeric(stringr::str_sub(colnames(exp),14,15))<10) 20 | group_list = ifelse(k1&k2,"tumor","normal") 21 | group_list = factor(group_list,levels = c("normal","tumor")) 22 | return(group_list) 23 | } 24 | 25 | ##' trans_exp 26 | ##' 27 | ##' transform rownames of TCGA or TCGA_Gtex expression set from gdc or xena,from ensembl id to gene symbol 28 | ##' 29 | ##' @param exp TCGA or TCGA_Gtex expression set from gdc or xena 30 | ##' @param mrna_only only keep mrna rows in result 31 | ##' @param lncrna_only only keep lncrna rows in result 32 | ##' @param gtex logical,whether including Gtex data 33 | ##' @return a transformed expression set with symbol 34 | ##' @author Xiaojie Sun 35 | ##' @importFrom stringr str_detect 36 | ##' @importFrom stringr str_remove 37 | ##' @importFrom dplyr inner_join 38 | ##' @export 39 | ##' @examples 40 | ##' exp = matrix(rnorm(1000),ncol = 10) 41 | ##' rownames(exp) = sample(mRNA_annov23$gene_id,100) 42 | ##' colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 43 | ##' k = trans_exp(exp) 44 | ##' @seealso 45 | ##' \code{\link{trans_array}} 46 | 47 | trans_exp = function(exp,mrna_only = FALSE, 48 | lncrna_only = FALSE,gtex = FALSE){ 49 | k00 = any(str_detect(colnames(exp),"TCGA")) 50 | if(!k00)warning("this expression set probably not from TCGA,please ensure it") 51 | k0 = any(str_detect(colnames(exp),"GTEX")) 52 | kd = any(str_detect(rownames(exp),"\\.")) 53 | if((!(k0|gtex))){ 54 | lanno = lnc_anno 55 | manno = mRNA_anno 56 | }else if(k00){ 57 | lanno = lnc_annov23 58 | manno = mRNA_annov23 59 | } 60 | if(!kd){ 61 | lanno$gene_id = str_remove(lanno$gene_id,"\\.\\d*") 62 | manno$gene_id = str_remove(manno$gene_id,"\\.\\d*") 63 | } 64 | n1 = sum(rownames(exp) %in% manno$gene_id) 65 | k1 = length(n1)/nrow(exp)< 0.25 & length(n1)<5000 66 | n2 = sum(rownames(exp) %in% lanno$gene_id) 67 | k2 = length(n2)/nrow(exp)< 0.25 & length(n2)<5000 68 | mRNA_exp = exp[rownames(exp) %in% manno$gene_id,] 69 | tmp = data.frame(gene_id = rownames(exp)) 70 | x = dplyr::inner_join(tmp,manno,by = "gene_id") 71 | mRNA_exp = mRNA_exp[!duplicated(x$gene_name),] 72 | x = x[!duplicated(x$gene_name),] 73 | rownames(mRNA_exp) = x$gene_name 74 | lnc_exp = exp[rownames(exp) %in% lanno$gene_id,] 75 | tmp = data.frame(gene_id = rownames(exp)) 76 | x = dplyr::inner_join(tmp,lanno,by = "gene_id") 77 | lnc_exp = lnc_exp[!duplicated(x$gene_name),] 78 | x = x[!duplicated(x$gene_name),] 79 | rownames(lnc_exp) = x$gene_name 80 | message(paste0(nrow(mRNA_exp), 81 | " of genes successfully mapping to mRNA,", 82 | nrow(lnc_exp), 83 | " of genes successfully mapping to lncRNA")) 84 | if(mrna_only){ 85 | return(mRNA_exp) 86 | }else if(lncrna_only){ 87 | return(lnc_exp) 88 | }else{ 89 | expa = rbind(mRNA_exp,lnc_exp) 90 | k = !duplicated(rownames(expa)) 91 | expa = expa[k,] 92 | return(expa) 93 | message(paste0(sum(!k), 94 | " of duplicaterd genes removed")) 95 | } 96 | } 97 | utils::globalVariables(c("lnc_anno","mRNA_anno","lnc_annov23","mRNA_annov23")) 98 | 99 | ##' trans_array 100 | ##' 101 | ##' transform rownames for microarray or rnaseq expression matrix 102 | ##' 103 | ##' @param exp microarray expression matrix with probe_id as rownames 104 | ##' @param ids data.frame with original rownames and new rownames 105 | ##' @param from colname for original rownames 106 | ##' @param to colname for new rownames 107 | ##' @return a transformed expression set with new rownames 108 | ##' @author Xiaojie Sun 109 | ##' @export 110 | ##' @examples 111 | ##' exp = matrix(1:50,nrow = 10) 112 | ##' rownames(exp) = paste0("g",1:10) 113 | ##' ids = data.frame(probe_id = paste0("g",1:10), 114 | ##' symbol = paste0("G",c(1:9,9))) 115 | ##' trans_array(exp,ids) 116 | ##' @seealso 117 | ##' \code{\link{trans_exp}} 118 | 119 | trans_array = function(exp,ids,from = "probe_id", 120 | to = "symbol"){ 121 | if(!is.character(ids[,from])) ids[,from] = as.character(ids[,from]) 122 | a = intersect(rownames(exp),ids[,from]) 123 | ids = ids[!duplicated(ids[,to]),] 124 | exp = exp[rownames(exp) %in% ids[,from],] 125 | ids = ids[ids[,from]%in% rownames(exp),] 126 | exp = exp[ids[,from],] 127 | rownames(exp)=ids[,to] 128 | message(paste0(nrow(exp)," rownames transformed after duplicate rows removed")) 129 | return(exp) 130 | } 131 | 132 | ##' sam_filter 133 | ##' 134 | ##' drop duplicated samples from the same patients 135 | ##' 136 | ##' @param exp TCGA or TCGA_Gtex expression set from gdc or xena 137 | ##' @return a transformed expression set without duplicated samples 138 | ##' @author Xiaojie Sun 139 | ##' @export 140 | ##' @examples 141 | ##' cod[1:4,1:4] 142 | ##' dim(cod) 143 | ##' cod2 = sam_filter(cod) 144 | ##' dim(cod2) 145 | ##' g = make_tcga_group(cod);table(g) 146 | ##' library(stringr) 147 | ##' table(!duplicated(str_sub(colnames(cod[,g=="tumor"]),1,12))) 148 | ##' @seealso 149 | ##' \code{\link{make_tcga_group}};\code{\link{match_exp_cl}} 150 | 151 | sam_filter = function(exp){ 152 | exp = exp[,order(colnames(exp))] 153 | n1 = ncol(exp) 154 | group = make_tcga_group(exp) 155 | exptumor = exp[,group == "tumor"] 156 | 157 | expnormol = exp[,group == "normal"] 158 | exptumor = exptumor[,!duplicated(str_sub(colnames(exptumor),1,12))] 159 | expnormol = expnormol[,!duplicated(str_sub(colnames(expnormol),1,12))] 160 | 161 | exp = cbind(exptumor,expnormol) 162 | message(paste("filtered",n1-ncol(exp),"samples.")) 163 | return(exp) 164 | } 165 | 166 | 167 | ##' match_exp_cl 168 | ##' 169 | ##' match exp and clinical data from TCGA 170 | ##' 171 | ##' @param exp TCGA expression set 172 | ##' @param cl TCGA clinical data.frame 173 | ##' @param id_column which column contains patient ids, column number or colnmn name. 174 | ##' @param sample_centric logical,deault T,keep all samples from the same patients.if FALSE,keep only one tumor sample for one patient. 175 | ##' @return a transformed clinical data.frame with sample ids. 176 | ##' @author Xiaojie Sun 177 | ##' @export 178 | ##' @examples 179 | ##' a = match_exp_cl(exp_hub1,meta1[,2:4],"X_PATIENT") 180 | ##' exp_matched = a[[1]] 181 | ##' cl_matched = a[[2]] 182 | ##' b = match_exp_cl(exp_hub1,meta1[,2:4],"X_PATIENT",sample_centric = FALSE) 183 | ##' exp_matched = b[[1]] 184 | ##' cl_matched = b[[2]] 185 | ##' @seealso 186 | ##' \code{\link{make_tcga_group}};\code{\link{sam_filter}} 187 | 188 | match_exp_cl = function(exp,cl,id_column = "id",sample_centric = TRUE){ 189 | colnames(cl)[colnames(cl)==id_column] = "id" 190 | cl = cl[cl$id %in% substr(colnames(exp),1,12),] 191 | exp = exp[,substr(colnames(exp),1,12) %in% cl$id] 192 | patient <- substr(colnames(exp),1,12) 193 | if(nrow(cl)==0) stop("your exp or cl doesn't match,please check them.") 194 | da = data.frame(sample_id = colnames(exp), 195 | id = patient) 196 | cl = merge(da,cl,by ="id",all.y = TRUE) 197 | cl = cl[match(colnames(exp),cl$sample_id),] 198 | if(!sample_centric) { 199 | Group = make_tcga_group(exp) 200 | exp = exp[,Group=="tumor"] 201 | cl = cl[Group=="tumor",] 202 | cl = cl[order(colnames(exp)),] 203 | exp = exp[,sort(colnames(exp))] 204 | exp = exp[,!duplicated(cl$id)] 205 | cl = cl[!duplicated(cl$id),] 206 | } 207 | k = identical(colnames(exp),cl$sample_id) 208 | if(k)message("match successfully") 209 | rownames(cl) = cl$sample_id 210 | compiler::setCompilerOptions(suppressAll = TRUE) 211 | return(list(exp_matched = exp, 212 | cl_matched = cl)) 213 | message("New version of tinyarray canceled global assigning inside the package, 214 | please obtain exp_matched and cl_matched by split this list result.") 215 | } 216 | 217 | ##' trans_exp_new 218 | ##' 219 | ##' transform rownames of expression set from "ensembl" to"symbol",according to the new information from ensembl database. 220 | ##' 221 | ##' @param exp expression set with ensembl as rownames 222 | ##' @param mrna_only only keep mrna rows in result 223 | ##' @param lncrna_only only keep lncrna rows in result 224 | ##' @param species choose human or mouse, or rat, default: human 225 | ##' @return a transformed expression set with symbol 226 | ##' @author Xiaojie Sun 227 | ##' @importFrom stringr str_split 228 | ##' @export 229 | ##' @examples 230 | ##' exp = matrix(rnorm(1000),ncol = 10) 231 | ##' rownames(exp) = sample(mRNA_annov23$gene_id,100) 232 | ##' colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 233 | ##' if(requireNamespace("AnnoProbe")){ 234 | ##' k = trans_exp_new(exp) 235 | ##' }else{ 236 | ##' warning("Package \"AnnoProbe\" needed for this function to work. 237 | ##' Please install it by install.packages('AnnoProbe')") 238 | ##' } 239 | ##' @seealso 240 | ##' \code{\link{trans_exp}} 241 | trans_exp_new = function(exp,mrna_only = FALSE, 242 | lncrna_only = FALSE, 243 | species = "human"){ 244 | if(is.data.frame(exp)){exp = as.matrix(exp)} 245 | if(!requireNamespace("AnnoProbe"))stop("Package \"AnnoProbe\" needed for this function to work. 246 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 247 | rownames(exp) = str_split(rownames(exp),"\\.",simplify = T)[,1] 248 | re = AnnoProbe::annoGene(rownames(exp),ID_type = "ENSEMBL",species = species) 249 | if(mrna_only){ 250 | re = re[re$biotypes=="protein_coding",] 251 | }else if(lncrna_only){ 252 | re = re[re$biotypes=="lncRNA",] 253 | }else{ 254 | re = re 255 | } 256 | exp = trans_array(exp,ids = re,from = "ENSEMBL",to = "SYMBOL") 257 | return(exp) 258 | } 259 | 260 | ##' trans_entrezexp 261 | ##' 262 | ##' transform rownames of expression set from "entrez" to"symbol",according to the bitr function. 263 | ##' 264 | ##' @param entrezexp expression set with entrezid as rownames 265 | ##' @param species choose human or mouse, or rat, default: human 266 | ##' @importFrom clusterProfiler bitr 267 | ##' @return a transformed expression set with symbol 268 | ##' @author Xiaojie Sun 269 | ##' @export 270 | ##' @examples 271 | ##' exp = matrix(rnorm(200),ncol = 10) 272 | ##' rownames(exp) = c("79691", "56271", "8662", "10394", "55630", "159162", "23541", 273 | ##' "79723", "54413", "22927", "92342", "23787", "5550", "8924", 274 | ##' "55274", "866", "8844", "353299", "587", "1473") 275 | ##' colnames(exp) = paste0("s",1:10) 276 | ##' if(requireNamespace("org.Hs.eg.db",quietly = TRUE)){ 277 | ##' exp2 = trans_entrezexp(exp) 278 | ##' }else{ 279 | ##' warning("Package \"org.Hs.eg.db\" needed for this function to work. 280 | ##' Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 281 | ##' } 282 | ##' @seealso 283 | ##' \code{\link{trans_exp}} 284 | trans_entrezexp = function(entrezexp,species="human"){ 285 | if(species == "human"){ 286 | if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 287 | stop("Package \"org.Hs.eg.db\" needed for this function to work. 288 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 289 | } 290 | or = org.Hs.eg.db::org.Hs.eg.db 291 | } 292 | if(species == "mouse"){ 293 | if(!requireNamespace("org.Mm.eg.db",quietly = TRUE)) { 294 | stop("Package \"org.Mm.eg.db\" needed for this function to work. 295 | Please install it by BiocManager::install('org.Mm.eg.db')",call. = FALSE) 296 | } 297 | or = org.Mm.eg.db::org.Mm.eg.db 298 | } 299 | if(species == "rat"){ 300 | if(!requireNamespace("org.Rn.eg.db",quietly = TRUE)) { 301 | stop("Package \"org.Rn.eg.db\" needed for this function to work. 302 | Please install it by BiocManager::install('org.Rn.eg.db')",call. = FALSE) 303 | } 304 | or = org.Rn.eg.db::org.Rn.eg.db 305 | } 306 | if(is.data.frame(entrezexp)){exp = as.matrix(entrezexp)} 307 | re = bitr(rownames(entrezexp),fromType = "ENTREZID",toType = "SYMBOL",OrgDb = or) 308 | exp = trans_array(entrezexp,ids = re,from = "ENTREZID",to = "SYMBOL") 309 | return(exp) 310 | } 311 | -------------------------------------------------------------------------------- /R/9_cor_t_choose.R: -------------------------------------------------------------------------------- 1 | ##' t_choose 2 | ##' 3 | ##' choose differential expressed genes by simple t.test 4 | ##' 5 | ##' @inheritParams get_deg 6 | ##' @param genes a vector with some genes 7 | ##' @param up_only keep up genes in the result only 8 | ##' @param down_only keep down genes in the result only 9 | ##' @param pvalue_cutoff p value cut off ,0.05 by defult 10 | ##' @export 11 | ##' @return a vector with differential expressed genes 12 | ##' @author Xiaojie Sun 13 | ##' @examples 14 | ##' exp = matrix(rnorm(1000),ncol = 10) 15 | ##' rownames(exp) = sample(mRNA_annov23$gene_id,100) 16 | ##' colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 17 | ##' exp2 = trans_exp(exp) 18 | ##' exp2[,1:5] = exp2[,1:5]+10 19 | ##' group_list = rep(c("A","B"),each = 5) 20 | ##' genes = sample(rownames(exp2),3) 21 | ##' t_choose(genes,exp2,group_list) 22 | 23 | t_choose <- function(genes,exp,group_list,up_only = FALSE,down_only = FALSE,pvalue_cutoff = 0.05){ 24 | if(up_only&down_only)stop("please change neither up_only or down_only to FALSE") 25 | genes = genes[genes %in% rownames(exp)] 26 | exp_small = exp[genes,] 27 | dat = data.frame(t(exp_small),check.names = FALSE) 28 | dat$group_list = group_list 29 | p_v <- sapply(1:(ncol(dat)-1), function(i){ 30 | stats::t.test(dat[,i] ~group_list)$p.value 31 | }) 32 | names(p_v) = colnames(dat)[-ncol(dat)] 33 | 34 | exp_genes = names(p_v[p_v < pvalue_cutoff]) 35 | 36 | if(up_only){ 37 | es_up <- sapply(1:(ncol(dat)-1), function(i){ 38 | tmp = stats::t.test(dat[,i] ~group_list) 39 | k = tmp$estimate[2]-tmp$estimate[1] >0 40 | return(k) 41 | }) 42 | up_genes = names(p_v)[p_v < pvalue_cutoff & es_up] 43 | return(up_genes) 44 | }else if(down_only){ 45 | es_down <- sapply(1:(ncol(dat)-1), function(i){ 46 | tmp = stats::t.test(dat[,i] ~group_list) 47 | k = tmp$estimate[2]-tmp$estimate[1] <0 48 | return(k) 49 | }) 50 | down_genes = names(p_v)[p_v drop 84 | k2 = kt > drop 85 | if(sum(k1&k2) < min.obs){ 86 | p[[i]] = c(NA,NA) 87 | }else{ 88 | cot = stats::cor.test(bt[k1&k2],kt[k1&k2]) 89 | p[[i]] = c(cot$p.value,cot$estimate) 90 | } 91 | names(p[[i]]) = c("p.value","cor") 92 | } 93 | re = do.call(cbind,p) 94 | colnames(re) = apply(ss1, 2, paste,collapse =":") 95 | re = as.data.frame(t(re)) 96 | ks = sapply(rownames(re), function(gs){ 97 | g1 = str_split(gs,":",simplify = T)[,1] 98 | g2 = str_split(gs,":",simplify = T)[,2] 99 | sum(x[,g1]>drop & x[,g2]>drop) 100 | }) 101 | re$obsnumber = ks 102 | re = stats::na.omit(re) 103 | return(re) 104 | } 105 | 106 | 107 | 108 | ##' cor.test for one variable with all variables 109 | ##' 110 | ##' cor.test for all variables(each two columns) 111 | ##' 112 | ##' @param x A numeric matrix or data.frame 113 | ##' @param var your chosen variable,only one. 114 | ##' @param drop.var drop values in var 115 | ##' @param drop.other drop values in other columns 116 | ##' @param min.obs minimum number of observations after dropping 117 | ##' @return A data.frame with cor.test p.value and estimate 118 | ##' @author Xiaojie Sun 119 | ##' @export 120 | ##' @examples 121 | ##' x = iris[,-5] 122 | ##' cor.one(x,"Sepal.Width") 123 | ##' @seealso 124 | ##' \code{\link{cor.full}} 125 | 126 | cor.one <- function(x,var,drop.var = min(x[,var])-0.001, 127 | drop.other = min(x[,-which(colnames(x)==var)])-0.001, 128 | min.obs = 10){ 129 | if(!(var %in% colnames(x))) stop(paste0(var," is not a colname of ",x,",please check it.")) 130 | if(!all(!duplicated(colnames(x)))) stop("unique colnames is required") 131 | p = list() 132 | ss = setdiff(colnames(x),var) 133 | bt = x[,var] 134 | k1 = bt > drop.var 135 | for(i in (1:length(ss))){ 136 | kt = x[,ss[[i]]] 137 | k2 = kt > drop.other 138 | if(sum(k1&k2) < min.obs){ 139 | p[[i]] = c(NA,NA) 140 | }else{ 141 | cot = stats::cor.test(bt[k1&k2],kt[k1&k2]) 142 | p[[i]] = c(cot$p.value,cot$estimate) 143 | } 144 | names(p[[i]]) = c("p.value","cor") 145 | } 146 | re = do.call(cbind,p) 147 | colnames(re) = ss 148 | re = as.data.frame(t(re)) 149 | ks = sapply(rownames(re), function(g){ 150 | sum(x[,g]>drop.other) 151 | }) 152 | re$obsnumber = ks 153 | re = stats::na.omit(re) 154 | return(re) 155 | } 156 | 157 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' cod 2 | #' 3 | #' An expression matrix form TCGA 4 | #' 5 | #' @examples 6 | #' cod 7 | "cod" 8 | 9 | #' deg 10 | #' 11 | #' limma differential analysis result for GSE42872 12 | #' 13 | #' @examples 14 | #' head(deg) 15 | "deg" 16 | 17 | #' deseq_data 18 | #' 19 | #' DEseq2 differential analysis result 20 | #' 21 | #' @examples 22 | #' head(deseq_data) 23 | "deseq_data" 24 | 25 | #' exists_anno_list 26 | #' 27 | #' AnnoProbe supported GPLs 28 | #' 29 | #' @examples 30 | #' exists_anno_list 31 | "exists_anno_list" 32 | 33 | #' exp_hub1 34 | #' 35 | #' An expression matrix from TCGA and Gtex 36 | #' 37 | #' @examples 38 | #' exp_hub1[1:4,1:4] 39 | "exp_hub1" 40 | 41 | 42 | #' exprSet_hub1 43 | #' 44 | #' An cpm expression matrix from TCGA,tumor samples only 45 | #' 46 | #' @examples 47 | #' exprSet_hub1[1:4,1:4] 48 | "exprSet_hub1" 49 | 50 | 51 | #' genes 52 | #' 53 | #' some gene entriz ids 54 | #' 55 | #' @examples 56 | #' genes 57 | "genes" 58 | 59 | #' lnc_anno 60 | #' 61 | #' annotation for TCGA expression matrix(lncRNA),form genecode v22 gtf file. 62 | #' 63 | #' @examples 64 | #' head(lnc_anno) 65 | "lnc_anno" 66 | 67 | #' lnc_annov23 68 | #' 69 | #' annotation for TCGA and gtex expression matrix(lncRNA),form genecode v23 gtf file. 70 | #' 71 | #' @examples 72 | #' head(lnc_annov23) 73 | "lnc_annov23" 74 | 75 | #' mRNA_annov23 76 | #' 77 | #' annotation for TCGA and gtex expression matrix(mRNA),form genecode v23 gtf file. 78 | #' 79 | #' @examples 80 | #' head(mRNA_annov23) 81 | "mRNA_annov23" 82 | 83 | #' mRNA_anno 84 | #' 85 | #' annotation for TCGA and gtex expression matrix(mRNA),form genecode v22 gtf file. 86 | #' 87 | #' @examples 88 | #' head(mRNA_anno) 89 | "mRNA_anno" 90 | 91 | #' meta1 92 | #' 93 | #' clinical messages for some TCGA patients,correspond to exprSet_hub1 94 | #' 95 | #' @examples 96 | #' head(meta1) 97 | "meta1" 98 | 99 | #' pkg_all 100 | #' 101 | #' bioconductor annotation packages for GPLs 102 | #' 103 | #' @examples 104 | #' head(pkg_all) 105 | "pkg_all" 106 | -------------------------------------------------------------------------------- /R/start_massage.R: -------------------------------------------------------------------------------- 1 | ##' @importFrom utils packageDescription 2 | .onAttach <- function(libname, pkgname) { 3 | packageStartupMessage("tinyarray v 2.4.2 welcome to use tinyarray! 4 | If you use tinyarray in published research, please acknowledgements: 5 | We thank Dr.Jianming Zeng(University of Macau), and all the members of his bioinformatics team, biotrainee,especially Xiaojie Sun, for generously sharing their experience and codes. 6 | ") 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tinyarray 2 | 3 | ### Introduction 4 | 5 | Hi, I'm Xiao Jie. This is an R package I wrote based on my own data analysis needs. I'm glad you found it. I will update some useful functions here on the public account "bioinfoplanet" and also do some other sharing. 6 | 7 | ### Installation 8 | 9 | #### 1.online 10 | 11 | ``` 12 | if(!require(tinyarray))install.packages("tinyarray") 13 | if(!require(devtools))install.packages("devtools") 14 | if(!require(tinyarray))devtools::install_github("xjsun1221/tinyarray",upgrade = FALSE,dependencies = TRUE) 15 | ``` 16 | 17 | #### 2.local 18 | 19 | Click the green button "code" on this page, then click "Download ZIP" to download it to your working directory. Install it with `devtools::install_local("tinyarray-master.zip",upgrade = F,dependencies = T)`. 20 | 21 | ### functions 22 | 23 | #### 1.basic 24 | 25 | draw_heatmap(),draw_volcano(),draw_venn(),draw_boxplot(),draw_KM(),draw_venn(),risk_plot() 26 | 27 | ggheat() is a function from the ggplot2 package that can be used to create heatmaps. It is still relatively immature and mainly used for aligning plots and collecting legends. 28 | 29 | Something about ggheat(): 30 | https://mp.weixin.qq.com/s/WhsBf6QAhVXeXeScM59cSA 31 | 32 | #### 2.Downstream Analysis of Gene Expression Array Data from GEO Database 33 | 34 | geo_download(): Provide a GEO number and get back the expression matrix, clinical information table, and platform number used. 35 | 36 | find_anno(): Look up the annotation of the array platform. 37 | 38 | get_deg(): Provide the array expression matrix, grouping information, probe annotation and get back the differential analysis results. 39 | 40 | multi_deg(): Differential analysis for multiple groups (up to 5). 41 | 42 | If you want to do differential analysis and get the common figures in one step, you can use get_deg_all() and multi_deg_all(). This part mainly integrates and simplifies the differential analysis of GEOquery, Annoprobe, and limma. 43 | 44 | quick_enrich(): Simple and intuitive enrichment analysis. 45 | 46 | double_enrich(): Separate enrichment of up- and down-regulated genes, combined with plotting. 47 | 48 | https://mp.weixin.qq.com/s/YQQoDsE5JaKpgFGlbEfQNg 49 | 50 | https://mp.weixin.qq.com/s/j5IB_MQ0zeOCe1j_ahwtdQ 51 | 52 | #### 3.Exploring Expression Matrices 53 | 54 | make_tcga_group(): Quickly get the grouping according to the TCGA sample naming rules. 55 | 56 | sam_filter(): Remove duplicate tumor samples in TCGA. 57 | 58 | match_exp_cl(): Match TCGA expression matrix with clinical information. 59 | 60 | trans_array(): Replace the row names of the matrix, such as replacing the probe names of the expression matrix with gene names. 61 | 62 | trans_exp(): Convert TCGA or TCGA+GTeX data to gene IDs (old version, genecode v22 or v23) 63 | 64 | trans_exp_new(): Convert TCGA or TCGA+GTeX data to gene IDs(new versions) 65 | 66 | t_choose(): Do t-tests for individual genes in batches. 67 | 68 | cor.full() and cor.one(): Calculate correlations between genes in batches. 69 | 70 | #### 4.Survival Analysis and Visualization 71 | 72 | point_cut(): Calculate the best cutoff point for survival analysis in batches. 73 | 74 | surv_KM(): Do KM survival analysis in batches, supporting grouping with the best cutoff point. 75 | 76 | surv_cox(): Do single factor Cox in batches, supporting grouping with the best cutoff point. 77 | 78 | risk_plot(): Risk factor three-way linkage. 79 | 80 | https://mp.weixin.qq.com/s/WYBhGxfGg6QFUPHFBashaA 81 | 82 | exp_boxplot(): Draw T-N boxplot for the interested genes. 83 | 84 | exp_surv(): Draw KM-plot for the interested genes. 85 | 86 | box_surv(): Draw boxplot and KM-plot for the interested genes. 87 | 88 | #### 5.Something about network graph 89 | 90 | hypertest(): Do hypergeometric distribution test for mRNA and lncRNA in batches. 91 | 92 | plcortest(): Do correlation test for mRNA and lncRNA in batches. 93 | 94 | https://www.yuque.com/xiaojiewanglezenmofenshen/bsgk2d/dt0isp 95 | 96 | interaction_to_edges(): Generate the connection table for the network graph based on the relationship table. 97 | 98 | edges_to_nodes(): Generate the node table based on the connection table. 99 | 100 | #### 6.Tricks 101 | 102 | dumd(): Count how many values each column of the data frame has. 103 | 104 | intersect_all(): Take the intersection of any number of vectors. 105 | 106 | union_all(): Take the union of any number of vectors. 107 | 108 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 0 note 4 | 5 | * This is a new release.We have resolved the note for the previous data for non ASCII characters 6 | 7 | Please run `export _R_CHECK_DEPENDS_ONLY_ true` before checking 8 | -------------------------------------------------------------------------------- /data/cod.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/cod.rda -------------------------------------------------------------------------------- /data/deg.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/deg.rda -------------------------------------------------------------------------------- /data/deseq_data.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/deseq_data.rda -------------------------------------------------------------------------------- /data/exists_anno_list.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/exists_anno_list.rda -------------------------------------------------------------------------------- /data/exp_hub1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/exp_hub1.rda -------------------------------------------------------------------------------- /data/exprSet_hub1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/exprSet_hub1.rda -------------------------------------------------------------------------------- /data/genes.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/genes.rda -------------------------------------------------------------------------------- /data/lnc_anno.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/lnc_anno.rda -------------------------------------------------------------------------------- /data/lnc_annov23.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/lnc_annov23.rda -------------------------------------------------------------------------------- /data/mRNA_anno.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/mRNA_anno.rda -------------------------------------------------------------------------------- /data/mRNA_annov23.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/mRNA_annov23.rda -------------------------------------------------------------------------------- /data/meta1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/meta1.rda -------------------------------------------------------------------------------- /data/pkg_all.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xjsun1221/tinyarray/e1b5df306627ad7e11d93278ec64a67ae80cd299/data/pkg_all.rda -------------------------------------------------------------------------------- /man/box_surv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/11_surv_box_plot.R 3 | \name{box_surv} 4 | \alias{box_surv} 5 | \title{box_surv} 6 | \usage{ 7 | box_surv(exp_hub, exprSet_hub, meta) 8 | } 9 | \arguments{ 10 | \item{exp_hub}{an expression matrix for hubgenes} 11 | 12 | \item{exprSet_hub}{a tumor expression set for hubgenes} 13 | 14 | \item{meta}{meta data corresponds to expression set} 15 | } 16 | \value{ 17 | patchwork result for hub genes boxplot and survival plot 18 | } 19 | \description{ 20 | draw box plot for a hub gene expression matrix 21 | } 22 | \examples{ 23 | if(requireNamespace("ggpubr",quietly = TRUE)) { 24 | k = box_surv(log2(exp_hub1+1),exprSet_hub1,meta1);k[[1]] 25 | }else{ 26 | warning("Package 'ggpubr' needed for this function to work. 27 | Please install it by install.packages('ggpubr')") 28 | } 29 | } 30 | \seealso{ 31 | \code{\link{exp_boxplot}};\code{\link{exp_surv}} 32 | } 33 | \author{ 34 | Xiaojie Sun 35 | } 36 | -------------------------------------------------------------------------------- /man/cod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{cod} 5 | \alias{cod} 6 | \title{cod} 7 | \format{ 8 | An object of class \code{matrix} (inherits from \code{array}) with 100 rows and 512 columns. 9 | } 10 | \usage{ 11 | cod 12 | } 13 | \description{ 14 | An expression matrix form TCGA 15 | } 16 | \examples{ 17 | cod 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/cor.full.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/9_cor_t_choose.R 3 | \name{cor.full} 4 | \alias{cor.full} 5 | \title{cor.test for all variables} 6 | \usage{ 7 | cor.full(x, drop = min(x) - 0.001, min.obs = 10) 8 | } 9 | \arguments{ 10 | \item{x}{A numeric matrix or data.frame} 11 | 12 | \item{drop}{drop values} 13 | 14 | \item{min.obs}{minimum number of observations after dropping} 15 | } 16 | \value{ 17 | a data.frame with cor.test p.value and estimate 18 | } 19 | \description{ 20 | cor.test for all variables(each two columns) 21 | } 22 | \examples{ 23 | x = iris[,-5] 24 | cor.full(x) 25 | } 26 | \seealso{ 27 | \code{\link{cor.one}} 28 | } 29 | \author{ 30 | Xiaojie Sun 31 | } 32 | -------------------------------------------------------------------------------- /man/cor.one.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/9_cor_t_choose.R 3 | \name{cor.one} 4 | \alias{cor.one} 5 | \title{cor.test for one variable with all variables} 6 | \usage{ 7 | cor.one( 8 | x, 9 | var, 10 | drop.var = min(x[, var]) - 0.001, 11 | drop.other = min(x[, -which(colnames(x) == var)]) - 0.001, 12 | min.obs = 10 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{A numeric matrix or data.frame} 17 | 18 | \item{var}{your chosen variable,only one.} 19 | 20 | \item{drop.var}{drop values in var} 21 | 22 | \item{drop.other}{drop values in other columns} 23 | 24 | \item{min.obs}{minimum number of observations after dropping} 25 | } 26 | \value{ 27 | A data.frame with cor.test p.value and estimate 28 | } 29 | \description{ 30 | cor.test for all variables(each two columns) 31 | } 32 | \examples{ 33 | x = iris[,-5] 34 | cor.one(x,"Sepal.Width") 35 | } 36 | \seealso{ 37 | \code{\link{cor.full}} 38 | } 39 | \author{ 40 | Xiaojie Sun 41 | } 42 | -------------------------------------------------------------------------------- /man/corheatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{corheatmap} 4 | \alias{corheatmap} 5 | \title{corheatmap} 6 | \usage{ 7 | corheatmap(exp, x, y, color = c("#2fa1dd", "white", "#f87669")) 8 | } 9 | \arguments{ 10 | \item{exp}{A numeric matrix} 11 | 12 | \item{x}{genes or cells from exp} 13 | 14 | \item{y}{genes or cells from exp} 15 | 16 | \item{color}{color for heatmap} 17 | } 18 | \value{ 19 | a ggplot object 20 | } 21 | \description{ 22 | draw cor heatmap 23 | } 24 | \examples{ 25 | x = rownames(exprSet_hub1)[1:3] 26 | y = rownames(exprSet_hub1)[4:7] 27 | corheatmap(exprSet_hub1,x,y) 28 | } 29 | \author{ 30 | Xiaojie Sun 31 | } 32 | -------------------------------------------------------------------------------- /man/corscatterplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{corscatterplot} 4 | \alias{corscatterplot} 5 | \title{corscatterplot} 6 | \usage{ 7 | corscatterplot( 8 | dat, 9 | x, 10 | y, 11 | color_cor = "blue", 12 | fill_cor = "lightgray", 13 | fill_x = "#ff820e", 14 | fill_y = "#0000fe", 15 | type = "density", 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{dat}{plot data} 21 | 22 | \item{x}{x} 23 | 24 | \item{y}{y} 25 | 26 | \item{color_cor}{color for cor reg.line} 27 | 28 | \item{fill_cor}{fill for cor reg.line} 29 | 30 | \item{fill_x}{fill for top density plot} 31 | 32 | \item{fill_y}{fill for right density plot} 33 | 34 | \item{type}{whether to use a density plot or a histogram plot for the side panel.} 35 | 36 | \item{...}{other paramters for ggscatter} 37 | } 38 | \value{ 39 | a ggplot object 40 | } 41 | \description{ 42 | draw cor scatter plot with density plot by ggplot2 43 | } 44 | \examples{ 45 | if(requireNamespace("ggpubr",quietly = TRUE)){ 46 | corscatterplot(iris,"Sepal.Length","Sepal.Width") 47 | }else{ 48 | warning("Package 'ggpubr' needed for this function to work. 49 | Please install it by install.packages('ggpubr')") 50 | } 51 | } 52 | \author{ 53 | Xiaojie Sun 54 | } 55 | -------------------------------------------------------------------------------- /man/deg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{deg} 5 | \alias{deg} 6 | \title{deg} 7 | \format{ 8 | An object of class \code{data.frame} with 18591 rows and 10 columns. 9 | } 10 | \usage{ 11 | deg 12 | } 13 | \description{ 14 | limma differential analysis result for GSE42872 15 | } 16 | \examples{ 17 | head(deg) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/deseq_data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{deseq_data} 5 | \alias{deseq_data} 6 | \title{deseq_data} 7 | \format{ 8 | An object of class \code{data.frame} with 552 rows and 6 columns. 9 | } 10 | \usage{ 11 | deseq_data 12 | } 13 | \description{ 14 | DEseq2 differential analysis result 15 | } 16 | \examples{ 17 | head(deseq_data) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/double_enrich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/7_quick_double_enrich.R 3 | \name{double_enrich} 4 | \alias{double_enrich} 5 | \title{draw enrichment bar plots for both up and down genes} 6 | \usage{ 7 | double_enrich(deg, n = 10, color = c("#2874C5", "#f87669")) 8 | } 9 | \arguments{ 10 | \item{deg}{a data.frame contains at least two columns:"ENTREZID" and "change"} 11 | 12 | \item{n}{how many terms will you perform for up and down genes respectively} 13 | 14 | \item{color}{color for bar plot} 15 | } 16 | \value{ 17 | a list with kegg and go bar plot according to up and down genes enrichment result. 18 | } 19 | \description{ 20 | draw enrichment bar plots for both up and down genes,for human only. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | if(requireNamespace("org.Hs.eg.db",quietly = TRUE)& 25 | requireNamespace("labeling",quietly = TRUE)){ 26 | double_enrich(deg) 27 | }else{ 28 | if(!requireNamespace("org.Hs.eg.db",quietly = TRUE)) { 29 | warning("Package 'org.Hs.eg.db' needed for this function to work. 30 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 31 | } 32 | if(!requireNamespace("labeling",quietly = TRUE)) { 33 | warning("Package 'labeling' needed for this function to work. 34 | Please install it by install.packages('labeling')",call. = FALSE) 35 | } 36 | } 37 | } 38 | } 39 | \seealso{ 40 | \code{\link{quick_enrich}} 41 | } 42 | \author{ 43 | Xiaojie Sun 44 | } 45 | -------------------------------------------------------------------------------- /man/draw_KM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_KM} 4 | \alias{draw_KM} 5 | \title{draw_KM} 6 | \usage{ 7 | draw_KM( 8 | meta, 9 | group_list, 10 | time_col = "time", 11 | event_col = "event", 12 | legend.title = "Group", 13 | legend.labs = levels(group_list), 14 | color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#92C5DE", "#F4A582", "#66C2A5", 15 | "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{meta}{survival data with time and event column} 21 | 22 | \item{group_list}{A factor with duplicated character or factor} 23 | 24 | \item{time_col}{colname of time} 25 | 26 | \item{event_col}{colname of event} 27 | 28 | \item{legend.title}{legend title} 29 | 30 | \item{legend.labs}{character vector specifying legend labels} 31 | 32 | \item{color}{color vector} 33 | 34 | \item{...}{other parameters from ggsurvplot} 35 | } 36 | \value{ 37 | a KM-plot 38 | } 39 | \description{ 40 | draw KM-plot with two or more group 41 | } 42 | \examples{ 43 | require("survival") 44 | x = survival::lung 45 | draw_KM(meta = x, 46 | group_list = x$sex,event_col = "status") 47 | } 48 | \author{ 49 | Xiaojie Sun 50 | } 51 | -------------------------------------------------------------------------------- /man/draw_boxplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_boxplot} 4 | \alias{draw_boxplot} 5 | \title{draw boxplot for expression} 6 | \usage{ 7 | draw_boxplot( 8 | exp, 9 | group_list, 10 | method = "kruskal.test", 11 | sort = TRUE, 12 | drop = FALSE, 13 | width = 0.5, 14 | pvalue_cutoff = 0.05, 15 | xlab = "Gene", 16 | ylab = "Expression", 17 | grouplab = "Group", 18 | p.label = FALSE, 19 | add_error_bar = FALSE, 20 | color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#66C2A5", "#FC8D62", "#8DA0CB", 21 | "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 22 | ... 23 | ) 24 | } 25 | \arguments{ 26 | \item{exp}{A numeric matrix} 27 | 28 | \item{group_list}{A factor with duplicated character or factor} 29 | 30 | \item{method}{one of kruskal.test,aov,t.test and wilcox.test} 31 | 32 | \item{sort}{whether the boxplot will be sorted} 33 | 34 | \item{drop}{whether to discard insignificant values} 35 | 36 | \item{width}{width of boxplot and error bar} 37 | 38 | \item{pvalue_cutoff}{if drop = TRUE,genes with p-values below the threshold will be drawn} 39 | 40 | \item{xlab}{title of the x axis} 41 | 42 | \item{ylab}{title of the y axis} 43 | 44 | \item{grouplab}{title of group legend} 45 | 46 | \item{p.label}{whether to show p value in the plot} 47 | 48 | \item{add_error_bar}{whether to add error bar} 49 | 50 | \item{color}{color vector} 51 | 52 | \item{...}{other parameters from stat_compare_means} 53 | } 54 | \value{ 55 | a boxplot according to \code{exp} and grouped by \code{group}. 56 | } 57 | \description{ 58 | draw boxplot for expression 59 | } 60 | \examples{ 61 | if(requireNamespace("tidyr",quietly = TRUE)& 62 | requireNamespace("ggpubr",quietly = TRUE)){ 63 | draw_boxplot(t(iris[,1:4]),iris$Species) 64 | exp <- matrix(rnorm(60),nrow = 10) 65 | colnames(exp) <- paste0("sample",1:6) 66 | rownames(exp) <- paste0("gene",1:10) 67 | exp[,4:6] = exp[,4:6] +10 68 | exp[1:4,1:4] 69 | group_list <- factor(rep(c("A","B"),each = 3)) 70 | draw_boxplot(exp,group_list) 71 | draw_boxplot(exp,group_list,color = c("grey","red")) 72 | }else{ 73 | if(!requireNamespace("ggpubr",quietly = TRUE)) { 74 | warning("Package 'ggpubr' needed for this function to work. 75 | Please install it by install.packages('ggpubr')") 76 | } 77 | if(!requireNamespace("tidyr",quietly = TRUE)) { 78 | warning("Package 'tidyr' needed for this function to work. 79 | Please install it by install.packages('tidyr')") 80 | } 81 | } 82 | } 83 | \seealso{ 84 | \code{\link{draw_heatmap}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 85 | } 86 | \author{ 87 | Xiaojie Sun 88 | } 89 | -------------------------------------------------------------------------------- /man/draw_heatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_heatmap} 4 | \alias{draw_heatmap} 5 | \title{draw a heatmap plot} 6 | \usage{ 7 | draw_heatmap( 8 | n, 9 | group_list, 10 | scale_before = FALSE, 11 | n_cutoff = 3, 12 | legend = FALSE, 13 | show_rownames = FALSE, 14 | annotation_legend = FALSE, 15 | split_column = FALSE, 16 | show_column_title = FALSE, 17 | color = (grDevices::colorRampPalette(c("#2fa1dd", "white", "#f87669")))(100), 18 | color_an = c("#2fa1dd", "#f87669", "#e6b707", "#868686", "#92C5DE", "#F4A582", 19 | "#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", 20 | "#B3B3B3"), 21 | scale = TRUE, 22 | main = NA, 23 | ... 24 | ) 25 | } 26 | \arguments{ 27 | \item{n}{A numeric matrix} 28 | 29 | \item{group_list}{A factor with duplicated character or factor} 30 | 31 | \item{scale_before}{deprecated parameter} 32 | 33 | \item{n_cutoff}{3 by defalut , scale before plot and set a cutoff,usually 2 or 1.6} 34 | 35 | \item{legend}{logical,show legend or not} 36 | 37 | \item{show_rownames}{logical,show rownames or not} 38 | 39 | \item{annotation_legend}{logical,show annotation legend or not} 40 | 41 | \item{split_column}{split column by group_list} 42 | 43 | \item{show_column_title}{show column title or not} 44 | 45 | \item{color}{color for heatmap} 46 | 47 | \item{color_an}{color for column annotation} 48 | 49 | \item{scale}{logical,scale the matrix or not} 50 | 51 | \item{main}{the title of the plot} 52 | 53 | \item{...}{other parameters from pheatmap} 54 | } 55 | \value{ 56 | a heatmap plot according to \code{exp} and grouped by \code{group}. 57 | } 58 | \description{ 59 | warning a heatmap plot for expression matrix and group by group_list praramter, exp will be scaled. 60 | } 61 | \examples{ 62 | #example data 63 | exp = matrix(abs(rnorm(60,sd = 16)),nrow = 10) 64 | exp[,4:6] <- exp[,4:6]+20 65 | colnames(exp) <- paste0("sample",1:6) 66 | rownames(exp) <- paste0("gene",1:10) 67 | exp[1:4,1:4] 68 | group_list = factor(rep(c("A","B"),each = 3)) 69 | if(requireNamespace("ggplotify",quietly = TRUE)){ 70 | draw_heatmap(exp,group_list) 71 | #use iris 72 | n = t(iris[,1:4]);colnames(n) = 1:150 73 | group_list = iris$Species 74 | draw_heatmap(n,group_list) 75 | draw_heatmap(n,group_list,color = colorRampPalette(c("green","black","red"))(100), 76 | color_an = c("red","blue","pink") ) 77 | }else{ 78 | warning("Package 'ggplotify' needed for this function to work. 79 | Please install it by install.packages('ggplotify')") 80 | } 81 | } 82 | \seealso{ 83 | \code{\link{draw_pca}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 84 | } 85 | \author{ 86 | Xiaojie Sun 87 | } 88 | -------------------------------------------------------------------------------- /man/draw_heatmap2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/6_multi_deg_all.R 3 | \name{draw_heatmap2} 4 | \alias{draw_heatmap2} 5 | \title{draw heatmap plots} 6 | \usage{ 7 | draw_heatmap2(exp, group_list, deg, my_genes = NULL, heat_union = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{exp}{A numeric matrix} 11 | 12 | \item{group_list}{A factor with duplicated character or factor} 13 | 14 | \item{deg}{a data.frame created by Differential analysis} 15 | 16 | \item{my_genes}{genes for pheatmap} 17 | 18 | \item{heat_union}{logical ,use union or intersect DEGs for heatmap} 19 | 20 | \item{...}{other parameters from draw_heatmap} 21 | } 22 | \value{ 23 | a heatmap plot according to \code{exp} and grouped by \code{group}. 24 | } 25 | \description{ 26 | print heatmap plots for expression matrix and group by group_list paramter 27 | } 28 | \examples{ 29 | \dontrun{ 30 | if(requireNamespace("Biobase",quietly = TRUE)& 31 | requireNamespace("AnnoProbe",quietly = TRUE)){ 32 | gse = "GSE474" 33 | geo = geo_download(gse,destdir=tempdir()) 34 | geo$exp[1:4,1:4] 35 | geo$exp=log2(geo$exp+1) 36 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 37 | ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 38 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 39 | find_anno(geo$gpl) 40 | ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 41 | deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 42 | draw_heatmap2(geo$exp,group_list,deg) 43 | }else{ 44 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 45 | warning("Package 'AnnoProbe' needed for this function to work. 46 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 47 | } 48 | if(!requireNamespace("Biobase",quietly = TRUE)) { 49 | warning("Package 'Biobase' needed for this function to work. 50 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 51 | } 52 | } 53 | } 54 | } 55 | \seealso{ 56 | \code{\link{draw_pca}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 57 | } 58 | \author{ 59 | Xiaojie Sun 60 | } 61 | -------------------------------------------------------------------------------- /man/draw_pca.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_pca} 4 | \alias{draw_pca} 5 | \title{draw PCA plots} 6 | \usage{ 7 | draw_pca( 8 | exp, 9 | group_list, 10 | color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#92C5DE", "#F4A582", "#66C2A5", 11 | "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 12 | addEllipses = TRUE, 13 | style = "default", 14 | color.label = "Group", 15 | title = "", 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{exp}{A numeric matrix} 21 | 22 | \item{group_list}{A factor with duplicated character or factor} 23 | 24 | \item{color}{color vector} 25 | 26 | \item{addEllipses}{logical,add ellipses or not} 27 | 28 | \item{style}{plot style,"default","ggplot2"and "3D"} 29 | 30 | \item{color.label}{color legend label} 31 | 32 | \item{title}{plot title} 33 | 34 | \item{...}{other paramters from fviz_pca_ind} 35 | } 36 | \value{ 37 | a pca plot according to \code{exp} and grouped by \code{group}. 38 | } 39 | \description{ 40 | do PCA analysis and warning a PCA plot 41 | } 42 | \examples{ 43 | if(requireNamespace("FactoMineR",quietly = TRUE)& 44 | requireNamespace("factoextra",quietly = TRUE)){ 45 | draw_pca(t(iris[,1:4]),iris$Species) 46 | draw_pca(t(iris[,1:4]),iris$Species,style = "ggplot2") 47 | #change color 48 | draw_pca(t(iris[,1:4]),iris$Species,color = c("#E78AC3", "#A6D854", "#FFD92F")) 49 | }else{ 50 | if(!requireNamespace("FactoMineR",quietly = TRUE)){ 51 | warning("Package 'FactoMineR' needed for this function to work. 52 | Please install it by install.packages('FactoMineR')") 53 | } 54 | if(!requireNamespace("factoextra",quietly = TRUE)){ 55 | warning("Package 'factoextra' needed for this function to work. 56 | Please install it by install.packages('factoextra')") 57 | } 58 | } 59 | 60 | if(requireNamespace("scatterplot3d",quietly = TRUE)& 61 | requireNamespace("FactoMineR",quietly = TRUE)){ 62 | draw_pca(t(iris[,1:4]),iris$Species,style = "3D") 63 | }else{ 64 | if(!requireNamespace("scatterplot3d",quietly = TRUE)){ 65 | warning("Package 'scatterplot3d' needed for this function to work. 66 | Please install it by install.packages('scatterplot3d')") 67 | } 68 | if(!requireNamespace("FactoMineR",quietly = TRUE)){ 69 | warning("Package 'FactoMineR' needed for this function to work. 70 | Please install it by install.packages('FactoMineR')") 71 | } 72 | } 73 | } 74 | \seealso{ 75 | \code{\link{draw_heatmap}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 76 | } 77 | \author{ 78 | Xiaojie Sun 79 | } 80 | -------------------------------------------------------------------------------- /man/draw_tsne.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_tsne} 4 | \alias{draw_tsne} 5 | \title{draw_tsne} 6 | \usage{ 7 | draw_tsne( 8 | exp, 9 | group_list, 10 | perplexity = 30, 11 | color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#92C5DE", "#F4A582", "#66C2A5", 12 | "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 13 | color.label = "group", 14 | addEllipses = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{exp}{A numeric matrix} 19 | 20 | \item{group_list}{A factor with duplicated character or factor} 21 | 22 | \item{perplexity}{numeric; perplexity parameter for Rtsne} 23 | 24 | \item{color}{color vector} 25 | 26 | \item{color.label}{color legend label} 27 | 28 | \item{addEllipses}{logical,add ellipses or not} 29 | } 30 | \value{ 31 | a ggplot object 32 | } 33 | \description{ 34 | draw tsne plot with annotation by ggplot2 35 | } 36 | \examples{ 37 | exp <- matrix(rnorm(10000),nrow = 50) 38 | colnames(exp) <- paste0("sample",1:200) 39 | rownames(exp) <- paste0("gene",1:50) 40 | exp[1:4,1:4] 41 | exp[,1:100] = exp[,1:100]+10 42 | group_list <- factor(rep(c("A","B"),each = 100)) 43 | if(requireNamespace("Rtsne",quietly = TRUE)){ 44 | draw_tsne(exp,group_list) 45 | }else{ 46 | warning("Package 'Rtsne' needed for this function to work. 47 | Please install it by install.packages('Rtsne')") 48 | } 49 | } 50 | \author{ 51 | Xiaojie Sun 52 | } 53 | -------------------------------------------------------------------------------- /man/draw_venn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_venn} 4 | \alias{draw_venn} 5 | \title{draw a venn plot} 6 | \usage{ 7 | draw_venn( 8 | x, 9 | main, 10 | color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#66C2A5", "#FC8D62", "#8DA0CB", 11 | "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 12 | imagetype = "png", 13 | filename = NULL, 14 | lwd = 1, 15 | lty = 1, 16 | col = color[1:length(x)], 17 | fill = color[1:length(x)], 18 | cat.col = color[1:length(x)], 19 | cat.cex = 1, 20 | cat.dist = -0.15, 21 | rotation.degree = 0, 22 | main.cex = 1, 23 | cex = 1, 24 | alpha = 0.1, 25 | reverse = TRUE, 26 | ... 27 | ) 28 | } 29 | \arguments{ 30 | \item{x}{a list for plot} 31 | 32 | \item{main}{Character giving the main title of the diagram} 33 | 34 | \item{color}{color vector} 35 | 36 | \item{imagetype}{Specification of the image format (e.g. tiff, png or svg)} 37 | 38 | \item{filename}{Filename for image output, or if NULL returns the grid object itself} 39 | 40 | \item{lwd}{width of the circle's circumference} 41 | 42 | \item{lty}{dash pattern of the circle's circumference} 43 | 44 | \item{col}{Colour of the circle's circumference} 45 | 46 | \item{fill}{Colour of the circle's area} 47 | 48 | \item{cat.col}{Colour of the category name} 49 | 50 | \item{cat.cex}{size of the category name} 51 | 52 | \item{cat.dist}{The distance (in npc units) of the category name from the edge of the circle (can be negative)} 53 | 54 | \item{rotation.degree}{Number of degrees to rotate the entire diagram} 55 | 56 | \item{main.cex}{Number giving the cex (font size) of the main title} 57 | 58 | \item{cex}{size of the area label} 59 | 60 | \item{alpha}{Alpha transparency of the circle's area} 61 | 62 | \item{reverse}{logical,reflect the three-set Venn diagram along its central 63 | vertical axis of symmetry. Use in combination with rotation 64 | to generate all possible set orders} 65 | 66 | \item{...}{other parameters from venn.diagram} 67 | } 68 | \value{ 69 | a venn plot according to \code{x}, \code{y} and.\code{z} named "name" paramter 70 | } 71 | \description{ 72 | warning a venn plot for deg result created by three packages 73 | } 74 | \examples{ 75 | if(requireNamespace("VennDiagram",quietly = TRUE)& 76 | requireNamespace("ggplotify",quietly = TRUE)& 77 | requireNamespace("cowplot",quietly = TRUE)){ 78 | x = list(Deseq2=sample(1:100,30),edgeR = sample(1:100,30),limma = sample(1:100,30)) 79 | draw_venn(x,"test") 80 | draw_venn(x,"test",color = c("darkgreen", "darkblue", "#B2182B")) 81 | }else{ 82 | if(!requireNamespace("VennDiagram",quietly = TRUE)) { 83 | warning("Package 'VennDiagram' needed for this function to work. 84 | Please install it by install.packages('VennDiagram')") 85 | } 86 | if(!requireNamespace("ggplotify",quietly = TRUE)) { 87 | warning("Package 'ggplotify' needed for this function to work. 88 | Please install it by install.packages('ggplotify')") 89 | } 90 | if(!requireNamespace("cowplot",quietly = TRUE)) { 91 | warning("Package 'cowplot' needed for this function to work. 92 | Please install it by install.packages('cowplot')") 93 | } 94 | } 95 | } 96 | \seealso{ 97 | \code{\link{draw_pca}};\code{\link{draw_volcano}};\code{\link{draw_heatmap}} 98 | } 99 | \author{ 100 | Xiaojie Sun 101 | } 102 | -------------------------------------------------------------------------------- /man/draw_volcano.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{draw_volcano} 4 | \alias{draw_volcano} 5 | \title{draw a volcano plot} 6 | \usage{ 7 | draw_volcano( 8 | deg, 9 | lab = NA, 10 | xlab.package = TRUE, 11 | pvalue_cutoff = 0.05, 12 | logFC_cutoff = 1, 13 | pkg = 1, 14 | adjust = FALSE, 15 | symmetry = FALSE, 16 | color = c("#2874C5", "grey", "#f87669") 17 | ) 18 | } 19 | \arguments{ 20 | \item{deg}{a data.frame created by Differential analysis} 21 | 22 | \item{lab}{label for x axis in volcano plot, if NA , x axis names by package} 23 | 24 | \item{xlab.package}{whether to use the package name as the x axis name} 25 | 26 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 27 | 28 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 29 | 30 | \item{pkg}{a integer ,means which Differential analysis packages you used,we support three packages by now, 1,2,3,4 respectively means "DESeq2","edgeR","limma(voom)","limma"} 31 | 32 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 33 | 34 | \item{symmetry}{a logical value ,would you like to get your plot symmetrical} 35 | 36 | \item{color}{color vector} 37 | } 38 | \value{ 39 | a volcano plot according to logFC and P.value(or adjust P.value) 40 | } 41 | \description{ 42 | warning a volcano plot for Differential analysis result in data.frame format. 43 | } 44 | \examples{ 45 | head(deseq_data) 46 | draw_volcano(deseq_data) 47 | draw_volcano(deseq_data,pvalue_cutoff = 0.01,logFC_cutoff = 2) 48 | draw_volcano(deseq_data,color = c("darkgreen", "darkgrey", "#B2182B")) 49 | } 50 | \seealso{ 51 | \code{\link{draw_heatmap}};\code{\link{draw_pca}};\code{\link{draw_venn}} 52 | } 53 | \author{ 54 | Xiaojie Sun 55 | } 56 | -------------------------------------------------------------------------------- /man/draw_volcano2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/6_multi_deg_all.R 3 | \name{draw_volcano2} 4 | \alias{draw_volcano2} 5 | \title{draw_volcano2} 6 | \usage{ 7 | draw_volcano2(deg, pkg = 4, lab, ...) 8 | } 9 | \arguments{ 10 | \item{deg}{a data.frame created by Differential analysis} 11 | 12 | \item{pkg}{a integer ,means which Differential analysis packages you used,we support three packages by now, 1,2,3,4 respectively means "DESeq2","edgeR","limma(voom)","limma"} 13 | 14 | \item{lab}{label for x axis in volcano plot, if NA , x axis names by package} 15 | 16 | \item{...}{other parameters from draw_volcano} 17 | } 18 | \value{ 19 | one or more volcano plot 20 | } 21 | \description{ 22 | print one or more volcano plot for Differential analysis result in data.frame fomat. 23 | } 24 | \examples{ 25 | \dontrun{ 26 | if(requireNamespace("Biobase",quietly = TRUE)& 27 | requireNamespace("AnnoProbe",quietly = TRUE)){ 28 | #two group 29 | gse = "GSE42872" 30 | geo = geo_download(gse,destdir=tempdir()) 31 | group_list = rep(c("A","B"),each = 3) 32 | ids = AnnoProbe::idmap('GPL6244',destdir = tempdir()) 33 | deg = get_deg(geo$exp,group_list,ids) 34 | draw_volcano2(deg) 35 | #multigroup 36 | gse = "GSE474" 37 | geo = geo_download(gse,destdir=tempdir()) 38 | geo$exp[1:4,1:4] 39 | geo$exp=log2(geo$exp+1) 40 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 41 | ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 42 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 43 | find_anno(geo$gpl) 44 | ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 45 | deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 46 | draw_volcano2(deg) 47 | draw_volcano2(deg,color = c("darkgreen","grey","darkred")) 48 | }else{ 49 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 50 | warning("Package 'AnnoProbe' needed for this function to work. 51 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 52 | } 53 | if(!requireNamespace("Biobase",quietly = TRUE)) { 54 | warning("Package 'Biobase' needed for this function to work. 55 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 56 | } 57 | } 58 | } 59 | } 60 | \seealso{ 61 | \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 62 | } 63 | \author{ 64 | Xiaojie Sun 65 | } 66 | -------------------------------------------------------------------------------- /man/dumd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/14_dumd_all.R 3 | \name{dumd} 4 | \alias{dumd} 5 | \title{count unique values in every columns for data.frame} 6 | \usage{ 7 | dumd(x) 8 | } 9 | \arguments{ 10 | \item{x}{A data.frame.} 11 | } 12 | \value{ 13 | The simple data.frame of columns unique values count in \code{x} 14 | } 15 | \description{ 16 | in geo analysis,this function can help you simplify pdata, delete columns with unique values,which can't be used as group vector 17 | } 18 | \examples{ 19 | dumd(iris) 20 | data(ToothGrowth) 21 | x = ToothGrowth 22 | dumd(ToothGrowth) 23 | } 24 | -------------------------------------------------------------------------------- /man/edges_to_nodes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/13_network_edge_node.R 3 | \name{edges_to_nodes} 4 | \alias{edges_to_nodes} 5 | \title{edges_to_nodes} 6 | \usage{ 7 | edges_to_nodes(edges) 8 | } 9 | \arguments{ 10 | \item{edges}{data.frame} 11 | } 12 | \value{ 13 | nodes data.frame 14 | } 15 | \description{ 16 | get nodes from edges 17 | } 18 | \examples{ 19 | df = data.frame(a = c("gene1","gene2","gene3"), 20 | b = c("d,f,a,b", 21 | "c,e,g", 22 | "a,b,d")) 23 | edges = interaction_to_edges(df) 24 | nodes = edges_to_nodes(edges) 25 | } 26 | \seealso{ 27 | \code{\link{interaction_to_edges}} 28 | } 29 | \author{ 30 | Xiaojie Sun 31 | } 32 | -------------------------------------------------------------------------------- /man/exists_anno_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{exists_anno_list} 5 | \alias{exists_anno_list} 6 | \title{exists_anno_list} 7 | \format{ 8 | An object of class \code{character} of length 175. 9 | } 10 | \usage{ 11 | exists_anno_list 12 | } 13 | \description{ 14 | AnnoProbe supported GPLs 15 | } 16 | \examples{ 17 | exists_anno_list 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/exp_boxplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/11_surv_box_plot.R 3 | \name{exp_boxplot} 4 | \alias{exp_boxplot} 5 | \title{exp_boxplot} 6 | \usage{ 7 | exp_boxplot(exp_hub, color = c("#2fa1dd", "#f87669")) 8 | } 9 | \arguments{ 10 | \item{exp_hub}{an expression matrix for hubgenes} 11 | 12 | \item{color}{color for boxplot} 13 | } 14 | \value{ 15 | box plots list for all genes in the matrix 16 | } 17 | \description{ 18 | draw box plot for a hub gene expression matrix 19 | } 20 | \examples{ 21 | if(requireNamespace("ggpubr",quietly = TRUE)) { 22 | k = exp_boxplot(log2(exp_hub1+1));k[[1]] 23 | }else{ 24 | warning("Package 'ggpubr' needed for this function to work. 25 | Please install it by install.packages('ggpubr')") 26 | } 27 | } 28 | \seealso{ 29 | \code{\link{exp_surv}};\code{\link{box_surv}} 30 | } 31 | \author{ 32 | Xiaojie Sun 33 | } 34 | -------------------------------------------------------------------------------- /man/exp_hub1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{exp_hub1} 5 | \alias{exp_hub1} 6 | \title{exp_hub1} 7 | \format{ 8 | An object of class \code{matrix} (inherits from \code{array}) with 8 rows and 350 columns. 9 | } 10 | \usage{ 11 | exp_hub1 12 | } 13 | \description{ 14 | An expression matrix from TCGA and Gtex 15 | } 16 | \examples{ 17 | exp_hub1[1:4,1:4] 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/exp_surv.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/11_surv_box_plot.R 3 | \name{exp_surv} 4 | \alias{exp_surv} 5 | \title{exp_surv} 6 | \usage{ 7 | exp_surv(exprSet_hub, meta, cut.point = FALSE, color = c("#2874C5", "#f87669")) 8 | } 9 | \arguments{ 10 | \item{exprSet_hub}{a tumor expression set for hubgenes} 11 | 12 | \item{meta}{meta data corresponds to expression set} 13 | 14 | \item{cut.point}{logical , use cut_point or not, if FALSE,use median by defult} 15 | 16 | \item{color}{color for boxplot} 17 | } 18 | \value{ 19 | survival plots list for all genes 20 | } 21 | \description{ 22 | draw surv plot for a hub gene expression matrix for tumor samples 23 | } 24 | \examples{ 25 | tmp = exp_surv(exprSet_hub1,meta1) 26 | patchwork::wrap_plots(tmp)+patchwork::plot_layout(guides = "collect") 27 | tmp2 = exp_surv(exprSet_hub1,meta1,cut.point = TRUE) 28 | patchwork::wrap_plots(tmp2)+patchwork::plot_layout(guides = "collect") 29 | } 30 | \seealso{ 31 | \code{\link{exp_boxplot}};\code{\link{box_surv}};\code{\link{draw_venn}} 32 | } 33 | \author{ 34 | Xiaojie Sun 35 | } 36 | -------------------------------------------------------------------------------- /man/exprSet_hub1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{exprSet_hub1} 5 | \alias{exprSet_hub1} 6 | \title{exprSet_hub1} 7 | \format{ 8 | An object of class \code{matrix} (inherits from \code{array}) with 8 rows and 177 columns. 9 | } 10 | \usage{ 11 | exprSet_hub1 12 | } 13 | \description{ 14 | An cpm expression matrix from TCGA,tumor samples only 15 | } 16 | \examples{ 17 | exprSet_hub1[1:4,1:4] 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/find_anno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2_geo_id.R 3 | \name{find_anno} 4 | \alias{find_anno} 5 | \title{find annotation package or files} 6 | \usage{ 7 | find_anno(gpl, install = FALSE, update = FALSE) 8 | } 9 | \arguments{ 10 | \item{gpl}{a gpl accession} 11 | 12 | \item{install}{whether to install and library the package} 13 | 14 | \item{update}{whether to update the package} 15 | } 16 | \value{ 17 | a list with deg data.frame, volcano plot and a list with DEGs. 18 | } 19 | \description{ 20 | find gpl annotation package or files 21 | } 22 | \examples{ 23 | find_anno("GPL570") 24 | } 25 | \seealso{ 26 | \code{\link{geo_download}} 27 | } 28 | \author{ 29 | Xiaojie Sun 30 | } 31 | -------------------------------------------------------------------------------- /man/genes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{genes} 5 | \alias{genes} 6 | \title{genes} 7 | \format{ 8 | An object of class \code{character} of length 511. 9 | } 10 | \usage{ 11 | genes 12 | } 13 | \description{ 14 | some gene entriz ids 15 | } 16 | \examples{ 17 | genes 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/geo_download.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2_geo_id.R 3 | \name{geo_download} 4 | \alias{geo_download} 5 | \title{geo_download} 6 | \usage{ 7 | geo_download( 8 | gse, 9 | by_annopbrobe = TRUE, 10 | simpd = TRUE, 11 | colon_remove = FALSE, 12 | destdir = getwd(), 13 | n = 1 14 | ) 15 | } 16 | \arguments{ 17 | \item{gse}{gse assession number} 18 | 19 | \item{by_annopbrobe}{download data by geoquery or annoprobe} 20 | 21 | \item{simpd}{get simplified pdata,drop out columns with all same values} 22 | 23 | \item{colon_remove}{whether to remove duplicated columns with colons} 24 | 25 | \item{destdir}{The destination directory for data downloads.} 26 | 27 | \item{n}{For data with more than one ExpressionSet, specify which one to analyze} 28 | } 29 | \value{ 30 | a list with exp,pd and gpl 31 | } 32 | \description{ 33 | download gse data and get informations 34 | } 35 | \examples{ 36 | \dontrun{ 37 | if(requireNamespace("Biobase",quietly = TRUE)& 38 | requireNamespace("AnnoProbe",quietly = TRUE)){ 39 | gse = "GSE42872" 40 | a = geo_download(gse,destdir=tempdir()) 41 | }else{ 42 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 43 | print("Package 'AnnoProbe' needed for this function to work. 44 | Please install it by install.packages('AnnoProbe')"print) 45 | } 46 | if(!requireNamespace("Biobase",quietly = TRUE)) { 47 | print("Package 'Biobase' needed for this function to work. 48 | Please install it by BiocManager::install('Biobase')"print) 49 | } 50 | } 51 | } 52 | } 53 | \seealso{ 54 | \code{\link{find_anno}} 55 | } 56 | \author{ 57 | Xiaojie Sun 58 | } 59 | -------------------------------------------------------------------------------- /man/get_cgs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/6_multi_deg_all.R 3 | \name{get_cgs} 4 | \alias{get_cgs} 5 | \title{get_cgs} 6 | \usage{ 7 | get_cgs(deg) 8 | } 9 | \arguments{ 10 | \item{deg}{a data.frame created by Differential analysis} 11 | } 12 | \value{ 13 | a list with upgenes,downgenes,diffgenes. 14 | } 15 | \description{ 16 | extract DEGs from deg data.frame 17 | } 18 | \examples{ 19 | \dontrun{ 20 | #two group 21 | gse = "GSE42872" 22 | geo = geo_download(gse,destdir=tempdir()) 23 | group_list = rep(c("A","B"),each = 3) 24 | ids = AnnoProbe::idmap('GPL6244',destdir=tempdir()) 25 | deg = get_deg(geo$exp,group_list,ids) 26 | cgs = get_cgs(deg) 27 | #mutigroup 28 | gse = "GSE474" 29 | geo = geo_download(gse,destdir=tempdir()) 30 | geo$exp[1:4,1:4] 31 | geo$exp=log2(geo$exp+1) 32 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 33 | ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 34 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 35 | find_anno(geo$gpl) 36 | ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 37 | deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE) 38 | cgs = get_cgs(deg) 39 | } 40 | } 41 | \seealso{ 42 | \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 43 | } 44 | \author{ 45 | Xiaojie Sun 46 | } 47 | -------------------------------------------------------------------------------- /man/get_count_txt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2_geo_id.R 3 | \name{get_count_txt} 4 | \alias{get_count_txt} 5 | \title{get count from GEO} 6 | \usage{ 7 | get_count_txt(gse, destdir = getwd(), download = FALSE) 8 | } 9 | \arguments{ 10 | \item{gse}{gse assession number} 11 | 12 | \item{destdir}{The destination directory for data downloads.} 13 | 14 | \item{download}{download the txt file or not} 15 | } 16 | \value{ 17 | a list with deg data.frame, volcano plot and a list with DEGs. 18 | } 19 | \description{ 20 | get RNA-seq count file from GEO database 21 | } 22 | \examples{ 23 | get_count_txt("GSE162550",destdir = tempdir()) 24 | } 25 | \seealso{ 26 | \code{\link{geo_download}} 27 | } 28 | \author{ 29 | Xiaojie Sun 30 | } 31 | -------------------------------------------------------------------------------- /man/get_deg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/3_get_deg.R 3 | \name{get_deg} 4 | \alias{get_deg} 5 | \title{get_deg} 6 | \usage{ 7 | get_deg( 8 | exp, 9 | group_list, 10 | ids, 11 | logFC_cutoff = 1, 12 | pvalue_cutoff = 0.05, 13 | adjust = FALSE, 14 | entriz = TRUE, 15 | species = "human" 16 | ) 17 | } 18 | \arguments{ 19 | \item{exp}{A numeric matrix} 20 | 21 | \item{group_list}{A factor with duplicated character or factor} 22 | 23 | \item{ids}{a data.frame with 2 columns,including probe_id and symbol} 24 | 25 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 26 | 27 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 28 | 29 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 30 | 31 | \item{entriz}{whether convert symbols to entriz ids} 32 | 33 | \item{species}{choose human or mouse, or rat, default: human} 34 | } 35 | \value{ 36 | a deg data.frame with 10 columns 37 | } 38 | \description{ 39 | do differential analysis according to expression set and group information 40 | } 41 | \examples{ 42 | \dontrun{ 43 | if(requireNamespace("Biobase",quietly = TRUE)& 44 | requireNamespace("AnnoProbe",quietly = TRUE)){ 45 | gse = "GSE42872" 46 | a = geo_download(gse,destdir=tempdir()) 47 | find_anno(geo$gpl) 48 | ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 49 | Group = rep(c("control","treat"),each = 3) 50 | Group = factor(Group) 51 | deg = get_deg(geo$exp,Group,ids,entriz = FALSE) 52 | head(deg) 53 | }else{ 54 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 55 | warning("Package 'AnnoProbe' needed for this function to work. 56 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 57 | } 58 | if(!requireNamespace("Biobase",quietly = TRUE)) { 59 | warning("Package 'Biobase' needed for this function to work. 60 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 61 | } 62 | } 63 | } 64 | } 65 | \seealso{ 66 | \code{\link{multi_deg}};\code{\link{get_deg_all}} 67 | } 68 | \author{ 69 | Xiaojie Sun 70 | } 71 | -------------------------------------------------------------------------------- /man/get_deg_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/5_get_deg_all.R 3 | \name{get_deg_all} 4 | \alias{get_deg_all} 5 | \title{get_deg_all} 6 | \usage{ 7 | get_deg_all( 8 | exp, 9 | group_list, 10 | ids, 11 | symmetry = TRUE, 12 | my_genes = NULL, 13 | show_rownames = FALSE, 14 | cluster_cols = TRUE, 15 | color_volcano = c("#2874C5", "grey", "#f87669"), 16 | logFC_cutoff = 1, 17 | pvalue_cutoff = 0.05, 18 | adjust = FALSE, 19 | entriz = TRUE, 20 | n_cutoff = 2, 21 | annotation_legend = FALSE, 22 | lab = NA, 23 | species = "human" 24 | ) 25 | } 26 | \arguments{ 27 | \item{exp}{A numeric matrix} 28 | 29 | \item{group_list}{A factor with duplicated character or factor} 30 | 31 | \item{ids}{a data.frame with 2 columns,including probe_id and symbol} 32 | 33 | \item{symmetry}{a logical value ,would you like to get your plot symmetrical} 34 | 35 | \item{my_genes}{genes for pheatmap} 36 | 37 | \item{show_rownames}{logical,show rownames or not} 38 | 39 | \item{cluster_cols}{boolean values determining if columns should be clustered or \code{hclust} object.} 40 | 41 | \item{color_volcano}{color for volcano} 42 | 43 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 44 | 45 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 46 | 47 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 48 | 49 | \item{entriz}{logical , if TRUE ,convert symbol to entriz id.} 50 | 51 | \item{n_cutoff}{3 by defalut , scale before plot and set a cutoff,usually 2 or 1.6} 52 | 53 | \item{annotation_legend}{logical,show annotation legend or not} 54 | 55 | \item{lab}{label for x axis in volcano plot, if NA , x axis names by package} 56 | 57 | \item{species}{choose human or mouse, or rat, default: human} 58 | } 59 | \value{ 60 | a list with deg data.frame, volcano plot ,pca plot ,heatmap and a list with DEGs. 61 | } 62 | \description{ 63 | do diffiencial analysis according to exprission set and group information 64 | } 65 | \examples{ 66 | \dontrun{ 67 | if(requireNamespace("Biobase",quietly = TRUE)& 68 | requireNamespace("AnnoProbe",quietly = TRUE)){ 69 | gse = "GSE42872" 70 | geo = geo_download(gse,destdir=tempdir()) 71 | group_list = rep(c("A","B"),each = 3) 72 | group_list = factor(group_list) 73 | find_anno(geo$gpl) 74 | ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 75 | dcp = get_deg_all(geo$exp,group_list,ids,entriz = FALSE) 76 | head(dcp$deg) 77 | dcp$plots 78 | }else{ 79 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 80 | warning("Package 'AnnoProbe' needed for this function to work. 81 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 82 | } 83 | if(!requireNamespace("Biobase",quietly = TRUE)) { 84 | warning("Package 'Biobase' needed for this function to work. 85 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 86 | } 87 | } 88 | } 89 | } 90 | \seealso{ 91 | \code{\link{get_deg}};\code{\link{multi_deg_all}} 92 | } 93 | \author{ 94 | Xiaojie Sun 95 | } 96 | -------------------------------------------------------------------------------- /man/get_gpl_txt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/2_geo_id.R 3 | \name{get_gpl_txt} 4 | \alias{get_gpl_txt} 5 | \title{get gpl txt from GEO} 6 | \usage{ 7 | get_gpl_txt(gpl, destdir = getwd(), download = FALSE) 8 | } 9 | \arguments{ 10 | \item{gpl}{gpl accession from GEO database} 11 | 12 | \item{destdir}{The destination directory for data downloads.} 13 | 14 | \item{download}{download the txt file or not} 15 | } 16 | \value{ 17 | a list with deg data.frame, volcano plot and a list with DEGs. 18 | } 19 | \description{ 20 | get gpl annotation txt file from GEO database 21 | } 22 | \examples{ 23 | get_gpl_txt("GPL23270",destdir = tempdir()) 24 | } 25 | \seealso{ 26 | \code{\link{geo_download}} 27 | } 28 | \author{ 29 | Xiaojie Sun 30 | } 31 | -------------------------------------------------------------------------------- /man/ggheat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/1_plots.R 3 | \name{ggheat} 4 | \alias{ggheat} 5 | \title{ggheat} 6 | \usage{ 7 | ggheat( 8 | dat, 9 | group, 10 | cluster = FALSE, 11 | color = c("#2874C5", "white", "#f87669"), 12 | legend_color = c("#2874C5", "#f87669", "#e6b707", "#868686", "#66C2A5", "#FC8D62", 13 | "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3"), 14 | show_rownames = TRUE, 15 | show_colnames = TRUE, 16 | cluster_rows = FALSE, 17 | cluster_cols = FALSE, 18 | groupname = "group", 19 | expname = "exp", 20 | fill_mid = TRUE 21 | ) 22 | } 23 | \arguments{ 24 | \item{dat}{expression matrix for plot} 25 | 26 | \item{group}{group for expression colnames} 27 | 28 | \item{cluster}{logical,cluster in both rows and column or not, default F,now replaced by cluster_rows and cluster_cols.} 29 | 30 | \item{color}{color for heatmap} 31 | 32 | \item{legend_color}{color for legend} 33 | 34 | \item{show_rownames}{logical,show rownames in plot or not, default T} 35 | 36 | \item{show_colnames}{logical,show colnames in plot or not, default T} 37 | 38 | \item{cluster_rows}{logical, if rows (on the plot) should be clustered, default F} 39 | 40 | \item{cluster_cols}{logical, if column (on the plot) should be clustered, default F} 41 | 42 | \item{groupname}{name of group legend} 43 | 44 | \item{expname}{name of exp legend} 45 | 46 | \item{fill_mid}{use median value as geom_tile fill midpoint} 47 | } 48 | \value{ 49 | a ggplot object 50 | } 51 | \description{ 52 | draw heatmap plot with annotation by ggplot2 53 | } 54 | \examples{ 55 | exp_dat = matrix(sample(100:1000,40),ncol = 4) 56 | exp_dat[1:(nrow(exp_dat)/2),] = exp_dat[1:(nrow(exp_dat)/2),]-1000 57 | rownames(exp_dat) = paste0("sample",1:nrow(exp_dat)) 58 | colnames(exp_dat) = paste0("gene",1:ncol(exp_dat)) 59 | group = rep(c("A","B"),each = nrow(exp_dat)/2) 60 | group = factor(group,levels = c("A","B")) 61 | ggheat(exp_dat,group) 62 | ggheat(exp_dat,group,cluster_rows = TRUE) 63 | ggheat(exp_dat,group,cluster_rows = TRUE,show_rownames = FALSE, 64 | show_colnames = FALSE,groupname = "risk",expname = "expression") 65 | } 66 | \author{ 67 | Xiaojie Sun 68 | } 69 | -------------------------------------------------------------------------------- /man/hypertest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/12_cor_and_hyper.R 3 | \name{hypertest} 4 | \alias{hypertest} 5 | \title{hypertest} 6 | \usage{ 7 | hypertest(lnc, pc, deMIR = NULL, lnctarget, pctarget) 8 | } 9 | \arguments{ 10 | \item{lnc}{lncRNA names} 11 | 12 | \item{pc}{mRNA names} 13 | 14 | \item{deMIR}{miRNA names , default NULL} 15 | 16 | \item{lnctarget}{a data.frame with two column,lncRNA in the first column ,miRNA in the second column} 17 | 18 | \item{pctarget}{a data.frame with two column,mRNA in the first column ,miRNA in the second column} 19 | } 20 | \value{ 21 | a data.frame with hypertest result 22 | } 23 | \description{ 24 | make hypertest for given lncRNA and mRNA common miRNAs 25 | } 26 | \examples{ 27 | # to update 28 | } 29 | \seealso{ 30 | \code{\link{plcortest}} 31 | } 32 | \author{ 33 | Xiaojie Sun 34 | } 35 | -------------------------------------------------------------------------------- /man/interaction_to_edges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/13_network_edge_node.R 3 | \name{interaction_to_edges} 4 | \alias{interaction_to_edges} 5 | \title{interaction_to_edges} 6 | \usage{ 7 | interaction_to_edges(df, a = 1, b = 2, sep = ",") 8 | } 9 | \arguments{ 10 | \item{df}{interactions data.frame} 11 | 12 | \item{a}{column to replicate} 13 | 14 | \item{b}{column to split} 15 | 16 | \item{sep}{a character string to separate b column} 17 | } 18 | \value{ 19 | a new data.frame with two column ,one interaction by one rows 20 | } 21 | \description{ 22 | split interactions by sep paramter,return edges data.frame 23 | } 24 | \examples{ 25 | df = data.frame(a = c("gene1","gene2","gene3"), 26 | b = c("d,f,a,b", 27 | "c,e,g", 28 | "a,b,d")) 29 | interaction_to_edges(df) 30 | } 31 | \seealso{ 32 | \code{\link{edges_to_nodes}} 33 | } 34 | \author{ 35 | Xiaojie Sun 36 | } 37 | -------------------------------------------------------------------------------- /man/intersect_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/14_dumd_all.R 3 | \name{intersect_all} 4 | \alias{intersect_all} 5 | \title{intersect_all} 6 | \usage{ 7 | intersect_all(...) 8 | } 9 | \arguments{ 10 | \item{...}{some vectors or a list with some vectors} 11 | } 12 | \value{ 13 | vector 14 | } 15 | \description{ 16 | calculate intersect set for two or more elements 17 | } 18 | \examples{ 19 | x1 = letters[1:4] 20 | x2 = letters[3:6] 21 | x3 = letters[3:4] 22 | re =intersect_all(x1,x2,x3) 23 | re2 = intersect_all(list(x1,x2,x3)) 24 | re3 = union_all(x1,x2,x3) 25 | } 26 | \seealso{ 27 | \code{\link{union_all}} 28 | } 29 | \author{ 30 | Xiaojie Sun 31 | } 32 | -------------------------------------------------------------------------------- /man/lnc_anno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{lnc_anno} 5 | \alias{lnc_anno} 6 | \title{lnc_anno} 7 | \format{ 8 | An object of class \code{data.frame} with 14826 rows and 3 columns. 9 | } 10 | \usage{ 11 | lnc_anno 12 | } 13 | \description{ 14 | annotation for TCGA expression matrix(lncRNA),form genecode v22 gtf file. 15 | } 16 | \examples{ 17 | head(lnc_anno) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/lnc_annov23.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{lnc_annov23} 5 | \alias{lnc_annov23} 6 | \title{lnc_annov23} 7 | \format{ 8 | An object of class \code{data.frame} with 14852 rows and 3 columns. 9 | } 10 | \usage{ 11 | lnc_annov23 12 | } 13 | \description{ 14 | annotation for TCGA and gtex expression matrix(lncRNA),form genecode v23 gtf file. 15 | } 16 | \examples{ 17 | head(lnc_annov23) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/mRNA_anno.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mRNA_anno} 5 | \alias{mRNA_anno} 6 | \title{mRNA_anno} 7 | \format{ 8 | An object of class \code{data.frame} with 19814 rows and 3 columns. 9 | } 10 | \usage{ 11 | mRNA_anno 12 | } 13 | \description{ 14 | annotation for TCGA and gtex expression matrix(mRNA),form genecode v22 gtf file. 15 | } 16 | \examples{ 17 | head(mRNA_anno) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/mRNA_annov23.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mRNA_annov23} 5 | \alias{mRNA_annov23} 6 | \title{mRNA_annov23} 7 | \format{ 8 | An object of class \code{data.frame} with 19797 rows and 3 columns. 9 | } 10 | \usage{ 11 | mRNA_annov23 12 | } 13 | \description{ 14 | annotation for TCGA and gtex expression matrix(mRNA),form genecode v23 gtf file. 15 | } 16 | \examples{ 17 | head(mRNA_annov23) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/make_tcga_group.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{make_tcga_group} 4 | \alias{make_tcga_group} 5 | \title{make_tcga_group} 6 | \usage{ 7 | make_tcga_group(exp) 8 | } 9 | \arguments{ 10 | \item{exp}{TCGA or TCGA_Gtex expression set from gdc or xena} 11 | } 12 | \value{ 13 | a group factor with normal and tumor ,correspond to colnames for expression matrix 14 | } 15 | \description{ 16 | make tcga group for given tcga expression matrix 17 | } 18 | \examples{ 19 | k = make_tcga_group(exp_hub1);table(k) 20 | } 21 | \seealso{ 22 | \code{\link{sam_filter}};\code{\link{match_exp_cl}} 23 | } 24 | \author{ 25 | Xiaojie Sun 26 | } 27 | -------------------------------------------------------------------------------- /man/match_exp_cl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{match_exp_cl} 4 | \alias{match_exp_cl} 5 | \title{match_exp_cl} 6 | \usage{ 7 | match_exp_cl(exp, cl, id_column = "id", sample_centric = TRUE) 8 | } 9 | \arguments{ 10 | \item{exp}{TCGA expression set} 11 | 12 | \item{cl}{TCGA clinical data.frame} 13 | 14 | \item{id_column}{which column contains patient ids, column number or colnmn name.} 15 | 16 | \item{sample_centric}{logical,deault T,keep all samples from the same patients.if FALSE,keep only one tumor sample for one patient.} 17 | } 18 | \value{ 19 | a transformed clinical data.frame with sample ids. 20 | } 21 | \description{ 22 | match exp and clinical data from TCGA 23 | } 24 | \examples{ 25 | a = match_exp_cl(exp_hub1,meta1[,2:4],"X_PATIENT") 26 | exp_matched = a[[1]] 27 | cl_matched = a[[2]] 28 | b = match_exp_cl(exp_hub1,meta1[,2:4],"X_PATIENT",sample_centric = FALSE) 29 | exp_matched = b[[1]] 30 | cl_matched = b[[2]] 31 | } 32 | \seealso{ 33 | \code{\link{make_tcga_group}};\code{\link{sam_filter}} 34 | } 35 | \author{ 36 | Xiaojie Sun 37 | } 38 | -------------------------------------------------------------------------------- /man/meta1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{meta1} 5 | \alias{meta1} 6 | \title{meta1} 7 | \format{ 8 | An object of class \code{data.frame} with 177 rows and 4 columns. 9 | } 10 | \usage{ 11 | meta1 12 | } 13 | \description{ 14 | clinical messages for some TCGA patients,correspond to exprSet_hub1 15 | } 16 | \examples{ 17 | head(meta1) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/multi_deg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/4_multi_deg.R 3 | \name{multi_deg} 4 | \alias{multi_deg} 5 | \title{multi_deg} 6 | \usage{ 7 | multi_deg( 8 | exp, 9 | group_list, 10 | ids, 11 | logFC_cutoff = 1, 12 | pvalue_cutoff = 0.05, 13 | adjust = FALSE, 14 | species = "human", 15 | entriz = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{exp}{A numeric matrix} 20 | 21 | \item{group_list}{A factor with duplicated character or factor} 22 | 23 | \item{ids}{a data.frame with 2 columns,including probe_id and symbol} 24 | 25 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 26 | 27 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 28 | 29 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 30 | 31 | \item{species}{choose human or mouse, or rat, default: human} 32 | 33 | \item{entriz}{whether convert symbols to entriz ids} 34 | } 35 | \value{ 36 | a deg data.frame with 10 columns 37 | } 38 | \description{ 39 | do diffiential analysis according to expression set and group information 40 | } 41 | \examples{ 42 | \dontrun{ 43 | if(requireNamespace("Biobase",quietly = TRUE)& 44 | requireNamespace("AnnoProbe",quietly = TRUE)){ 45 | gse = "GSE474" 46 | geo = geo_download(gse,destdir=tempdir()) 47 | geo$exp[1:4,1:4] 48 | geo$exp=log2(geo$exp+1) 49 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"), 50 | "MObese",ifelse(stringr::str_detect(geo$pd$title,"NonObese"), 51 | "NonObese","Obese")) 52 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 53 | find_anno(geo$gpl) 54 | ids <- AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 55 | deg = multi_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 56 | names(deg) 57 | head(deg[[1]]) 58 | head(deg[[2]]) 59 | head(deg[[3]]) 60 | }else{ 61 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 62 | warning("Package 'AnnoProbe' needed for this function to work. 63 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 64 | } 65 | if(!requireNamespace("Biobase",quietly = TRUE)) { 66 | warning("Package 'Biobase' needed for this function to work. 67 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 68 | } 69 | } 70 | } 71 | } 72 | \seealso{ 73 | \code{\link{get_deg}};\code{\link{multi_deg_all}} 74 | } 75 | \author{ 76 | Xiaojie Sun 77 | } 78 | -------------------------------------------------------------------------------- /man/multi_deg_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/6_multi_deg_all.R 3 | \name{multi_deg_all} 4 | \alias{multi_deg_all} 5 | \title{multi_deg_all} 6 | \usage{ 7 | multi_deg_all( 8 | exp, 9 | group_list, 10 | ids, 11 | symmetry = TRUE, 12 | my_genes = NULL, 13 | show_rownames = FALSE, 14 | cluster_cols = TRUE, 15 | color_volcano = c("#2874C5", "grey", "#f87669"), 16 | pvalue_cutoff = 0.05, 17 | logFC_cutoff = 1, 18 | adjust = FALSE, 19 | entriz = TRUE, 20 | annotation_legend = FALSE, 21 | lab = NA, 22 | species = "human" 23 | ) 24 | } 25 | \arguments{ 26 | \item{exp}{A numeric matrix} 27 | 28 | \item{group_list}{A factor with duplicated character or factor} 29 | 30 | \item{ids}{a data.frame with 2 columns,including probe_id and symbol} 31 | 32 | \item{symmetry}{a logical value ,would you like to get your plot symmetrical} 33 | 34 | \item{my_genes}{genes for pheatmap} 35 | 36 | \item{show_rownames}{boolean specifying if column names are be shown.} 37 | 38 | \item{cluster_cols}{boolean values determining if columns should be clustered or \code{hclust} object.} 39 | 40 | \item{color_volcano}{color for volcano} 41 | 42 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 43 | 44 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 45 | 46 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 47 | 48 | \item{entriz}{whether convert symbols to entriz ids} 49 | 50 | \item{annotation_legend}{boolean value showing if the legend for annotation 51 | tracks should be drawn.} 52 | 53 | \item{lab}{label for x axis in volcano plot, if NA , x axis names by package} 54 | 55 | \item{species}{choose human or mouse, or rat, default: human} 56 | } 57 | \value{ 58 | a list with deg data.frame, volcano plot and a list with DEGs. 59 | } 60 | \description{ 61 | do diffiencial analysis according to exprission set and group information 62 | } 63 | \examples{ 64 | \dontrun{ 65 | if(requireNamespace("Biobase",quietly = TRUE)& 66 | requireNamespace("AnnoProbe",quietly = TRUE)){ 67 | gse = "GSE474" 68 | geo = geo_download(gse,destdir=tempdir()) 69 | geo$exp[1:4,1:4] 70 | geo$exp=log2(geo$exp+1) 71 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 72 | ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 73 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 74 | find_anno(geo$gpl) 75 | ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 76 | dcp = multi_deg_all(geo$exp, 77 | group_list,ids,adjust = FALSE,entriz = FALSE) 78 | dcp[[3]] 79 | }else{ 80 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 81 | warning("Package 'AnnoProbe' needed for this function to work. 82 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 83 | } 84 | if(!requireNamespace("Biobase",quietly = TRUE)) { 85 | warning("Package 'Biobase' needed for this function to work. 86 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 87 | } 88 | } 89 | } 90 | } 91 | \seealso{ 92 | \code{\link{geo_download}};\code{\link{draw_volcano}};\code{\link{draw_venn}} 93 | } 94 | \author{ 95 | Xiaojie Sun 96 | } 97 | -------------------------------------------------------------------------------- /man/pkg_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pkg_all} 5 | \alias{pkg_all} 6 | \title{pkg_all} 7 | \format{ 8 | An object of class \code{data.frame} with 82 rows and 3 columns. 9 | } 10 | \usage{ 11 | pkg_all 12 | } 13 | \description{ 14 | bioconductor annotation packages for GPLs 15 | } 16 | \examples{ 17 | head(pkg_all) 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/plcortest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/12_cor_and_hyper.R 3 | \name{plcortest} 4 | \alias{plcortest} 5 | \title{plcortest} 6 | \usage{ 7 | plcortest(lnc_exp, mRNA_exp, cor_cutoff = 0) 8 | } 9 | \arguments{ 10 | \item{lnc_exp}{lncRNA expression set} 11 | 12 | \item{mRNA_exp}{mRNA expression set which nrow equal to lncRNA_exp} 13 | 14 | \item{cor_cutoff}{cor estimate cut_off, default 0} 15 | } 16 | \value{ 17 | a list with cor.test result,names are lncRNAs, element are mRNAs 18 | } 19 | \description{ 20 | make cor.test for given lncRNA and mRNA 21 | } 22 | \examples{ 23 | # to update 24 | } 25 | \seealso{ 26 | \code{\link{hypertest}} 27 | } 28 | \author{ 29 | Xiaojie Sun 30 | } 31 | -------------------------------------------------------------------------------- /man/plot_deg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/6_multi_deg_all.R 3 | \name{plot_deg} 4 | \alias{plot_deg} 5 | \title{plot_deg} 6 | \usage{ 7 | plot_deg( 8 | exp, 9 | group_list, 10 | deg, 11 | symmetry = TRUE, 12 | my_genes = NULL, 13 | show_rownames = FALSE, 14 | cluster_cols = TRUE, 15 | color_volcano = c("#2874C5", "grey", "#f87669"), 16 | pvalue_cutoff = 0.05, 17 | logFC_cutoff = 1, 18 | adjust = FALSE, 19 | annotation_legend = FALSE, 20 | lab = NA, 21 | species = "human" 22 | ) 23 | } 24 | \arguments{ 25 | \item{exp}{A numeric matrix} 26 | 27 | \item{group_list}{A factor with duplicated character or factor} 28 | 29 | \item{deg}{result of multi_deg or get_deg function} 30 | 31 | \item{symmetry}{a logical value ,would you like to get your plot symmetrical} 32 | 33 | \item{my_genes}{genes for pheatmap} 34 | 35 | \item{show_rownames}{boolean specifying if column names are be shown.} 36 | 37 | \item{cluster_cols}{boolean values determining if columns should be clustered or \code{hclust} object.} 38 | 39 | \item{color_volcano}{color for volcano} 40 | 41 | \item{pvalue_cutoff}{Cutoff value of pvalue,0.05 by default.} 42 | 43 | \item{logFC_cutoff}{Cutoff value of logFC,1 by default.} 44 | 45 | \item{adjust}{a logical value, would you like to use adjusted pvalue to draw this plot,FAlSE by default.} 46 | 47 | \item{annotation_legend}{boolean value showing if the legend for annotation 48 | tracks should be drawn.} 49 | 50 | \item{lab}{label for x axis in volcano plot, if NA , x axis names by package} 51 | 52 | \item{species}{choose human or mouse, or rat, default: human} 53 | } 54 | \value{ 55 | plots 56 | } 57 | \description{ 58 | plot pca plot,volcano plot,heatmap,and venn plot for Differential analysis result 59 | } 60 | \examples{ 61 | \dontrun{ 62 | if(requireNamespace("Biobase",quietly = TRUE)& 63 | requireNamespace("AnnoProbe",quietly = TRUE)){ 64 | gse = "GSE474" 65 | geo = geo_download(gse,destdir=tempdir()) 66 | geo$exp[1:4,1:4] 67 | geo$exp=log2(geo$exp+1) 68 | group_list=ifelse(stringr::str_detect(geo$pd$title,"MObese"),"MObese", 69 | ifelse(stringr::str_detect(geo$pd$title,"NonObese"),"NonObese","Obese")) 70 | group_list=factor(group_list,levels = c("NonObese","Obese","MObese")) 71 | find_anno(geo$gpl) 72 | ids = AnnoProbe::idmap(geo$gpl,destdir = tempdir()) 73 | deg = get_deg(geo$exp,group_list,ids,adjust = FALSE,entriz = FALSE) 74 | plot_deg(geo$exp,group_list,deg) 75 | }else{ 76 | if(!requireNamespace("AnnoProbe",quietly = TRUE)) { 77 | warning("Package 'AnnoProbe' needed for this function to work. 78 | Please install it by install.packages('AnnoProbe')",call. = FALSE) 79 | } 80 | if(!requireNamespace("Biobase",quietly = TRUE)) { 81 | warning("Package 'Biobase' needed for this function to work. 82 | Please install it by BiocManager::install('Biobase')",call. = FALSE) 83 | } 84 | } 85 | } 86 | } 87 | \author{ 88 | Xiaojie Sun 89 | } 90 | -------------------------------------------------------------------------------- /man/point_cut.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/10_survival_cut_cox_km.R 3 | \name{point_cut} 4 | \alias{point_cut} 5 | \title{point_cut} 6 | \usage{ 7 | point_cut(exprSet_hub, meta) 8 | } 9 | \arguments{ 10 | \item{exprSet_hub}{a tumor expression set for hubgenes} 11 | 12 | \item{meta}{meta data corresponds to expression set} 13 | } 14 | \value{ 15 | a vector with cutpoint for genes 16 | } 17 | \description{ 18 | calculate cut point for multiple genes 19 | } 20 | \examples{ 21 | point_cut(exprSet_hub1,meta1) 22 | } 23 | \seealso{ 24 | \code{\link{surv_KM}};\code{\link{surv_cox}} 25 | } 26 | \author{ 27 | Xiaojie Sun 28 | } 29 | -------------------------------------------------------------------------------- /man/quick_enrich.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/7_quick_double_enrich.R 3 | \name{quick_enrich} 4 | \alias{quick_enrich} 5 | \title{quick_enrich} 6 | \usage{ 7 | quick_enrich( 8 | genes, 9 | kkgo_file = "kkgo_file.Rdata", 10 | destdir = getwd(), 11 | species = "human" 12 | ) 13 | } 14 | \arguments{ 15 | \item{genes}{a gene symbol or entrizid vector} 16 | 17 | \item{kkgo_file}{Rdata filename for kegg and go result} 18 | 19 | \item{destdir}{destdir to save kkgofile} 20 | 21 | \item{species}{choose human or mouse, or rat, default: human} 22 | } 23 | \value{ 24 | enrichment results and dotplots 25 | } 26 | \description{ 27 | do diffiencial analysis according to exprission set and group information,for human only 28 | } 29 | \examples{ 30 | \dontrun{ 31 | if(requireNamespace("org.Hs.eg.db",quietly = TRUE)){ 32 | head(genes) 33 | g = quick_enrich(genes,destdir = tempdir()) 34 | names(g) 35 | g[[1]][1:4,1:4] 36 | g[[3]] 37 | g[[4]] 38 | }else{ 39 | warning("Package 'org.Hs.eg.db' needed for this function to work. 40 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 41 | } 42 | } 43 | } 44 | \seealso{ 45 | \code{\link{double_enrich}} 46 | } 47 | \author{ 48 | Xiaojie Sun 49 | } 50 | -------------------------------------------------------------------------------- /man/risk_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/11_surv_box_plot.R 3 | \name{risk_plot} 4 | \alias{risk_plot} 5 | \title{risk_plot} 6 | \usage{ 7 | risk_plot( 8 | exprSet_hub, 9 | meta, 10 | riskscore, 11 | cut.point = FALSE, 12 | color = c("#2fa1dd", "#f87669"), 13 | n_cutoff = 3 14 | ) 15 | } 16 | \arguments{ 17 | \item{exprSet_hub}{a tumor expression set for hubgenes} 18 | 19 | \item{meta}{meta data corresponds to expression set} 20 | 21 | \item{riskscore}{a numeric vector of riskscore} 22 | 23 | \item{cut.point}{logical , use cut_point or not, if FALSE,use median by defult} 24 | 25 | \item{color}{color for boxplot} 26 | 27 | \item{n_cutoff}{3 by defalut , scale before plot and set a cutoff,usually 2 or 1.6} 28 | } 29 | \value{ 30 | risk plot 31 | } 32 | \description{ 33 | draw risk plot 34 | } 35 | \examples{ 36 | risk_plot(exprSet_hub1,meta1,riskscore = rnorm(nrow(meta1))) 37 | } 38 | \seealso{ 39 | \code{\link{exp_boxplot}};\code{\link{box_surv}};\code{\link{draw_venn}} 40 | } 41 | \author{ 42 | Xiaojie Sun 43 | } 44 | -------------------------------------------------------------------------------- /man/sam_filter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{sam_filter} 4 | \alias{sam_filter} 5 | \title{sam_filter} 6 | \usage{ 7 | sam_filter(exp) 8 | } 9 | \arguments{ 10 | \item{exp}{TCGA or TCGA_Gtex expression set from gdc or xena} 11 | } 12 | \value{ 13 | a transformed expression set without duplicated samples 14 | } 15 | \description{ 16 | drop duplicated samples from the same patients 17 | } 18 | \examples{ 19 | cod[1:4,1:4] 20 | dim(cod) 21 | cod2 = sam_filter(cod) 22 | dim(cod2) 23 | g = make_tcga_group(cod);table(g) 24 | library(stringr) 25 | table(!duplicated(str_sub(colnames(cod[,g=="tumor"]),1,12))) 26 | } 27 | \seealso{ 28 | \code{\link{make_tcga_group}};\code{\link{match_exp_cl}} 29 | } 30 | \author{ 31 | Xiaojie Sun 32 | } 33 | -------------------------------------------------------------------------------- /man/surv_KM.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/10_survival_cut_cox_km.R 3 | \name{surv_KM} 4 | \alias{surv_KM} 5 | \title{surv_KM} 6 | \usage{ 7 | surv_KM( 8 | exprSet_hub, 9 | meta, 10 | cut.point = FALSE, 11 | pvalue_cutoff = 0.05, 12 | min_gn = 0.1 13 | ) 14 | } 15 | \arguments{ 16 | \item{exprSet_hub}{a tumor expression set for hubgenes} 17 | 18 | \item{meta}{meta data corresponds to expression set} 19 | 20 | \item{cut.point}{logical , use cut_point or not, if FALSE,use median by defult} 21 | 22 | \item{pvalue_cutoff}{p value cut off ,0.05 by defult} 23 | 24 | \item{min_gn}{Depending on the expression of a gene, there may be a large difference in the number of samples between the two groups, and if a smaller group of samples is less than 10 percent (default) of all, the gene will be discarded} 25 | } 26 | \value{ 27 | a vector with gene names and log_rank p value 28 | } 29 | \description{ 30 | calculate log_rank test p values for genes 31 | } 32 | \examples{ 33 | surv_KM(exprSet_hub1,meta1) 34 | surv_KM(exprSet_hub1,meta1,pvalue_cutoff = 1) 35 | surv_KM(exprSet_hub1,meta1,cut.point = TRUE) 36 | } 37 | \seealso{ 38 | \code{\link{point_cut}};\code{\link{surv_cox}} 39 | } 40 | \author{ 41 | Xiaojie Sun 42 | } 43 | -------------------------------------------------------------------------------- /man/surv_cox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/10_survival_cut_cox_km.R 3 | \name{surv_cox} 4 | \alias{surv_cox} 5 | \title{surv_cox} 6 | \usage{ 7 | surv_cox( 8 | exprSet_hub, 9 | meta, 10 | cut.point = FALSE, 11 | pvalue_cutoff = 0.05, 12 | HRkeep = "all", 13 | continuous = FALSE, 14 | min_gn = 0.1 15 | ) 16 | } 17 | \arguments{ 18 | \item{exprSet_hub}{a tumor expression set for hubgenes} 19 | 20 | \item{meta}{meta data corresponds to expression set} 21 | 22 | \item{cut.point}{logical , use cut_point or not, if FALSE,use median by defult} 23 | 24 | \item{pvalue_cutoff}{p value cut off ,0.05 by defult} 25 | 26 | \item{HRkeep}{one of "all","protect"or"risk"} 27 | 28 | \item{continuous}{logical, gene expression or gene expression group} 29 | 30 | \item{min_gn}{Depending on the expression of a gene, there may be a large difference in the number of samples between the two groups, and if a smaller group of samples is less than 10 percent (default) of all, the gene will be discarded} 31 | } 32 | \value{ 33 | a matrix with gene names ,cox p value and HR 34 | } 35 | \description{ 36 | calculate cox p values and HR for genes 37 | } 38 | \examples{ 39 | surv_cox(exprSet_hub1,meta1) 40 | surv_cox(exprSet_hub1,meta1,cut.point = TRUE,continuous = TRUE) 41 | surv_cox(exprSet_hub1,meta1,cut.point = TRUE,continuous = TRUE,pvalue_cutoff = 1) 42 | } 43 | \seealso{ 44 | \code{\link{point_cut}};\code{\link{surv_KM}} 45 | } 46 | \author{ 47 | Xiaojie Sun 48 | } 49 | -------------------------------------------------------------------------------- /man/t_choose.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/9_cor_t_choose.R 3 | \name{t_choose} 4 | \alias{t_choose} 5 | \title{t_choose} 6 | \usage{ 7 | t_choose( 8 | genes, 9 | exp, 10 | group_list, 11 | up_only = FALSE, 12 | down_only = FALSE, 13 | pvalue_cutoff = 0.05 14 | ) 15 | } 16 | \arguments{ 17 | \item{genes}{a vector with some genes} 18 | 19 | \item{exp}{A numeric matrix} 20 | 21 | \item{group_list}{A factor with duplicated character or factor} 22 | 23 | \item{up_only}{keep up genes in the result only} 24 | 25 | \item{down_only}{keep down genes in the result only} 26 | 27 | \item{pvalue_cutoff}{p value cut off ,0.05 by defult} 28 | } 29 | \value{ 30 | a vector with differential expressed genes 31 | } 32 | \description{ 33 | choose differential expressed genes by simple t.test 34 | } 35 | \examples{ 36 | exp = matrix(rnorm(1000),ncol = 10) 37 | rownames(exp) = sample(mRNA_annov23$gene_id,100) 38 | colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 39 | exp2 = trans_exp(exp) 40 | exp2[,1:5] = exp2[,1:5]+10 41 | group_list = rep(c("A","B"),each = 5) 42 | genes = sample(rownames(exp2),3) 43 | t_choose(genes,exp2,group_list) 44 | } 45 | \author{ 46 | Xiaojie Sun 47 | } 48 | -------------------------------------------------------------------------------- /man/trans_array.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{trans_array} 4 | \alias{trans_array} 5 | \title{trans_array} 6 | \usage{ 7 | trans_array(exp, ids, from = "probe_id", to = "symbol") 8 | } 9 | \arguments{ 10 | \item{exp}{microarray expression matrix with probe_id as rownames} 11 | 12 | \item{ids}{data.frame with original rownames and new rownames} 13 | 14 | \item{from}{colname for original rownames} 15 | 16 | \item{to}{colname for new rownames} 17 | } 18 | \value{ 19 | a transformed expression set with new rownames 20 | } 21 | \description{ 22 | transform rownames for microarray or rnaseq expression matrix 23 | } 24 | \examples{ 25 | exp = matrix(1:50,nrow = 10) 26 | rownames(exp) = paste0("g",1:10) 27 | ids = data.frame(probe_id = paste0("g",1:10), 28 | symbol = paste0("G",c(1:9,9))) 29 | trans_array(exp,ids) 30 | } 31 | \seealso{ 32 | \code{\link{trans_exp}} 33 | } 34 | \author{ 35 | Xiaojie Sun 36 | } 37 | -------------------------------------------------------------------------------- /man/trans_entrezexp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{trans_entrezexp} 4 | \alias{trans_entrezexp} 5 | \title{trans_entrezexp} 6 | \usage{ 7 | trans_entrezexp(entrezexp, species = "human") 8 | } 9 | \arguments{ 10 | \item{entrezexp}{expression set with entrezid as rownames} 11 | 12 | \item{species}{choose human or mouse, or rat, default: human} 13 | } 14 | \value{ 15 | a transformed expression set with symbol 16 | } 17 | \description{ 18 | transform rownames of expression set from "entrez" to"symbol",according to the bitr function. 19 | } 20 | \examples{ 21 | exp = matrix(rnorm(200),ncol = 10) 22 | rownames(exp) = c("79691", "56271", "8662", "10394", "55630", "159162", "23541", 23 | "79723", "54413", "22927", "92342", "23787", "5550", "8924", 24 | "55274", "866", "8844", "353299", "587", "1473") 25 | colnames(exp) = paste0("s",1:10) 26 | if(requireNamespace("org.Hs.eg.db",quietly = TRUE)){ 27 | exp2 = trans_entrezexp(exp) 28 | }else{ 29 | warning("Package \"org.Hs.eg.db\" needed for this function to work. 30 | Please install it by BiocManager::install('org.Hs.eg.db')",call. = FALSE) 31 | } 32 | } 33 | \seealso{ 34 | \code{\link{trans_exp}} 35 | } 36 | \author{ 37 | Xiaojie Sun 38 | } 39 | -------------------------------------------------------------------------------- /man/trans_exp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{trans_exp} 4 | \alias{trans_exp} 5 | \title{trans_exp} 6 | \usage{ 7 | trans_exp(exp, mrna_only = FALSE, lncrna_only = FALSE, gtex = FALSE) 8 | } 9 | \arguments{ 10 | \item{exp}{TCGA or TCGA_Gtex expression set from gdc or xena} 11 | 12 | \item{mrna_only}{only keep mrna rows in result} 13 | 14 | \item{lncrna_only}{only keep lncrna rows in result} 15 | 16 | \item{gtex}{logical,whether including Gtex data} 17 | } 18 | \value{ 19 | a transformed expression set with symbol 20 | } 21 | \description{ 22 | transform rownames of TCGA or TCGA_Gtex expression set from gdc or xena,from ensembl id to gene symbol 23 | } 24 | \examples{ 25 | exp = matrix(rnorm(1000),ncol = 10) 26 | rownames(exp) = sample(mRNA_annov23$gene_id,100) 27 | colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 28 | k = trans_exp(exp) 29 | } 30 | \seealso{ 31 | \code{\link{trans_array}} 32 | } 33 | \author{ 34 | Xiaojie Sun 35 | } 36 | -------------------------------------------------------------------------------- /man/trans_exp_new.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/8_tcga_group_trans_exp.R 3 | \name{trans_exp_new} 4 | \alias{trans_exp_new} 5 | \title{trans_exp_new} 6 | \usage{ 7 | trans_exp_new(exp, mrna_only = FALSE, lncrna_only = FALSE, species = "human") 8 | } 9 | \arguments{ 10 | \item{exp}{expression set with ensembl as rownames} 11 | 12 | \item{mrna_only}{only keep mrna rows in result} 13 | 14 | \item{lncrna_only}{only keep lncrna rows in result} 15 | 16 | \item{species}{choose human or mouse, or rat, default: human} 17 | } 18 | \value{ 19 | a transformed expression set with symbol 20 | } 21 | \description{ 22 | transform rownames of expression set from "ensembl" to"symbol",according to the new information from ensembl database. 23 | } 24 | \examples{ 25 | exp = matrix(rnorm(1000),ncol = 10) 26 | rownames(exp) = sample(mRNA_annov23$gene_id,100) 27 | colnames(exp) = c(paste0("TCGA",1:5),paste0("GTEX",1:5)) 28 | if(requireNamespace("AnnoProbe")){ 29 | k = trans_exp_new(exp) 30 | }else{ 31 | warning("Package \"AnnoProbe\" needed for this function to work. 32 | Please install it by install.packages('AnnoProbe')") 33 | } 34 | } 35 | \seealso{ 36 | \code{\link{trans_exp}} 37 | } 38 | \author{ 39 | Xiaojie Sun 40 | } 41 | -------------------------------------------------------------------------------- /man/union_all.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/14_dumd_all.R 3 | \name{union_all} 4 | \alias{union_all} 5 | \title{union_all} 6 | \usage{ 7 | union_all(...) 8 | } 9 | \arguments{ 10 | \item{...}{some vectors or a list with some vectors} 11 | } 12 | \value{ 13 | vector 14 | } 15 | \description{ 16 | calculate union set for two or more elements 17 | } 18 | \examples{ 19 | x1 = letters[1:4] 20 | x2 = letters[3:6] 21 | x3 = letters[3:4] 22 | re =intersect_all(x1,x2,x3) 23 | re2 = intersect_all(list(x1,x2,x3)) 24 | re3 = union_all(x1,x2,x3) 25 | } 26 | \seealso{ 27 | \code{\link{intersect_all}} 28 | } 29 | \author{ 30 | Xiaojie Sun 31 | } 32 | -------------------------------------------------------------------------------- /tinyarray.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | --------------------------------------------------------------------------------