title | author | time |
---|---|---|
TCMR |
Jinkun Liu, Min Ying |
2023-09-07 |
Hello, here is the TCMR package for TCM research. TCMR的维护和更新将要转到新的包:TCMNP.请移到 https://github.com/tcmlab/TCMNP
You can install the development version of TCMR like so:
if(!require(devtools))install.packages("devtools")
if(!require(TCMR))devtools::install_github("tcmlab/TCMR",upgrade = FALSE,dependencies = TRUE)
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("TCMR-main.zip", upgrade = F, dependencies = T)
library(TCMR)
library(dplyr)
library(ggplot2)
library(ggraph)
library(clusterProfiler, quietly= TRUE)
library(org.Hs.eg.db, quietly= TRUE)
library(DOSE, quietly= TRUE)
xfbdf.compostion <- data.frame(
herb = c(
"mahuang", "kuxingren", "shengshigao",
"shengyiren", "maocangzhu", "guanghuoxiang",
"qinghaocao", "mabiancao", "ganlugen", "tinglizi",
"huajuhong", "shenggancao", "huzhang"
),
weight = c(6, 15, 30, 30, 10, 15, 12, 30, 30, 15, 15, 10, 20)
)
tcm_comp(xfbdf.compostion)
herb = c("ma huang", "ku xing ren", "hua ju hong",
"cang zhu", "guang huo xiang", "yi yi ren",
"hu zhang", "qing hao", "ma bian cao", "lu gen",
"ting li zi", "shi gao", "gan cao")
xfbdf.compostion <- data.frame(
herb = herb,
weight = c(6, 15, 15, 10, 15, 30, 20, 12, 30, 30, 15, 30, 10),
property = herb_pm[match(herb, herb_pm$Herb_name_pinyin), ]$Property,
flavor = herb_pm[match(herb, herb_pm$Herb_name_pinyin), ]$Flavor,
meridian = herb_pm[match(herb, herb_pm$Herb_name_pinyin), ]$Meridian
)
tcm_comp_plus(xfbdf.compostion)
herbs<-c('麻黄', '甘草','苦杏仁','石膏',
'薏苡仁', '苍术', '青蒿', '猪苓',
'马鞭草', '葶苈子','化橘红',
'虎杖', '广藿香','芦根')
xfbdf <- herb_target(herbs, type = "Herb_cn_name")
head(xfbdf)
herb molecule_id molecule target
cang zhu MOL000173 wogonin NOS2
cang zhu MOL000173 wogonin PTGS1
cang zhu MOL000173 wogonin ESR1
cang zhu MOL000173 wogonin AR
cang zhu MOL000173 wogonin SCN5A
cang zhu MOL000173 wogonin PPARG
herbs2 <- c("ma huang", "ku xing ren")
fufang2 <- herb_target(herbs2, type ="Herb_name_pin_yin")
head(fufang2)
herb molecule_id molecule target
ku xing ren MOL010921 estrone D1R
ku xing ren MOL010921 estrone DRD1
ku xing ren MOL010921 estrone CHRM3
ku xing ren MOL010921 estrone F2
ku xing ren MOL010921 estrone CHRM1
ku xing ren MOL010921 estrone CHRM5
gene <- c("MAPK1", "JUN", "FOS", "RAC1", "IL1", "IL6")
herb.data <- target_herb(gene)
head(herb.data)
herb molecule_id molecule target
ai di cha MOL000422 kaempferol JUN
ai di cha MOL000098 quercetin FOS
ai di cha MOL000098 quercetin MAPK1
ai di cha MOL000098 quercetin JUN
ai di cha MOL000098 quercetin IL6
ai ye MOL000358 beta-sitosterol JUN
#通过疾病靶点基因寻找中药及其处方
#寻找到的中药
tcm_prescription(disease_data)[[1]]
# A tibble: 273 × 2
# Groups: Herb_cn_name [273]
Herb_cn_name freq
<chr> <int>
1 人参 437
2 甘草 433
3 胡芦巴 325
4 皂角刺 288
5 地榆 276
# ℹ 263 more rows
# ℹ Use `print(n = ...)` to see more rows
#寻找到的处方
library(formattable)
formattable(tcm_prescription(disease_data)[[2]], list(Count = color_bar("lightblue")))
# draw plot
tcm_pre_plot(tcm_prescription(disease_data)[[2]],color = 'Spectral')
data("xfbdf", package = "TCMR")
network.data <- xfbdf %>%
dplyr::select(herb, molecule, target) %>%
sample_n(100, replace = FALSE) %>%
as.data.frame()
tcm_net(network.data,
label.degree = 3,
rem.dis.inter = TRUE)
degree_plot(xfbdf,plot.set='horizontal')
sankey.data <- xfbdf[sample(nrow(xfbdf), 30), ]
tcm_sankey(sankey.data,
text.size = 3,
text.position = 1
)
alluvial.data <- xfbdf[sample(nrow(xfbdf), 30), ]
tcm_alluvial(alluvial.data,
text.size = 3,
text.position = 1
)
data(xfbdf, package = "TCMR")
eg <- bitr(unique(xfbdf$target), fromType = "SYMBOL", toType = "ENTREZID", OrgDb = "org.Hs.eg.db")
KK <- enrichKEGG(
gene = eg$ENTREZID,
organism = "hsa",
pvalueCutoff = 0.05
)
KK <- setReadable(KK, "org.Hs.eg.db", keyType = "ENTREZID")
bar_plot(KK,title = "KEGG")
BP <- enrichGO(
gene = eg$ENTREZID,
"org.Hs.eg.db",
ont = "BP",
pvalueCutoff = 0.05,
readable = TRUE
)
bar_plot(BP,title = "biological process")
dot_plot(KK, title = "KEGG")
lollipop_plot(KK, title = "KEGG")
cir_plot(KK)
#Filter the pathways to display
data(KK, package = "TCMR")
newdata <- KK %>% dplyr::slice(11, 15, 17, 33, 53, .preserve = .preserve)
pathway_cirplot(newdata)
pathway_ccplot(KK, root = "KEGG")
bubble_plot(KK)
dot_sankey(newdata, dot.x = 0.35, dot.y = 0.25)
data(kegg.filter, package = "TCMR")
#Because not all pathways and genes are what we want to display, and displaying too many genes at the same time will cause text overlap.
#The data format must be an S4 object or data frame.
#"kegg.filter" was derived from the data frame after kegg-enriched data is screened for pathways and genes.
dot_sankey(kegg.filter)
eg <- bitr(unique(xfbdf$target), fromType = "SYMBOL", toType = "ENTREZID", OrgDb = "org.Hs.eg.db")
go.diff <- enrichGO(
gene = eg$ENTREZID,
org.Hs.eg.db,
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
ont = "all",
readable = T
)
go_barplot(go.diff)
go_dotplot(go.diff)
go_lollipop(go.diff)
go_cir(go.diff)
KK2 <- KK %>% mutate(richFactor = Count / as.numeric(sub("/\\d+", "", BgRatio)))
path <- separate_rows(KK2@result, geneID, sep = "/")
data_sankey <- left_join(xfbdf, path,
by = c("target" = "geneID"),
relationship = "many-to-many"
) %>%
distinct() %>%
drop_na() %>%
sample_n(30, replace = FALSE) %>%
as.data.frame()
tcm_sankey_dot(data_sankey)
data_sankey2<- data_sankey %>%
dplyr::select(herb, molecule, target, Description)
tcm_sankey(data_sankey2,text.position = 1)
tcm_alluvial_dot(data_sankey)
tcm_alluvial(data_sankey2, text.position = 1)
data(string, package = "TCMR")
ppi_plot(string,
label.degree = 1,
nodes.color = "Spectral",
label.repel = TRUE)
ppi_plot(string, nodes.color = "Spectral",
label.degree = 1,
label.size = 3,
label.repel = TRUE,
graph.layout = 'circle')
data <- matrix(rnorm(81), 9, 9)
data[1:9, seq(1, 9, 2)] <- data[1:9, seq(1, 9, 2)] - 4
colnames(data) <- paste("molecule", 1:9, sep = "")
rownames(data) <- paste("target", 1:9, sep = "")
data <- round(data, 2)
dock_plot(data)
dock_plot(data, shape = "circle", legend.height = 3)
data(venn.data, package = "TCMR")
venn_plot(venn.data, type = 1)
venn_plot(venn.data, type = 2)
data(venn.data, package = "TCMR")
gene <- names(sort(table(venn.data$gene), decreasing = TRUE))[1:50]
data <- venn.data[venn.data$gene %in% gene, ]
data2 <- sample_n(venn.data, 100) %>% rbind(data)
venn_net(data2, label.degree = 1)
#targets shared by four datasets
venn_net(data2, label.degree = 4)
venn_net(data2, edge.type = "hive", label.degree = 4)
# Finding transcription factors and their target genes
data(xfbdf, package = "TCMR")
newdata <- tf_filter(xfbdf$target)
head(newdata)
TF Target Mode_of_Regulation References(PMID) Species Database
AHR ABCG2 Unknown 20460431 Human TRRUST
AHR AHRR Activation 18848529 Human TRRUST
AHR ARNT Unknown 19255421;8631989 Human TRRUST
AHR BRCA1 Unknown 18259752 Human TRRUST
AHR CA9 Repression 19154183 Human TRRUST
AHR CCND1 Unknown 24380854 Human TRRUST
# Visualization of filtered transcription factor data
data(xfbdf, package = "TCMR")
tf_data <- tf_filter(xfbdf$target)
set.seed(1234)
data <- tf_data[, 1:2] %>%
distinct() %>%
sample_n(100)
tf_cirplot(data, color = "Spectral")
data("mahuang", package = "TCMR")
data <- etcm(mahuang, herb = "ma huang")
head(data)
herb molecule target QED
ma huang Kaempferol ACTB 0.9643
ma huang Kaempferol AHR 0.9643
ma huang Kaempferol AKR1C1 0.8621
ma huang Kaempferol AKT1 0.963
ma huang Kaempferol ATP5A1 0.9643
ma huang Kaempferol ATP5B 0.9643