1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| # Script qui contient l'accès à la base de données ath_exp pour différentes gènes et différentes options (tissue...) mais aussi different choix de datasets :
# Création du heatmap et de la matrice de corrélation pour un gène contre tout les autres gènes :
#R CMD BATCH --no-save --no-restore '--args gene_list=c("At3g21770","At5g12250") dataset=\"Seed_Serie\" tissue=c("seed","embryo")' test_rcmd.r test_rcmd.out &
library(RMySQL)
args=(commandArgs(TRUE))
# pour récuperer les arguments : options[1], options[2] etc
if(length(args)==0){
print("No arguments supplied.")
##supply default values
dataset = c(1,2)
#~ tissue = c(1,1,1)
gene_list=c(1,1)
}else{
for(i in 1:length(args)){
eval(parse(text=args[[i]]))
}
}
print(gene_list)
print(dataset)
#~ print(tissue)
con <- dbConnect(MySQL(), user="root", password="n337042m", dbname="mydb", host="localhost")
i=0;
for (gene in gene_list) {
query= dbSendQuery(con, paste ("SELECT distinctrow P.SAMPLE_SUFFIX, P.MEAN_REP as ",gene," FROM ",dataset," D, Processed_Data_Table P, Summary_Tables S WHERE S.NAME_TABLE = '",dataset,"' AND S.ID_TABLE = P.ID_TABLE AND D.IDGENE_AT LIKE '%",gene,"%' AND P.ID_MEAN_REP = D.ID_MEAN_REP ORDER BY P.SAMPLE_SUFFIX",sep=""))
dbGetStatement(query) # pour afficher la requête
exp_data <- fetch(query, n = -1) # -1 pour avoir toutes les lignes sinon limité à 500
dbClearResult(query);
#write.table(exp_data, file=gene, sep= "\t")
if (i==0) {
list_data = assign(paste("exp_data_", gene, sep=""),exp_data)
}
else {
# génération de variables pour chaque sortie de requête
gene_data = assign(paste("exp_data_", gene, sep=""),exp_data)
list_data = merge(list_data, gene_data)
}
i=i+1;
}
class(list_data)
list_data=data.frame(list_data, row.names=1)
# Calcul de la matrice de distance de corrélation :
corrdist =function(x) as.dist(1-cor(t(x)))
#~ source("http://bioconductor.org/biocLite.R")
#~ biocLite("NMF")
library("NMF")
#~ setwd("~/Documents/Stage_M2/R/Heatmap/Annotations")
annot = as.data.frame(t(read.table("./Annotations/Seed_Serie_annotation.txt", header=TRUE, sep="\t",row.names=1, comment.char="")))
ann_color=list(category=c(1:20), age=c(1:10), tissue=c(1:10), control=c(1:2), mutant=c(1:20), timecourse=c(1:20));
png("test_heatmap.png", width=1000, height=1000)
aheatmap(t(data.matrix(list_data)), annCol=annot, distfun =corrdist , hclustfun='ward', verbose = TRUE, Colv=NA, annColors=ann_color)
dev.off(); |
Partager