new Switch ("multiplex", JSAP.NO_SHORTFLAG, "multiplex", "Analyze each of the multiple datasests given in the input file using all the selection parameters specified."),
new Switch ("condOnLastSegregating", JSAP.NO_SHORTFLAG, "condOnLastSegregating", "When set, condition on the last sample being segregating."),
}
);
JSAPResult config = jsap.parse(args);
if (jsap.messagePrinted()) { System.exit(1); }
// what about the binomials
boolean ignoreBinomials = config.getBoolean ("ignoreBinomials");
// what about multiplexing
boolean multiplex = config.getBoolean ("multiplex");
// what about conditioning
boolean condOnLastSegregating = config.getBoolean ("condOnLastSegregating");
// precision
int precision = config.getInt("precision");
int scale = precision;
// set precision and some math context
MathContext mc = new MathContext (precision, RoundingMode.HALF_EVEN);
// what is the parametrization
boolean paramByHS = false;
String param1Name = null, param2Name = null;
// selection parameterization
if (config.contains("selection") && config.contains("dominance")) {
paramByHS = true;
param1Name = "selection";
param2Name = "dominance";
if (config.contains("hetF") || config.contains("homF")) {
System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
System.exit(1);
}
}
else if (config.contains("hetF") && config.contains("homF")) {
param1Name = "hetF";
param2Name = "homF";
if (config.contains("selection") || config.contains("dominance")) {
System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
System.exit(1);
}
}
else {
System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
System.exit(1);
}
// initial time?
BigDecimal initTime = null;
boolean initTimesInFile = !config.contains ("initTime");
if (initTimesInFile) {
if (!multiplex) {
System.err.println ("The flag timesInFile only works together with multiplexing.");
System.exit(-1);
}
}
else {
//we do have an initial time
initTime = config.getBigDecimal("initTime");
}
// get the initial condition right
BigDecimal initialFrequency = config.getBigDecimal("initFrequency");
boolean initFreqSet = (initialFrequency.compareTo(BigDecimal.ZERO) >= 0d) && (initialFrequency.compareTo(BigDecimal.ONE) <= 0d);
boolean mutSelSet = config.getBoolean ("mutSelBalance");
boolean mutDriftSet = config.getBoolean ("mutDriftBalance");
// not check whether exactly one is set, and which one it is
InitialConditionEnum initialCondition = null;
if (initFreqSet && !mutSelSet && !mutDriftSet) {
// initial frequency given
initialCondition = InitialConditionEnum.InitialFrequency;
}
else if (!initFreqSet && mutSelSet && !mutDriftSet) {
// mutation selection balance requested
initialCondition = InitialConditionEnum.MutationSelection;
}
else if (!initFreqSet && !mutSelSet && mutDriftSet) {
// mutation drift balance requested
initialCondition = InitialConditionEnum.MutationDrift;
}
else {
System.err.println ("Must specify consistent initial conditions.");
System.exit(1);
}
// get input file
File inputFile = config.getFile("inputFile");
// get raw mutation parameters
BigDecimal Ne = (new BigDecimal(config.getString("effPopSize"))).setScale(scale);
BigDecimal preAlpha = config.getBigDecimal("mutToBenef").setScale(scale);
if (BigDecimal.ZERO.compareTo(preAlpha) >= 0) throw new IOException ("Zero mutation rate not implemented yet.");
BigDecimal preBeta = config.getBigDecimal("mutFromBenef").setScale(scale);
if (BigDecimal.ZERO.compareTo(preBeta) >= 0) throw new IOException ("Zero mutation rate not implemented yet.");
// and rescale them to be population scaled
BigDecimal alpha = (new BigDecimal("4")).multiply(Ne, mc).multiply(preAlpha, mc);
BigDecimal beta = (new BigDecimal("4")).multiply(Ne, mc).multiply(preBeta, mc);
BigDecimal yearsPerGen = (new BigDecimal(config.getString("yearsPerGen"))).setScale(scale);
BigDecimal[] param1Range = null;
BigDecimal[] param2Range = null;
// some raw selection coefficients
if (config.contains("selection")) {
assert(config.contains("dominance"));
param1Range = parseRange (config.getString("selection"), scale, mc);
param2Range = parseRange (config.getString("dominance"), scale, mc);
}
if (config.contains("hetF")) {
assert(config.contains("homF"));
param1Range = parseRange (config.getString("hetF"), scale, mc);
param2Range = parseRange (config.getString("homF"), scale, mc);
}
// fill the list of values
ArrayList<BigDecimal> param1s = buildRange (param1Range[0], param1Range[1], param1Range[2], mc);
// also we need the other parameters
// make a list of other parameters
ArrayList<BigDecimal> param2s = buildRange (param2Range[0], param2Range[1], param2Range[2], mc);
// the remaining parameters
int matrixCutoff = config.getInt("matrixCutoff");
int maxM = config.getInt("maxM");
int maxN = config.getInt("maxN");
assert(maxM <= matrixCutoff);
assert(maxN <= maxM);
//print the command line arguments directly, and also the parameters nicely