tbtools插件的三种方法


第一种做插件的方法,适合一个文件夹,这个文件夹包含可执行的文

这个插件作者有一篇文章和一个视频
文章:https://mp.weixin.qq.com/s/3sXGyUwsYhld0vSBAcKSQQ
视频:https://www.bilibili.com/video/BV1tM411r7id/?spm_id_from=333.999.0.0

第二种做插件的方法,用 java 代码或其他代码描述,适合单个文件代码就能描述的功能。

下面举个例子
想做这样一个插件:有表格行批量提取的功能
例:我们有一个基因表达量矩阵,可能有 100Mb,我们需要从里面提取是 100 个基因
的表达量
描述:插件可以接受三个命令行参数,第一个参数是接受一个表格文件,表格文件中有
行名,有列名,第二个参数是一个 ID 列表文件,每一行是一个 ID。这个代码主要功能是,
按照 ID 列表文件中的 ID 提取表格文件中第一列匹配到 ID 的所有行,匹配内容输出到输出
文件。另外,最终文件同样需要有行名和列名。
代码:
import java.io.;
import java.util.
;
public class ExtractRows {
public static void main(String[] args) throws IOException {
// 解析命令行参数
String tableFileName = args[0];
String idListFileName = args[1];
String outputFileName = args[2];
// 读取表格文件
List<String[]> rows = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(tableFileName)))
{
String line;
while ((line = reader.readLine()) != null) {
String[] fields = line.split(“,”);
rows.add(fields);
}
}
// 读取 ID 列表文件
Set idSet = new HashSet<>();
try (BufferedReader reader = new BufferedReader(new FileReader(idListFileName)))
{
String line;
while ((line = reader.readLine()) != null) {
idSet.add(line);
}
}
// 提取行并写入输出文件
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName))) {
// 写入行名
writer.write(String.join(“,”, rows.get(0)));
writer.newLine();
// 写入匹配到的行
for (int i = 1; i < rows.size(); i++) {
String[] fields = rows.get(i);
if (idSet.contains(fields[0])) {
writer.write(String.join(“,”, fields));
writer.newLine();
}
}
}
}
}

准备好表格文件:

和 ID 列表文件:

拖入插件然后 start 的结果
用 CLI Progrem Wrapper Creator 做 progrem2.plugin 的界面

做好后的插件,拖入表格后,也能以 txt 和 csv 的形式输出

第三种做插件的方法,用 R 语言,Rstudio 的 shinyapp,理论上只要R 上能跑的,都能做成 TBtools 插件。这个要求对 R 语言和 shiny 熟悉。

TBtools 有一个插件 WGCNA.shiny,可以下载下来,他就是用 shiny 写成的。需要替换它的源
代码。

下载链接: https://tbtools.cowtransfer.com/s/7667396e6fdc4b

下面是这个例子的 shiny 代码
#一键安装包,把#删去就行
#if (!requireNamespace(“BiocManager”, quietly = TRUE))

install.packages(“BiocManager”)

#BiocManager::install(c(“openxlsx”, “ggplot2”, “stringr”, “enrichplot”, “clusterProfiler”,
“topGO”, “Rgraphviz”, “GOplot”, “DOSE”, “ggnewscale”, “circlize”, “ComplexHeatmap”))
library(shiny)
library(openxlsx)
library(ggplot2)
library(stringr)
library(enrichplot)
library(clusterProfiler)
library(topGO)
library(circlize)
library(ComplexHeatmap)
library(org.Hs.eg.db)
ui <- fluidPage(
titlePanel(“基于 R 代码的富集分析”),
sidebarLayout(
sidebarPanel(
fileInput(“file”, “上传差异表达数据(.xlsx)”),
selectInput(“go_species”, “选择物种 GO(Gg:鸡.HS:人.Ss:猪):”, choices = c(‘Gg’,’Hs’,’Ss’)),
actionButton(“goToBioconductor”, “GO 物种缩写索引表”),
selectInput(“kegg_species”, “ 选 择 物 种 KEGG(gga: 鸡 .hsa: 人 .pig: 猪 ):”, choices =
c(‘gga’,’hsa’,’pig’)),
actionButton(“goToKEGG”, “KEGG 物种缩写索引表”),
actionButton(“go”, “开始分析”),

helpText(“上传差异表达数据,选择物种 GO 和 KEGG,然后点击开始分析按钮进行富
集分析.”),

helpText(“ 这 个 数 据 可 以 是 一 行 , 两 行 , 或 者 四 行 , \n 但 行 名 需 要 是
‘SYMBOL’,’Log2FoldChange’, ‘pvalue’, ‘padj’,\n \n 对应的是 SYMBOL(基因符号)。
Log2FoldChange(差异表达的对数倍数)。pvalue(假设检验的 p 值)。padj(校正后的 p
值,例如通过 Bonferroni 校正)”),
helpText(“例如 GABRD 4.4991283 5.98E-119 1.02E-114”),

helpText(“”),

),
mainPanel(
tabsetPanel(
tabPanel(“GO 富集分析”,
plotOutput(“GO_barplot”),
plotOutput(“GO_dotplot”),
plotOutput(“GO_cnetplot”),
plotOutput(“GO_heatplot”),
plotOutput(“GO_emapplot”)
),
tabPanel(“KEGG 富集分析”,
plotOutput(“KEGG_barplot”),
plotOutput(“KEGG_dotplot”),
plotOutput(“KEGG_cnetplot”),
plotOutput(“KEGG_plot”)),
tabPanel(“GSEA 富集分析”,
plotOutput(“GSEA_plot”))
)
)
)
)
server <- function(input, output) {

data <- reactive({
if (is.null(input$file)) {
return(NULL)
}
file <- input$file$datapath
info <- read.xlsx(file,rowNames = F,colNames = T)
if (ncol(info) == 1) {
names(info) <- c(‘SYMBOL’)
} else if (ncol(info) == 2) {
names(info) <- c(‘SYMBOL’,’Log2FoldChange’)
} else if (ncol(info) == 4) {
names(info) <- c(‘SYMBOL’,’Log2FoldChange’,’pvalue’,’padj’)
}
info
})

gene <- reactive({
if (is.null(data())) {
return(NULL)
}
bitr(data()$SYMBOL, fromType = ‘SYMBOL’, toType = ‘ENTREZID’,
OrgDb = paste0(‘org.’, str_extract(input$go_species, ‘\w+’), ‘.eg.db’))
})

GO_result <- reactive({
if (is.null(gene())) {
return(NULL)
}
enrichGO(gene()$ENTREZID,
OrgDb = paste0(‘org.’, str_extract(input$go_species, ‘\w+’), ‘.eg.db’),
keyType = “ENTREZID”,
ont = “ALL”,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05,
readable = T)
})

observeEvent(input$goToBioconductor, {
browseURL(“http://bioconductor.org/packages/release/BiocViews.html#___OrgDb")
})

KEGG_result <- reactive({
if (is.null(gene())) {
return(NULL)
}
enrichKEGG(gene()$ENTREZID,
organism = input$kegg_species,
pvalueCutoff = 0.05,
qvalueCutoff = 0.05)
})

observeEvent(input$goToKEGG, {
browseURL(“http://www.genome.jp/kegg/catalog/org_list.html")
})
GSEA_result <- reactive({
if (is.null(data()) || is.null(gene())) {
return(NULL)
}
info <- data()
names(info) <- c(‘SYMBOL’, ‘Log2FoldChange’, ‘pvalue’, ‘padj’)
info_merge <- merge(info, gene(), by = ‘SYMBOL’)
GSEA_input <- info_merge$Log2FoldChange
names(GSEA_input) <- info_merge$ENTREZID
sort_input <- sort(GSEA_input, decreasing = TRUE)
sort_input_df <- data.frame(‘GENE’ = names(sort_input), ‘logFC’ = sort_input)
gseKEGG(sort_input_df, organism = str_to_lower(input$kegg_species),
pvalueCutoff = 0.05, qvalueCutoff = 0.05)
})

output$GO_barplot <- renderPlot({
if (!is.null(GO_result())) {
barplot(GO_result(), split=”ONTOLOGY”) + facet_grid(ONTOLOGY~., scale = “free”)
}
})

output$GO_dotplot <- renderPlot({
if (!is.null(GO_result())) {
dotplot(GO_result(), split=”ONTOLOGY”) + facet_grid(ONTOLOGY~., scale = “free”)
}
})

output$GO_cnetplot <- renderPlot({
if (!is.null(GO_result())) {
enrichplot::cnetplot(GO_result(), circular=FALSE, colorEdge = TRUE)
}
})
output$GO_heatplot <- renderPlot({
if (!is.null(GO_result())) {
enrichplot::heatplot(GO_result(), showCategory = 50)
}
})

output$GO_emapplot <- renderPlot({
if (!is.null(GO_result())) {
GO2 <- pairwise_termsim(GO_result())
enrichplot::emapplot(GO2, showCategory = 50, color = “p.adjust”, layout = “kk”)
}
})

output$KEGG_barplot <- renderPlot({
if (!is.null(KEGG_result())) {
barplot(KEGG_result(), showCategory = 40, title = ‘KEGG Pathway’)
}
})

output$KEGG_dotplot <- renderPlot({
if (!is.null(KEGG_result())) {
dotplot(KEGG_result())
}
})

output$KEGG_cnetplot <- renderPlot({
if (!is.null(KEGG_result())) {
enrichplot::cnetplot(KEGG_result(), circular=FALSE, colorEdge = TRUE)
}
})

output$KEGG_plot <- renderPlot({
if (!is.null(KEGG_result())) {
enrichplot::heatplot(KEGG_result(), showCategory = 20)
}
})

output$GSEA_plot <- renderPlot({
if (!is.null(GSEA_result())) {
gseaplot2(GSEA_result(), geneSetID = NULL)
}
})
}
shinyApp(ui = ui, server = server)
输入的 chicken_diffexp.xlsx 内容是这样的

下面是可能用到的一些文章链接
「鸽王之王」WGCNAshiny 使用说明
https://mp.weixin.qq.com/s?__biz=Mzg4MzUzODQwNw==&mid=2247483866&idx=1&sn=
f225cd45d960c378ddb2a3134775062f&chksm=cf44a152f8332844e6cc46d4a82bf0d25bfd1
4a65061835776571f9215d565f04d6c26b4fe39&mpshare=1&scene=24&srcid=0202dXKmZ
m3943AZjWmU8PNC&sharer_sharetime=1675304714454&sharer_shareid=f156b9c8fdc542
52e8f24b8ce5ac7c2f&ascene=14&devicetype=android33&version=2800205d&nettype=ctnet&abtest_cookie=AAACAA%3D%3D&lang=zh_CN&exp
ortkey=n_ChQIAhIQhm9yXRH0LXErvRO6tdTo4RLvAQIE97dBBAEAAAAAALMpBgrtOW8AAA
AOpnltbLcz9gKNyK89dVj0AyDUPpdznNWWI2tjGwPrGszXm3XzmLeEyPBmpigA0ELgcUDjZD
paz4eJKu9ccXdoCVM5epJvVD3zNMNZgIZT%2B0kqmYcwTkTuyVhuwnPXR8m6lnV7Pxh8aOL
y3P%2FK8y63Y3jnnUgtsEoG72nar2%2Fw4pPsVRtnFyjpfZd8b2upnwV7WwCAFFFxoanGck7r5w
7DNYrdfYZb7WeVqhRV9dgqGc1jkWcz4ZOzWygm6dXocNOua%2B0vD6mRK7AI3lMhtsXhpf
%2BdVTr7RKb2&pass_ticket=8bfpEUcbFWUXprpkvTW%2FemTR3RsXWKF7AZ76FlMGXQs3G
QVPxETdW9GIOwcQgYj0g8sswsyBqCeOVTBvqQfolQ%3D%3D&wx_header=3
TBtools | 零基础掌握 WGCNA 共表达网络分析 - 「WGCNAshiny by Warlock」
https://mp.weixin.qq.com/s?search_click_id=6226812296170952204-1682671532838-
1908149389&__biz=MzIwNjI0Njc1NQ==&mid=2651135199&idx=1&sn=52c4119d8b18dab
7beaea079caa55f5e&chksm=8cd53ad3bba2b3c5f642d4c88138bb1986082e67e5492bd68f8
c99ea86f43142c3722e8b75b2&scene=0&subscene=10000&clicktime=1682671532&enterid
=1682671532&sessionid=0&ascene=65&fasttmpl_type=0&fasttmpl_fullversion=6656088-
zh_CN-zip&fasttmpl_flag=0&realreporttime=1682671532884#rd
TBtools | 零基础掌握 WGCNA 共表达网络分析 - 「WGCNAshiny by Warlock」
详细的介绍可以网上找 shiny 的配套视频,这里有推荐的视

text

设置CRAN镜像源

options(“repos” = c(CRAN=”https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))

检查并安装shiny包

if (!require(‘shiny’, quietly = TRUE)) {
install.packages(‘shiny’)
}

检查并安装lattice包

if (!require(‘lattice’, quietly = TRUE)) {
install.packages(‘lattice’)
}

检查并安装BiocManager,用于安装Bioconductor包

if (!require(“BiocManager”, quietly = TRUE)) {
install.packages(“BiocManager”)
}

使用BiocManager安装rain包(假设rain是Bioconductor包)

if (!require(“rain”, quietly = TRUE)) {
BiocManager::install(“rain”)
}

检查并安装DT包

if (!require(‘DT’, quietly = TRUE)) {
install.packages(‘DT’)
}

加载库

library(shiny)
library(lattice)
library(rain)
library(DT)

参考上面这个把下面的哪些也变成这样的形式


文章作者: 花粱
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 花粱 !
  目录