> > library(tidyverse) > library(maSigPro) > library(readr) > > setwd("D:/ANorth...
🚨 错误信息
>
> library(tidyverse)
> library(maSigPro)
> library(readr)
>
> setwd("D:/ANorth/muilt/呼吸多组学-陈宵/Analysis-lym/1.单组学分析/转录组/4时序分析")
> dir.create("maSigPro_results", showWarnings = FALSE)
>
> groups <- c("Control", "Low", "High")
>
> for (g in groups) {
+ cat("\n====== running", g, "======\n")
+
+ ## 1 读入并对齐 ------------------------------------------------------------
+ mat <- read_csv(str_c("geneMatrix_", g, "_normalized_log2cpm.csv")) %>%
+ column_to_rownames("symble") %>% as.matrix()
+ meta <- read_csv(str_c("meta_", g, ".csv")) %>% arrange(sample)
+ mat <- mat[, meta$sample] # 严格对齐列顺序
+
+ ## 2 design ≥2 列,replicate 为因子
+ design <- data.frame(
+ time = meta$time,
+ replicate = factor(meta$replicate)
+ )
+ rownames(design) <- meta$sample
+
+ ## 3 maSigPro 两步回归 -----------------------------------------------------
+ fit <- p.vector(mat, design, Q = 0.05, "gaussian") # 修正:直接传递 "gaussian"
+ tfit <- T.fit(fit,
+ step.method = "two.ways.backward",
+ alfa = 0.05,
+ adjust = "fdr") # 使用 fdr 校正
+ sig <- get.siggenes(tfit, rsq = 0.6)
+
+ ## 4 写出结果 --------------------------------------------------------------
+ prefix <- str_c("maSigPro_results/", g)
+
+ write_csv(sig$sig.genes %>% as_tibble(rownames = "gene"),
+ str_c(prefix, "_sig_genes.csv"))
+ write_csv(tfit$sig.models %>% as_tibble(rownames = "gene"),
+ str_c(prefix, "_coef.csv"))
+
+ ## 5 趋势图
+ pdf(str_c(prefix, "_trends.pdf"), width = 8, height = 5)
+ plot(tfit, name = g, clustering = TRUE)
+ dev.off()
+
+ ## 6 可选:持续上调/下调基因
+ coef <- tfit$sig.models
+ up <- rownames(coef)[coef$time > 0 & coef$time < 0.05 & is.na(coef$time2)]
+ down <- rownames(coef)[coef$time < 0 & coef$time < 0.05 & is.na(coef$time2)]
+ write_csv(tibble(gene = up), str_c(prefix, "_up_genes.csv"))
+ write_csv(tibble(gene = down), str_c(prefix, "_down_genes.csv"))
+ }
====== running Control ======
Rows: 13692 Columns: 13
── Column specification ──────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (1): symble
dbl (12): 6hC1, 6hC2, 6hC3, 24hC1, 24hC2, 24hC3, 72hC1, 72hC2, 72hC3, 120hC1, 120hC2, 120hC3
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Rows: 12 Columns: 4
── Column specification ──────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (2): sample, group
dbl (2): time, replicate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
[1] "fitting gene 100 out of 13692"
[1] "fitting gene 200 out of 13692"
[1] "fitting gene 300 out of 13692"
[1] "fitting gene 400 out of 13692"
[1] "fitting gene 500 out of 13692"
[1] "fitting gene 600 out of 13692"
[1] "fitting gene 700 out of 13692"
[1] "fitting gene 800 out of 13692"
[1] "fitting gene 900 out of 13692"
[1] "fitting gene 1000 out of 13692"
[1] "fitting gene 1100 out of 13692"
[1] "fitting gene 1200 out of 13692"
[1] "fitting gene 1300 out of 13692"
[1] "fitting gene 1400 out of 13692"
[1] "fitting gene 1500 out of 13692"
[1] "fitting gene 1600 out of 13692"
[1] "fitting gene 1700 out of 13692"
[1] "fitting gene 1800 out of 13692"
[1] "fitting gene 1900 out of 13692"
[1] "fitting gene 2000 out of 13692"
[1] "fitting gene 2100 out of 13692"
[1] "fitting gene 2200 out of 13692"
[1] "fitting gene 2300 out of 13692"
[1] "fitting gene 2400 out of 13692"
[1] "fitting gene 2500 out of 13692"
[1] "fitting gene 2600 out of 13692"
[1] "fitting gene 2700 out of 13692"
[1] "fitting gene 2800 out of 13692"
[1] "fitting gene 2900 out of 13692"
[1] "fitting gene 3000 out of 13692"
[1] "fitting gene 3100 out of 13692"
[1] "fitting gene 3200 out of 13692"
[1] "fitting gene 3300 out of 13692"
[1] "fitting gene 3400 out of 13692"
[1] "fitting gene 3500 out of 13692"
[1] "fitting gene 3600 out of 13692"
[1] "fitting gene 3700 out of 13692"
[1] "fitting gene 3800 out of 13692"
[1] "fitting gene 3900 out of 13692"
[1] "fitting gene 4000 out of 13692"
[1] "fitting gene 4100 out of 13692"
[1] "fitting gene 4200 out of 13692"
[1] "fitting gene 4300 out of 13692"
[1] "fitting gene 4400 out of 13692"
[1] "fitting gene 4500 out of 13692"
[1] "fitting gene 4600 out of 13692"
[1] "fitting gene 4700 out of 13692"
[1] "fitting gene 4800 out of 13692"
[1] "fitting gene 4900 out of 13692"
[1] "fitting gene 5000 out of 13692"
[1] "fitting gene 5100 out of 13692"
[1] "fitting gene 5200 out of 13692"
[1] "fitting gene 5300 out of 13692"
[1] "fitting gene 5400 out of 13692"
[1] "fitting gene 5500 out of 13692"
[1] "fitting gene 5600 out of 13692"
[1] "fitting gene 5700 out of 13692"
[1] "fitting gene 5800 out of 13692"
[1] "fitting gene 5900 out of 13692"
[1] "fitting gene 6000 out of 13692"
[1] "fitting gene 6100 out of 13692"
[1] "fitting gene 6200 out of 13692"
[1] "fitting gene 6300 out of 13692"
[1] "fitting gene 6400 out of 13692"
[1] "fitting gene 6500 out of 13692"
[1] "fitting gene 6600 out of 13692"
[1] "fitting gene 6700 out of 13692"
[1] "fitting gene 6800 out of 13692"
[1] "fitting gene 6900 out of 13692"
[1] "fitting gene 7000 out of 13692"
[1] "fitting gene 7100 out of 13692"
[1] "fitting gene 7200 out of 13692"
[1] "fitting gene 7300 out of 13692"
[1] "fitting gene 7400 out of 13692"
[1] "fitting gene 7500 out of 13692"
[1] "fitting gene 7600 out of 13692"
[1] "fitting gene 7700 out of 13692"
[1] "fitting gene 7800 out of 13692"
[1] "fitting gene 7900 out of 13692"
[1] "fitting gene 8000 out of 13692"
[1] "fitting gene 8100 out of 13692"
[1] "fitting gene 8200 out of 13692"
[1] "fitting gene 8300 out of 13692"
[1] "fitting gene 8400 out of 13692"
[1] "fitting gene 8500 out of 13692"
[1] "fitting gene 8600 out of 13692"
[1] "fitting gene 8700 out of 13692"
[1] "fitting gene 8800 out of 13692"
[1] "fitting gene 8900 out of 13692"
[1] "fitting gene 9000 out of 13692"
[1] "fitting gene 9100 out of 13692"
[1] "fitting gene 9200 out of 13692"
[1] "fitting gene 9300 out of 13692"
[1] "fitting gene 9400 out of 13692"
[1] "fitting gene 9500 out of 13692"
[1] "fitting gene 9600 out of 13692"
[1] "fitting gene 9700 out of 13692"
[1] "fitting gene 9800 out of 13692"
[1] "fitting gene 9900 out of 13692"
[1] "fitting gene 10000 out of 13692"
[1] "fitting gene 10100 out of 13692"
[1] "fitting gene 10200 out of 13692"
[1] "fitting gene 10300 out of 13692"
[1] "fitting gene 10400 out of 13692"
[1] "fitting gene 10500 out of 13692"
[1] "fitting gene 10600 out of 13692"
[1] "fitting gene 10700 out of 13692"
[1] "fitting gene 10800 out of 13692"
[1] "fitting gene 10900 out of 13692"
[1] "fitting gene 11000 out of 13692"
[1] "fitting gene 11100 out of 13692"
[1] "fitting gene 11200 out of 13692"
[1] "fitting gene 11300 out of 13692"
[1] "fitting gene 11400 out of 13692"
[1] "fitting gene 11500 out of 13692"
[1] "fitting gene 11600 out of 13692"
[1] "fitting gene 11700 out of 13692"
[1] "fitting gene 11800 out of 13692"
[1] "fitting gene 11900 out of 13692"
[1] "fitting gene 12000 out of 13692"
[1] "fitting gene 12100 out of 13692"
[1] "fitting gene 12200 out of 13692"
[1] "fitting gene 12300 out of 13692"
[1] "fitting gene 12400 out of 13692"
[1] "fitting gene 12500 out of 13692"
[1] "fitting gene 12600 out of 13692"
[1] "fitting gene 12700 out of 13692"
[1] "fitting gene 12800 out of 13692"
[1] "fitting gene 12900 out of 13692"
[1] "fitting gene 13000 out of 13692"
[1] "fitting gene 13100 out of 13692"
[1] "fitting gene 13200 out of 13692"
[1] "fitting gene 13300 out of 13692"
[1] "fitting gene 13400 out of 13692"
[1] "fitting gene 13500 out of 13692"
[1] "fitting gene 13600 out of 13692"
错误于match.arg(method):
'arg' should be one of “holm”, “hochberg”, “hommel”, “bonferroni”, “BH”, “BY”, “fdr”, “none”
🤖 AI解决方案
错误于match.arg(method):
'arg' should be one of “holm”, “hochberg”, “hommel”, “bonferroni”, “BH”, “BY”, “fdr”, “none”
Error in match.arg(method) :
'arg' should be one of “holm”, “hochberg”, “hommel”, “bonferroni”, “BH”, “BY”, “fdr”, “none”
1. 错误翻译
错误于match.arg(method): 'arg' 应该是 "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none" 中的一个。
2. 原因分析
T.fit 函数中的 adjust 参数接受的校正方法字符串不正确。您传递的是 "fdr",而函数期望的是 "BH"(Benjamini & Hochberg),这是 fdr 的常见实现。
3. 解决方案
将 T.fit 函数中 adjust 参数的值从 "fdr" 修改为 "BH"。
library(tidyverse)
library(maSigPro)
library(readr)
setwd("D:/ANorth/muilt/呼吸多组学-陈宵/Analysis-lym/1.单组学分析/转录组/4时序分析")
dir.create("maSigPro_results", showWarnings = FALSE)
groups <- c("Control", "Low", "High")
for (g in groups) {
cat("\n====== running", g, "======\n")
## 1 读入并对齐 ------------------------------------------------------------
mat <- read_csv(str_c("geneMatrix_", g, "_normalized_log2cpm.csv")) %>%
column_to_rownames("symble") %>% as.matrix()
meta <- read_csv(str_c("meta_", g, ".csv")) %>% arrange(sample)
mat <- mat[, meta$sample] # 严格对齐列顺序
## 2 design ≥2 列,replicate 为因子
design <- data.frame(
time = meta$time,
replicate = factor(meta$replicate)
)
rownames(design) <- meta$sample
## 3 maSigPro 两步回归 -----------------------------------------------------
fit <- p.vector(mat, design, Q = 0.05, "gaussian")
tfit <- T.fit(fit,
step.method = "two.ways.backward",
alfa = 0.05,
adjust = "BH") # 修正:使用 "BH" 代替 "fdr"
sig <- get.siggenes(tfit, rsq = 0.6)
## 4 写出结果 --------------------------------------------------------------
prefix <- str_c("maSigPro_results/", g)
write_csv(sig$sig.genes %>% as_tibble(rownames = "gene"),
str_c(prefix, "_sig_genes.csv"))
write_csv(tfit$sig.models %>% as_tibble(rownames = "gene"),
str_c(prefix, "_coef.csv"))
## 5 趋势图
pdf(str_c(prefix, "_trends.pdf"), width = 8, height = 5)
plot(tfit, name = g, clustering = TRUE)
dev.off()
## 6 可选:持续上调/下调基因
coef <- tfit$sig.models
up <- rownames(coef)[coef$time > 0 & coef$time < 0.05 & is.na(coef$time2)]
down <- rownames(coef)[coef$time < 0 & coef$time < 0.05 & is.na(coef$time2)]
write_csv(tibble(gene = up), str_c(prefix, "_up_genes.csv"))
write_csv(tibble(gene = down), str_c(prefix, "_down_genes.csv"))
}
4. 预防措施
- 查阅函数文档:在使用 R 包中的函数时,仔细阅读其帮助文档(通过
?function_name命令)以了解参数的有效值和预期格式。 - 使用已知的校正方法:
maSigPro包是基于limma等包的,了解常用的多重检验校正方法(如 "BH")并使用它们可以避免此类问题。