[英]How to make a scatterplot showing correlation between a single gene vs multiple genes?
[英]how to calculate the correlation between one gene and the other genes
我想找到一個基因與其他基因的相關性。 最后我會把這個 function 放入 shiny 中。
我的意思是當我 select 輸入一個基因時,我可以得到與這個密切相關的其他多少基因。 並且這些相關基因可以在主面板中 output 甚至可以作為文本或 excel 文件下載。
原諒我不恰當的表達,因為我是新手。
我的樣本 FPKM 基因計數如下:
## library(shiny)
## library(dplyr)
## library(tidyr)
## library(ggplot2)
###
mean_data <- data.frame(
Name = c(paste0("Gene_", LETTERS[1:20])),
matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
)
names(mean_data)[-1] <- c(paste0("Sample_", 1:50))
rownames(mean_data)<-mean_data[,1]
mean_data<-mean_data[,-1]
## I don't know the code below is right or not . But I wanna the correlation between the input one and the others
corResult=apply(mean_data,1,function(x){
cor(x[1:25],x[26:50],method="spearman")
})
hist(corResult)
corResult_test=apply(mean_data,1,function(x){
cor.test(x[1:25],x[26:50],method="spearman",exact = F)$p.value
})
table(abs(corResult)>0.65 & corResult_test<0.05)
有人可以幫助我嗎? 給我一個合適的方法。
感激不盡。
查看來自psych
corr.test
的 corr.test; 那應該做你想做的事:
library(psych)
set.seed(7)
mean_data <- data.frame(
Name = c(paste0("Gene_", LETTERS[1:20])),
matx <- matrix(sample(1:1000, 1000, replace = T), nrow = 20)
)
names(mean_data)[-1] <- c(paste0("Sample_", 1:50))
rownames(mean_data) <- mean_data[,1]
mean_data <- mean_data[,-1]
myCor <- function(x="Gene_A", mat=mean_data, pval=.05, R=.65, method="spearman"){
tm <- corr.test(t(mat[x,,drop=FALSE]),
y = t(mat), use = "pairwise", method=method, adjust="holm",
alpha=pval, ci=TRUE, minlength=5)
res <- setdiff(colnames(tm$r)[which(with(tm, abs(r) > R & p < pval))], x)
if(length(res) > 0) res
}
res <- sapply(rownames(mean_data), myCor, pval=.1, R=.3)
res[lengths(res) > 0]
#> $Gene_A
#> [1] "Gene_K"
#>
#> $Gene_H
#> [1] "Gene_K"
#>
#> $Gene_K
#> [1] "Gene_A" "Gene_H"
由代表 package (v1.0.0) 於 2021 年 2 月 3 日創建
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.