利用RNAseq数据做聚类分析

library(ConsensusClusterPlus)
library(factoextra)
library(cluster)
library(NbClust)
# 读入数据
data = read.table("T_405_ex.txt",header = T, row.names = 1)
b = matrix(data, nrow = 1, ncol = 1)
new<-as.matrix(t(data))
is.matrix(new)

#标准化

my_data <- na.omit(new)
my_data <- scale(my_data)
head(my_data, n = 3)

get_clust_tendency(my_data, n = 50,gradient = list(low = "steelblue",  high = "white"))

#n:the number of points selected from sample space which is also the number of points selected from the given sample(data).(不能大于样本个数)

$hopkins_stat
[1] 0.2837771

# If the value of Hopkins statistic is close to zero (far below 0.5), then we can conclude that the dataset is significantly clusterable.(本次结果小于0.5,证明样本之间有一定的聚类特性。)

$plot

#选择最好的分类K

library("NbClust")
res.nbclust <- NbClust(my_data, distance = "euclidean", min.nc = 2, max.nc = 10,  method = "complete", index ="all")

 

 

 

*** : The Hubert index is a graphical method of determining the number of clusters.
In the plot of Hubert index, we seek a significant knee that corresponds to a
significant increase of the value of the measure i.e the significant peak in Hubert
index second differences plot.

*** : The D index is a graphical method of determining the number of clusters.
In the plot of D index, we seek a significant knee (the significant peak in Dindex
second differences plot) that corresponds to a significant increase of the value of
the measure.

*******************************************************************
* Among all indices:
* 11 proposed 2 as the best number of clusters
* 5 proposed 3 as the best number of clusters
* 3 proposed 4 as the best number of clusters
* 4 proposed 6 as the best number of clusters

***** Conclusion *****

* According to the majority rule, the best number of clusters is 2

#样本聚类
factoextra::fviz_nbclust(res.nbclust) + theme_minimal()

res.hc <- eclust(my_data, "hclust", k = 2, graph = FALSE)
fviz_dend(res.hc, rect = TRUE, show_labels = FALSE)

 


fviz_silhouette(res.hc)

 


res.hc

#计算标签基因

library(pamr)
stad.data <- pamr.from.excel("k2_ex.txt", 417, sample.labels=TRUE)
#如果有缺失值
stad.data2 <- pamr.knnimpute(stad.data)

model <- pamr.train(stad.data2)
model
#You get a table with 3 columns and 30 rows.
#The rows correspond to threshold values (first column).
#For each threshold you see the number of surviving genes (second column)
#and the number of misclassifications on the training set (third column).


#验证
model.cv <- pamr.cv(model, stad.data2, nfold = 10)
model.cv
pamr.plotcv(model.cv)
#Using the results of cross validation, choose a threshold value Delta as a tradeoff
#between a small number of genes and a good generalization accuracy.

 


Delta = 11
pamr.plotcen(model, stad.data2, Delta)

 

 

dev.print(file = "MYcentroids_k2.ps")
dev.print(device = pdf, file = "MYcentroids_k2.pdf")
#The next function prints a 2 × 2 confusion table,
#which tells us how many samples in each class were predicted correctly.
pamr.confusion(model.cv, Delta)
#To get a visual impression of how clearly the two classes are separated by PAM
pamr.plotcvprob(model, stad.data2, Delta)

 


#The following command plots for each gene surviving the threshold a figure showing the expression levels of this gene over the whole set of samples.
#You will see which genes are up- or downregulated and how variable they are.
pamr.geneplot(model, stad.data2, Delta)

#导出标签基因

result <- pamr.listgenes(model, stad.data2, Delta, genenames = TRUE)
write.table(result,file="k2_result_gene.txt")

 

转载于:https://www.cnblogs.com/qiniqnyang/p/5884018.html

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值