GEO - 神经网络分析-ANN
01. 准备文件

id GSM3587381_con GSM3587382_con GSM3587383_con GSM3587384_con GSM3587385_con GSM3587386_con GSM3587387_con GSM3587388_con GSM3587389_con GSM3587390_con GSM3587391_con GSM3587392_con GSM3587393_con GSM3587394_con GSM3587395_con GSM3587396_con GSM3587397_treat GSM3587398_treat GSM3587399_treat GSM3587400_treat GSM3587401_treat GSM3587402_treat GSM3587403_treat GSM3587404_treat GSM3587405_treat GSM3587406_treat GSM3587407_treat GSM3587408_treat GSM3587409_treat GSM3587410_treat GSM3587411_treat GSM3587412_treat
AQP4 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1
AEBP1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1
PRRX1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 1
IGF1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
GAS1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1
COL1A1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
COL3A1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1
HTRA1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
LRRC15 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1
HSPG2 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 1 1 1 1 1
library(neuralnet)
library(NeuralNetTools)
set.seed(12345678)inputFile="geneScore.txt"
setwd("/Users/wangyang/Desktop/BCBM/03geneScore")
data=read.table(inputFile, header=T, sep="\t", check.names=F, row.names=1)
data=as.data.frame(t(data))
group=gsub("(.*)\\_(.*)", "\\2", row.names(data))
data$con=ifelse(group=="con", 1, 0)
data$treat=ifelse(group=="treat", 1, 0)
fit=neuralnet(con+treat~., data, hidden=15)
fit$result.matrix
fit$weight
pdf(file="neuralnet.pdf", width=15, height=20)
plotnet(fit)
dev.off()
net.predict=compute(fit, data)$net.result
net.prediction=c("con", "treat")[apply(net.predict, 1, which.max)]
predict.table=table(group, net.prediction)
predict.table
conAccuracy=predict.table[1,1]/(predict.table[1,1]+predict.table[1,2])
treatAccuracy=predict.table[2,2]/(predict.table[2,1]+predict.table[2,2])
paste0("Con accuracy: ", sprintf("%.3f", conAccuracy))
paste0("Treat accuracy: ", sprintf("%.3f", treatAccuracy))
colnames(net.predict)=c("con", "treat")
outTab=rbind(id=colnames(net.predict), net.predict)
write.table(outTab, file="neural.predict.txt", sep="\t", quote=F, col.names=F)
