11 args = commandArgs(trailingOnly = TRUE)
14 pheno <- read.table(args[1], sep = "\t", header = TRUE)
15 study_trait <- args[2]
16 cat("Study trait is ", study_trait[1])
17 figure1_file_name <- args[3]
18 figure2_file_name <- args[4]
22 #Making names standard
23 names <- colnames(pheno)
24 new_names <- gsub(".CO.*","", names)
25 colnames(pheno) <- new_names
26 cat(colnames(pheno),"\n")
28 #Finding which column is the study trait
29 for (i in 1:ncol(pheno)){
30 a = noquote(colnames(pheno[i]))
32 cat("COL: ", a, " vs study_trait: ", b,"\n")
39 cat("working ",i,"\n")
44 env <-as.factor(pheno$locationName)
45 gen <-as.factor(pheno$germplasmName)
46 rep <-as.factor(pheno$replicate)
47 # trait <-as.numeric(pheno[,col])
49 message<-"The analysis could not be completed. Please set your dataset with more than 1 location."
51 locations <- unique(pheno$locationDbId)
52 acc <- unique(pheno$germplasmDbId)
53 subGen <- unique(subset(pheno, select=c(germplasmDbId, germplasmName)))
56 if (! length(locations)>1){
58 png(AMMIFile, height = 130, width=800)
63 sub1 <- unique(subset(pheno, locationDbId == locations[1], select=c(locationDbId, locationName)))
64 png(figure1_file_name, height = 100, width=800)
69 acc <- unique(pheno$germplasmDbId)
70 png(figure2_file_name, height = (21*length(acc)), width = 800)
71 sub2 <- unique(subset(pheno, locationDbId == locations[1], select=c(germplasmDbId, germplasmName)))
76 cat("Starting stability analysis...","\n")
79 cat("create model", "\n")
84 model<- with(pheno,AMMI(env, gen, rep, pheno[,col], console=FALSE))
87 anova <-format(round(model$ANOVA, 3))
89 analysis <- model$analysis
95 cat("DONE WITH MODEL", "\n")
97 png(AMMIFile, height=130, width=800)
105 cat("running ammi", "\n")
107 png(figure1_file_name,height=400)
108 plot(model, first=0,second=1, number=TRUE, xlab = study_trait)
111 tam <- nrow(model$analysis)
113 png(figure2_file_name, height= 300)
114 plot(model, type=2, number=TRUE, xlab = study_trait)
117 png(figure2_file_name, height=5, width=5)
118 y <- tableGrob(message2)
123 }else if( method=="gge"){
124 dat1 <- pheno %>% select(germplasmName, locationName, trait=study_trait)
127 model1 <- gge(dat1, trait~germplasmName*locationName, scale=FALSE)
129 name1 = paste(study_trait,"- GGE Biplot", sep=" ")
131 png(figure1_file_name, height=400, width=500)
132 biplot(model1, main=name1, flip=c(1,0), origin=0, hull=TRUE)
135 model2 <- gge(dat1, trait~germplasmName*locationName, scale=TRUE)
136 png(figure2_file_name,height=400, width=500)
137 biplot(model2, main=name1, flip=c(1,1), origin=0)