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]))
37 cat("working ",i,"\n")
43 env <-as.factor(pheno$locationName)
44 gen <-as.factor(pheno$germplasmName)
45 rep <-as.factor(pheno$replicate)
46 # trait <-as.numeric(pheno[,col])
48 message<-"The analysis could not be completed. Please set your dataset with more than 1 location."
50 locations <- unique(pheno$locationDbId)
51 acc <- unique(pheno$germplasmDbId)
52 subGen <- unique(subset(pheno, select=c(germplasmDbId, germplasmName)))
54 if (! length(locations)>1){
56 png(AMMIFile, height = 130, width=800)
61 sub1 <- unique(subset(pheno, locationDbId == locations[1], select=c(locationDbId, locationName)))
62 png(figure1_file_name, height = 100, width=800)
67 acc <- unique(pheno$germplasmDbId)
68 png(figure2_file_name, height = (21*length(acc)), width = 800)
69 sub2 <- unique(subset(pheno, locationDbId == locations[1], select=c(germplasmDbId, germplasmName)))
74 cat("Starting stability analysis...","\n")
77 model<- with(pheno,AMMI(env, gen, rep, pheno[,col], console=FALSE))
79 anova <-format(round(model$ANOVA, 3))
80 analysis <- model$analysis
84 png(AMMIFile, height=130, width=800)
93 png(figure1_file_name,height=400)
94 plot(model, first=0,second=1, number=TRUE, xlab = study_trait)
97 tam <- nrow(model$analysis)
99 png(figure2_file_name, height= 300)
100 plot(model, type=2, number=TRUE, xlab = study_trait)
103 png(figure2_file_name, height=5, width=5)
104 y <- tableGrob(message2)
109 }else if( method=="gge"){
110 dat1 <- pheno %>% select(germplasmName, locationName, trait=study_trait)
113 model1 <- gge(dat1, trait~germplasmName*locationName, scale=FALSE)
115 name1 = paste(study_trait,"- GGE Biplot", sep=" ")
117 png(figure1_file_name, height=400, width=500)
118 biplot(model1, main=name1, flip=c(1,0), origin=0, hull=TRUE)
121 model2 <- gge(dat1, trait~germplasmName*locationName, scale=TRUE)
122 png(figure2_file_name,height=400, width=500)
123 biplot(model2, main=name1, flip=c(1,1), origin=0)