我正在尝试比较所有具有基因突变的患者与所有没有突变的患者的生存率。 我有一个包含 66 个数据框的列表,用于不同癌症类型的不同批次患者,我想隔离具有突变的患者并将它们与所有其他患者进行比较。
这是数据框的例子
A tibble:6 × 36
TCGA-OR-A5J1-01 3 42265106 42265106 C-T TCGA-OR-A5J1 1 1355
TCGA-OR-A5J2-01 X 39913284 39913284 C-A TCGA-OR-A5J2 1 1677
TCGA-OR-A5J3-01 17 10608472 10608472 G-A TCGA-OR-A5J3 0 2091
TCGA-OR-A5J3-01 17 10608472 10608472 G-A TCGA-OR-A5J3 0 2091
TCGA-OR-A5J4-01 5 38427121 38427121 G-C TCGA-OR-A5J4 1 423
TCGA-OR-A5J4-01 11 66272099 66272099 G-A TCGA-OR-A5J4 1 423
6 rows | 1-10, 33-36 of 36 columns
我想得到log rank test 并把它放在一个带有癌症类型和基因名称标题的pdf中
这是我正在运行的代码,但它一直说“错误:找不到 df1_OS”
survdif_KM = function(x, y) {
#x is the name of your data.frame (cancer type)
#y is you gene id you're interested in
read_file = paste0("C:/Users/cian/OneDrive/Desktop/Thesis/mergerd_data", "/", x)
df <- read.table(read_file, sep = "\t", header=T)
df2 <- df[grep(y, df[[14]]),]
df3 <- df[!grepl(y, df[[14]]),]
if (nrow(df2) > 20)
{
df4 <- df2[df2$X_PATIENT %in% df3$X_PATIENT, ]
if(nrow(df4) > 0)
{
df3_1 <- df3[!df3$V5 %in% df2$V5, ]
df3 <- df3_1
}
df2$group <- "A"
df3$group <- "B"
df1_OS <- rbind(df2,df3)
x = gsub("\\..*", "", x)
name_of_file = paste("Log-Rank", "Test", x, y, sep="_")
surv_diff <- survdiff(Surv(OS.time, OS) ~ group, data = df1_OS)
pval_sav <- surv_pvalue(surv_diff)
if (pval_sav$pval >= 0.05)
{
filename= paste0('C:/Users/cian/OneDrive/Desktop/Thesis/tables/', name_of_file, ".pdf", sep="")
pdf(filename)
a <- surv_diff
print(a)
dev.off()
}}}
这是一个 x 和 y 的例子,其中 x 是数据框的名称,Y 是基因
x = "UCEC_TCGA_ms.txt"
y = "ENSG00000240498"
我正在使用 mapply 在所有数据帧和基因的交叉列表上运行循环。
我已经使用 survfit 函数完成了一个非常相似的函数来获得 kaplan-meier 曲线,但是在我将 survfit 函数更改为 surv_fit 之前它也不起作用。我用 survdiff 试过了,但没有用。
是否有另一种类型的 survdiff 我可以像在 survfit 中那样使用,它会遍历数据帧列表?
带有 survfit 的示例附在下面以供参考,作为一个有效的函数
new_create_KM = function(x, y) {
#x is the name of your data.frame (cancer type)
#y is you gene id you're interested in
read_file = paste0("C:/Users/cian/OneDrive/Desktop/Thesis/mergerd_data", "/", x)
df <- read.table(read_file, sep = "\t", header=T)
df2 <- df[grep(y, df[[14]]),]
df3 <- df[!grepl(y, df[[14]]),]
if (nrow(df2) > 150)
{
df4 <- df2[df2$X_PATIENT %in% df3$X_PATIENT, ]
if(nrow(df4) > 0)
{
df3_1 <- df3[!df3$V5 %in% df2$V5, ]
df3 <- df3_1
}
df2$group <- "A"
df3$group <- "B"
df1_OS <- rbind(df2,df3)
x = gsub("\\..*", "", x)
name_of_file = paste("KM", "Curve", x, y, sep="_")
survival_function <- surv_fit(Surv(df1_OS$OS.time, df1_OS$OS)~group, data=df1_OS)
pval_sav <- surv_pvalue(survival_function)
if (pval_sav$pval <= 0.05)
{
filename= paste0('C:/Users/cian/OneDrive/Desktop/Thesis/Graphs2/', name_of_file, ".pdf", sep="")
# I changed destination to graphs 2 so I could use the new all_genes
pdf(filename)
a <- ggsurvplot(survival_function, conf.int=TRUE, pval=TRUE, risk.table=TRUE,
legend.labs=c("mutation", "no mutation"), legend.title="lncRNA status",
palette=c("orangered1", "royalblue"), title=name_of_file)
print(a)
dev.off()
}}}
谢谢你的帮助。