Skip to content
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ DSSBatch.v48
*.CDE
DSCSM048.CTR
GlueWarning.txt
GLWork/process.txt
GLWork/progress.txt
4 changes: 2 additions & 2 deletions BatchFileSetUp.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
BatchFileSetUp<-function(WD, OD, CultivarBatchFile)
{
eval(parse(text=paste('BatchFilePath="',WD,'/DSSBatch.template"',sep = '')));
BatchFileTamplate<-readLines(BatchFilePath, n=-1);
BatchFileTamplate<-suppressWarnings(readLines(BatchFilePath, n=-1));
#Get the template of the batch file.

eval(parse(text=paste('BatchFilePath="',OD,'/',CultivarBatchFile,'"', sep = '')));
CultivarBatchFile<-readLines(BatchFilePath, n=-1);
CultivarBatchFile<-suppressWarnings(readLines(BatchFilePath, n=-1));
TotalLineNumber<-length(CultivarBatchFile);
#Get the batch file generated with GenSelect.

Expand Down
334 changes: 325 additions & 9 deletions GLUE.r

Large diffs are not rendered by default.

294 changes: 150 additions & 144 deletions GenotypeChange.r
Original file line number Diff line number Diff line change
@@ -1,144 +1,150 @@
#Change the genotype file of crops in DSSAT.

GenotypeChange<-function(GD, DSSATD, OD, CropName, GenotypeFileName, CultivarID, TotalParameterNumber, RunNumber, RandomMatrix, EcotypeID, EcotypeParameters)
{
eval(parse(text=paste('GenotypeFilePath="',GD,'/',GenotypeFileName,'.CUL"',sep = '')));

ReadLine<-readLines(GenotypeFilePath, n=-1)
GenotypeFile<-as.character(ReadLine); #Get the genotype file saved as a template.

LineNumber<-grep(pattern=CultivarID, GenotypeFile); #Get the number of the line where the cultivar "GLUECUL" is located.
OldLine<-GenotypeFile[LineNumber];#Get the line according to the line number.

R<-RunNumber;#Get what parameter set will be used to change the genotype file.

#check if ecotype is also being calibrated
if(EcotypeParameters > 0){
eval(parse(text=paste('EcotypeFilePath="',GD,'/',GenotypeFileName,'.ECO"',sep = '')));

EcoReadLine<-readLines(EcotypeFilePath, n=-1)
EcotypeFile<-as.character(EcoReadLine); #Get the genotype file saved as a template.
EcoLineNumber<-grep(pattern=EcotypeID, EcotypeFile);
EcoOldLine<-EcotypeFile[EcoLineNumber];
}

# if (CropName != "SC")
# {
ParameterStep<-6;
ValuePosition1<-(38-ParameterStep);
ValuePosition2<-(42-ParameterStep);

EcoValuePosition1 <- (26-ParameterStep);
EcoValuePosition2 <- (30-ParameterStep);

for (i in 1:TotalParameterNumber)
{
ValuePosition1<-ValuePosition1+ParameterStep;
ValuePosition2<-ValuePosition2+ParameterStep;

eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));
#To solve the format problem for parameters with negative values. Modified by He, 2015-6-18.
if(Parameter < 0 & Parameter > -1.0) #
{ #
ParameterFormat<-sprintf('%1.3f', Parameter); #
ParameterFormat<-paste(substring(ParameterFormat,1,1), substring(ParameterFormat,3), sep=''); #
} else if (Parameter <= -1.0 & Parameter > -10.0) #
{ #
ParameterFormat<-sprintf('%2.2f', Parameter); #
} else if (Parameter <= -10.0 & Parameter > -100.0) #
{ #
ParameterFormat<-sprintf('%3.1f', Parameter); #
} #

if(Parameter >= 0 & Parameter < 10)
{
ParameterFormat<-sprintf('%1.3f', Parameter);
} else if (Parameter >= 10 & Parameter < 100)
{
ParameterFormat<-sprintf('%2.2f', Parameter);
} else if (Parameter >= 100)
{
ParameterFormat<-sprintf('%3.1f', Parameter);
}

if(EcotypeParameters > 0 & i > (TotalParameterNumber - EcotypeParameters)){ #Write on .ECO file
EcoValuePosition1 <- EcoValuePosition1+ParameterStep;
EcoValuePosition2 <- EcoValuePosition2+ParameterStep;
substr(EcoOldLine, EcoValuePosition1, EcoValuePosition2)<-ParameterFormat;
}else{ #Write on .CUL file
substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;
}
}
GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.

if(EcotypeParameters > 0){
EcotypeFile[EcoLineNumber]<-EcoOldLine;#Replace the old line with new generated line in the Ecotype file.
eval(parse(text=paste("NewEcotypeFilePath='",OD,"/",GenotypeFileName,".ECO'",sep = '')));
write(EcotypeFile, file=NewEcotypeFilePath);
#Save the new genotype file as "eco" file in the GLWork directory.
}

# } else
# {
# ParameterStep<-15;
#
# #chp modified
# ValuePosition1<-(47-ParameterStep); #The initial starting point was 42, but it was changed to 46 since "EXPNO" was added by Cheryl recently.
# ValuePosition2<-(61-ParameterStep); #The initial ending point was 47, but it is 51 now.
#
# for (i in 1:TotalParameterNumber)
# {
# ValuePosition1<-ValuePosition1+ParameterStep;
# ValuePosition2<-ValuePosition2+ParameterStep;
#
# eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));
#
# if(Parameter>=0 & Parameter<10)
# {
# ParameterFormat<-sprintf('%1.3f', Parameter);
# } else if (Parameter>=10 & Parameter<100)
# {
# ParameterFormat<-sprintf('%2.2f', Parameter);
#
# # chp added extra format statement for values between 100 and 1000
# } else if (Parameter>=100 & Parameter<1000)
# {
# ParameterFormat<-sprintf('%3.1f', Parameter);
# } else
#
# # chp - how to get format xxxx. (with nothing past the ".") ?
# {
# ParameterFormat<-sprintf('%4.0f', Parameter);
# }
#
# ##chp
# #print(ParameterFormat);
# #print (" ");
#
# substr(OldLine, ValuePosition1, ValuePosition2)<-' ';# Delete initial values.
# substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;
#
# }
#
# GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.
#
# eval(parse(text=paste('ECOFilePath="',GD,'/SCCAN048.ECO"',sep = '')));
# ReadLine<-readLines(ECOFilePath, n=-1)
# ECOFile<-as.character(ReadLine);
# #Get the ECO file from the Genotype directory.
#
# eval(parse(text=paste("NewECOFilePath='",OD,"/SCCAN048.ECO'",sep = '')));
# write(ECOFile, file=NewECOFilePath);
# #Save the ECO file in the GLWork directory.
# }

eval(parse(text=paste("NewGenotypeFilePath='",OD,"/",GenotypeFileName,".CUL'",sep = '')));
write(GenotypeFile, file=NewGenotypeFilePath);
#Save the new genotype file as "cul" file in the GLWork directory.

}





#Change the genotype file of crops in DSSAT.

GenotypeChange<-function(GD, DSSATD, OD, CropName, GenotypeFileName, CultivarID, TotalParameterNumber, RunNumber, RandomMatrix, EcotypeID, EcotypeParameters)
{
eval(parse(text=paste('GenotypeFilePath="',GD,'/',GenotypeFileName,'.CUL"',sep = '')));

EcoCROPGROformat <- 0
ReadLine<-readLines(GenotypeFilePath, n=-1)
GenotypeFile<-as.character(ReadLine); #Get the genotype file saved as a template.

LineNumber<-grep(pattern=CultivarID, GenotypeFile); #Get the number of the line where the cultivar "GLUECUL" is located.
OldLine<-GenotypeFile[LineNumber];#Get the line according to the line number.

R<-RunNumber;#Get what parameter set will be used to change the genotype file.

#check if ecotype is also being calibrated
if(EcotypeParameters > 0){
eval(parse(text=paste('EcotypeFilePath="',GD,'/',GenotypeFileName,'.ECO"',sep = '')));

EcoReadLine<-readLines(EcotypeFilePath, n=-1)
EcotypeFile<-as.character(EcoReadLine); #Get the genotype file saved as a template.
EcoLineNumber<-grep(pattern=EcotypeID, EcotypeFile);
EcoOldLine<-EcotypeFile[EcoLineNumber];
EcoCROPGROformat <- grep(pattern="MG TM", EcotypeFile);
}

# if (CropName != "SC")
# {
ParameterStep<-6;
ValuePosition1<-(38-ParameterStep);
ValuePosition2<-(42-ParameterStep);

if(length(EcoCROPGROformat) > 0){
EcoValuePosition1 <- (32-ParameterStep);
EcoValuePosition2 <- (36-ParameterStep);
}else{
EcoValuePosition1 <- (26-ParameterStep);
EcoValuePosition2 <- (30-ParameterStep);
}
for (i in 1:TotalParameterNumber)
{
ValuePosition1<-ValuePosition1+ParameterStep;
ValuePosition2<-ValuePosition2+ParameterStep;

eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));
#To solve the format problem for parameters with negative values. Modified by He, 2015-6-18.
if(Parameter < 0 & Parameter > -1.0) #
{ #
ParameterFormat<-sprintf('%1.3f', Parameter); #
ParameterFormat<-paste(substring(ParameterFormat,1,1), substring(ParameterFormat,3), sep=''); #
} else if (Parameter <= -1.0 & Parameter > -10.0) #
{ #
ParameterFormat<-sprintf('%2.2f', Parameter); #
} else if (Parameter <= -10.0 & Parameter > -100.0) #
{ #
ParameterFormat<-sprintf('%3.1f', Parameter); #
} #

if(Parameter >= 0 & Parameter < 10)
{
ParameterFormat<-sprintf('%1.3f', Parameter);
} else if (Parameter >= 10 & Parameter < 100)
{
ParameterFormat<-sprintf('%2.2f', Parameter);
} else if (Parameter >= 100)
{
ParameterFormat<-sprintf('%3.1f', Parameter);
}

if(EcotypeParameters > 0 & i > (TotalParameterNumber - EcotypeParameters)){ #Write on .ECO file
EcoValuePosition1 <- EcoValuePosition1+ParameterStep;
EcoValuePosition2 <- EcoValuePosition2+ParameterStep;
substr(EcoOldLine, EcoValuePosition1, EcoValuePosition2)<-ParameterFormat;
}else{ #Write on .CUL file
substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;
}
}
GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.

if(EcotypeParameters > 0){
EcotypeFile[EcoLineNumber]<-EcoOldLine;#Replace the old line with new generated line in the Ecotype file.
eval(parse(text=paste("NewEcotypeFilePath='",OD,"/",GenotypeFileName,".ECO'",sep = '')));
write(EcotypeFile, file=NewEcotypeFilePath);
#Save the new genotype file as "eco" file in the GLWork directory.
}

# } else
# {
# ParameterStep<-15;
#
# #chp modified
# ValuePosition1<-(47-ParameterStep); #The initial starting point was 42, but it was changed to 46 since "EXPNO" was added by Cheryl recently.
# ValuePosition2<-(61-ParameterStep); #The initial ending point was 47, but it is 51 now.
#
# for (i in 1:TotalParameterNumber)
# {
# ValuePosition1<-ValuePosition1+ParameterStep;
# ValuePosition2<-ValuePosition2+ParameterStep;
#
# eval(parse(text = paste("Parameter<-RandomMatrix[R,",i,"]",sep = '')));
#
# if(Parameter>=0 & Parameter<10)
# {
# ParameterFormat<-sprintf('%1.3f', Parameter);
# } else if (Parameter>=10 & Parameter<100)
# {
# ParameterFormat<-sprintf('%2.2f', Parameter);
#
# # chp added extra format statement for values between 100 and 1000
# } else if (Parameter>=100 & Parameter<1000)
# {
# ParameterFormat<-sprintf('%3.1f', Parameter);
# } else
#
# # chp - how to get format xxxx. (with nothing past the ".") ?
# {
# ParameterFormat<-sprintf('%4.0f', Parameter);
# }
#
# ##chp
# #print(ParameterFormat);
# #print (" ");
#
# substr(OldLine, ValuePosition1, ValuePosition2)<-' ';# Delete initial values.
# substr(OldLine, ValuePosition1, ValuePosition2)<-ParameterFormat;
#
# }
#
# GenotypeFile[LineNumber]<-OldLine;#Replace the old line with new generated line in the Genotype file.
#
# eval(parse(text=paste('ECOFilePath="',GD,'/SCCAN048.ECO"',sep = '')));
# ReadLine<-readLines(ECOFilePath, n=-1)
# ECOFile<-as.character(ReadLine);
# #Get the ECO file from the Genotype directory.
#
# eval(parse(text=paste("NewECOFilePath='",OD,"/SCCAN048.ECO'",sep = '')));
# write(ECOFile, file=NewECOFilePath);
# #Save the ECO file in the GLWork directory.
# }
#print(OldLine)
eval(parse(text=paste("NewGenotypeFilePath='",OD,"/",GenotypeFileName,".CUL'",sep = '')));
write(GenotypeFile, file=NewGenotypeFilePath);
#Save the new genotype file as "cul" file in the GLWork directory.

}





4 changes: 2 additions & 2 deletions IntegratedLikelihoodCalculation1.r
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RunNumber<-(Dimension[1]/TreatmentNumber); ##Get the number of model runs.
## Step 2. Get the information about measurement variance from a given Excel file.
#library(xlsReadWrite);

if (CropName=="PT" || CropName=="SC" || CropName=="CS" || CropName=="TN" || CropName=="TR" || CropName=="WH" || CropName=="PI")
if (CropName=="PT" || CropName=="SC" || CropName=="CS" || CropName=="TN" || CropName=="TR" || CropName=="WH" || CropName=="PI" || CropName=="RY")
{
# eval(parse(text=paste('VAR<-read.xls("',WD,
# '/MeasurementVariance.xls", sheet = "',CropName,'", rowNames = T, colNames=T)',sep = '')));
Expand Down Expand Up @@ -62,7 +62,7 @@ RowNames<-rownames(VAR);

NumberOfMeasurement<-dim(VAR)[1];

if (CropName=="BA" || CropName=="RI" || CropName=="WH" || CropName=="TF")
if (CropName=="BA" || CropName=="RI" || CropName=="WH" || CropName=="TF" || CropName=="RY")
{
VAR["PD1T","Flag"]<-0;
VAR["PWAM","Flag"]<-0;
Expand Down
4 changes: 2 additions & 2 deletions IntegratedLikelihoodCalculation2.r
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RunNumber<-(Dimension[1]/TreatmentNumber); ##Get the number of model runs.
## Step 2. Get the information about measurement variance from a given Excel file.
#library(xlsReadWrite);

if (CropName=="PT" || CropName=="SC" || CropName=="CS" || CropName=="TN" || CropName=="TR" || CropName=="WH" || CropName=="PI" )
if (CropName=="PT" || CropName=="SC" || CropName=="CS" || CropName=="TN" || CropName=="TR" || CropName=="WH" || CropName=="PI" || CropName=="RY")
{
# eval(parse(text=paste('VAR<-read.xls("',WD,
# '/MeasurementVariance.xls", sheet = "',CropName,'", rowNames = T, colNames=T)',sep = '')));
Expand Down Expand Up @@ -63,7 +63,7 @@ RowNames<-rownames(VAR);

NumberOfMeasurement<-dim(VAR)[1];

if (CropName=="BA" || CropName=="RI" || CropName=="WH" || CropName=="TF")
if (CropName=="BA" || CropName=="RI" || CropName=="WH" || CropName=="TF" || CropName=="RY")
{
VAR["PD1T","Flag"]<-0;
VAR["PWAM","Flag"]<-0;
Expand Down
10 changes: 10 additions & 0 deletions MeasurementVariance_RY.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
,STD,Variance,CV,Flag,Description
EDAP,3,9,,1,Emergence day (dap).
ADAP,3,9,,1,Anthesis day (dap).
MDAP,7,49,,1,Physiological maturity day (dap).
PD1T,4,16,,1,First pod date (YrDoy).
HWAM,,,0.3,2,Yield at harvest maturity (kg [dm]/ha).
CWAM,,,0.3,2,Tops weight at maturity (kg [dm]/ha).
LAIX,,,0.4,2,"Leaf area index, maximum."
HWUM,,,0.1,2,Grain unit weight at maturity (g/seed)
L.SM,3,9,,2,"Leaf number per stem at maturity. The symbol ""#"" was changed to ""."", since it is the symbol of comments in R."
2 changes: 1 addition & 1 deletion ModelRun.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pbapply_custom <- function (X, FUN, ..., cl = NULL)
rval[i] <- list(PAR_FUN(cl, X[Split[[i]]], FUN,
...))
setpb(pb, i)
write.table(i/B*100,file = paste0(OD,'process.txt'), row.names = FALSE, col.names = FALSE)
write.table(i/B*100,file = paste0(OD,'progress.txt'), row.names = FALSE, col.names = FALSE)
}
}
else if (identical(cl, "future")) {
Expand Down
Loading