Search in sources :

Example 16 with ArgsEngine

use of cz1.util.ArgsEngine in project polyGembler by c-zhou.

the class Haplotyper method setParameters.

@Override
public void setParameters(String[] args) {
    if (args.length == 0) {
        printUsage();
        throw new IllegalArgumentException("\n\nPlease use the above arguments/options.\n\n");
    }
    if (myArgsEngine == null) {
        myArgsEngine = new ArgsEngine();
        myArgsEngine.add("-i", "--input", true);
        myArgsEngine.add("-o", "--prefix", true);
        myArgsEngine.add("-ex", "--experiment-id", true);
        myArgsEngine.add("-hf", "--hmm-file", true);
        myArgsEngine.add("-c", "--scaffold", true);
        myArgsEngine.add("-cs", "--start-position", true);
        myArgsEngine.add("-ce", "--end-position", true);
        myArgsEngine.add("-x", "--max-iter", true);
        myArgsEngine.add("-p", "--ploidy", true);
        myArgsEngine.add("-f", "--parent", true);
        myArgsEngine.add("-fc", "--founder-hap-coeff", true);
        myArgsEngine.add("-s", "--initial-seperation", true);
        myArgsEngine.add("-r", "--reverse", true);
        myArgsEngine.add("-G", "--genotype", false);
        myArgsEngine.add("-D", "--allele-depth", false);
        myArgsEngine.add("-L", "--genotype-likelihood", false);
        myArgsEngine.add("-b", "--segmental-kmeans", false);
        myArgsEngine.add("-e", "--train-exp", false);
        myArgsEngine.add("-S", "--random-seed", true);
        myArgsEngine.add("-rs", "--resampling", true);
        myArgsEngine.add("-pp", "--print-plot", false);
        myArgsEngine.add("-sp", "--save-plot", true);
        myArgsEngine.parse(args);
    }
    if (myArgsEngine.getBoolean("-i")) {
        in_zip = myArgsEngine.getString("-i");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your input zip file.");
    }
    if (myArgsEngine.getBoolean("-o")) {
        out_prefix = myArgsEngine.getString("-o");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your output file prefix.");
    }
    if (myArgsEngine.getBoolean("-ex")) {
        expr_id = myArgsEngine.getString("-ex");
    } else {
        expr_id = new File(in_zip).getName().replaceAll(".zip$", "").replace(".", "").replace("_", "");
    }
    if (myArgsEngine.getBoolean("-hf")) {
        hmm_file = myArgsEngine.getString("-hf");
    }
    if (myArgsEngine.getBoolean("-c")) {
        scaff = myArgsEngine.getString("-c").split(":");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify the scaffold(s).");
    }
    if (myArgsEngine.getBoolean("-cs") ^ myArgsEngine.getBoolean("-ce")) {
        printUsage();
        throw new IllegalArgumentException("Need to specify both start position " + "and end position or none of them.");
    }
    if (myArgsEngine.getBoolean("-cs")) {
        String[] s = myArgsEngine.getString("-cs").split(":");
        start_pos = new int[scaff.length];
        int n = Math.min(scaff.length, s.length);
        for (int i = 0; i != n; i++) start_pos[i] = Integer.parseInt(s[i]);
        for (int i = n; i < start_pos.length; i++) start_pos[i] = Integer.MIN_VALUE;
    }
    if (myArgsEngine.getBoolean("-ce")) {
        String[] s = myArgsEngine.getString("-ce").split(":");
        end_pos = new int[scaff.length];
        int n = Math.min(scaff.length, s.length);
        for (int i = 0; i != n; i++) end_pos[i] = Integer.parseInt(s[i]);
        for (int i = n; i < end_pos.length; i++) end_pos[i] = Integer.MAX_VALUE;
    }
    if (myArgsEngine.getBoolean("-x")) {
        max_iter = Integer.parseInt(myArgsEngine.getString("-x"));
    }
    if (myArgsEngine.getBoolean("-p")) {
        Constants.ploidy(Integer.parseInt(myArgsEngine.getString("-p")));
    }
    if (myArgsEngine.getBoolean("-f")) {
        Constants._founder_haps = myArgsEngine.getString("-f");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify the parent samples (seperated by a \":\").");
    }
    if (myArgsEngine.getBoolean("-fc")) {
        founder_hap_coeff = Double.parseDouble(myArgsEngine.getString("-fc"));
    }
    if (myArgsEngine.getBoolean("-s")) {
        String[] ss = myArgsEngine.getString("-s").split(":");
        if (ss.length < scaff.length - 1)
            throw new RuntimeException("Number of scaffolds does not match number of initial seperations!!!");
        seperation = new double[scaff.length - 1];
        for (int i = 0; i < seperation.length; i++) seperation[i] = Double.parseDouble(ss[i]);
    } else {
        seperation = new double[scaff.length - 1];
        for (int i = 0; i < seperation.length; i++) seperation[i] = Math.max(Math.round(Constants.rand.nextDouble() * Constants._max_initial_seperation), 1);
    }
    boolean isRF = Constants.isRF(seperation);
    if (isRF) {
        for (int i = 0; i < seperation.length; i++) seperation[i] = Constants.haldane(seperation[i]);
    }
    if (myArgsEngine.getBoolean("-r")) {
        String[] dd = myArgsEngine.getString("-r").split(":");
        if (dd.length < scaff.length)
            throw new RuntimeException("Number of scaffolds does not match number of reverses!!!");
        reverse = new boolean[scaff.length];
        for (int i = 0; i < reverse.length; i++) reverse[i] = Boolean.parseBoolean(dd[i]);
    } else {
        reverse = new boolean[scaff.length];
        Arrays.fill(reverse, false);
    }
    int i = 0;
    if (myArgsEngine.getBoolean("-G")) {
        field = Field.GT;
        i++;
    }
    if (myArgsEngine.getBoolean("-D")) {
        field = Field.AD;
        i++;
    }
    if (myArgsEngine.getBoolean("-L")) {
        field = Field.PL;
        i++;
    }
    if (i > 1)
        throw new RuntimeException("Options -G/--genotype, " + "-D/--allele-depth, and -L/--genotype-likelihood " + "are exclusive!!!");
    if (myArgsEngine.getBoolean("-b")) {
        vbt = true;
    // throw new RuntimeException("Viterbi training not supported yet!!!");
    }
    if (myArgsEngine.getBoolean("-S")) {
        Constants.seed = Long.parseLong(myArgsEngine.getString("-S"));
        Constants.setRandomGenerator();
    }
    if (myArgsEngine.getBoolean("-rs")) {
        resampling = Integer.parseInt(myArgsEngine.getString("-rs"));
        ;
    }
    if (myArgsEngine.getBoolean("-e")) {
        trainExp = true;
    }
    if (myArgsEngine.getBoolean("-pp")) {
        Constants.plot(true);
    }
    if (myArgsEngine.getBoolean("-sp")) {
        plot_pdf = myArgsEngine.getString("-sp");
        Constants.plot(true);
        Constants.printPlots(true);
    }
}
Also used : File(java.io.File) ArgsEngine(cz1.util.ArgsEngine)

Example 17 with ArgsEngine

use of cz1.util.ArgsEngine in project polyGembler by c-zhou.

the class LinkageMapConstructor method setParameters.

@Override
public void setParameters(String[] args) {
    // TODO Auto-generated method stub
    if (args.length == 0) {
        printUsage();
        throw new IllegalArgumentException("\n\nPlease use the above arguments/options.\n\n");
    }
    if (myArgsEngine == null) {
        myArgsEngine = new ArgsEngine();
        myArgsEngine.add("-i", "--rf", true);
        myArgsEngine.add("-m", "--map", true);
        myArgsEngine.add("-1", "--one-group", false);
        myArgsEngine.add("-2", "--check-group", false);
        myArgsEngine.add("-o", "--prefix", true);
        myArgsEngine.add("-rlib", "--R-external-libs", true);
        myArgsEngine.parse(args);
    }
    if (myArgsEngine.getBoolean("-i")) {
        rf_file = myArgsEngine.getString("-i");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your recombinatio frequency file.");
    }
    if (myArgsEngine.getBoolean("-m")) {
        map_file = myArgsEngine.getString("-m");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your recombination map file.");
    }
    if (myArgsEngine.getBoolean("-1")) {
        one = true;
    }
    if (myArgsEngine.getBoolean("-2")) {
        two = true;
    }
    if (myArgsEngine.getBoolean("-o")) {
        out_prefix = myArgsEngine.getString("-o");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your output file prefix.");
    }
    if (myArgsEngine.getBoolean("-rlib")) {
        RLibPath = myArgsEngine.getString("-rlib");
    }
}
Also used : ArgsEngine(cz1.util.ArgsEngine)

Example 18 with ArgsEngine

use of cz1.util.ArgsEngine in project polyGembler by c-zhou.

the class PseudoMoleculeConstructor method setParameters.

@Override
public void setParameters(String[] args) {
    // TODO Auto-generated method stub
    if (args.length == 0) {
        printUsage();
        throw new IllegalArgumentException("\n\nPlease use the above arguments/options.\n\n");
    }
    if (myArgsEngine == null) {
        myArgsEngine = new ArgsEngine();
        myArgsEngine.add("-i", "--input-mct", true);
        myArgsEngine.add("-a", "--input-assembly", true);
        myArgsEngine.add("-frac", "--frac-thresold", true);
        myArgsEngine.add("-gz", "--genome-size", true);
        myArgsEngine.add("-o", "--prefix", true);
    }
    if (myArgsEngine.getBoolean("-i")) {
        mct_file = myArgsEngine.getString("-i");
        this.geneticMapReader();
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your input genetic linkage map file.");
    }
    if (myArgsEngine.getBoolean("-a")) {
        assembly_file = myArgsEngine.getString("-a");
        this.assemblyReader();
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your assembly fasta file.");
    }
    if (myArgsEngine.getBoolean("-o")) {
        out_file = myArgsEngine.getString("-o");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your output file name.");
    }
    if (myArgsEngine.getBoolean("-frac")) {
        frac_thresh = Double.parseDouble(myArgsEngine.getString("-frac"));
    }
    if (myArgsEngine.getBoolean("-gz")) {
        genome_size = Double.parseDouble(myArgsEngine.getString("-gz"));
    }
}
Also used : ArgsEngine(cz1.util.ArgsEngine)

Example 19 with ArgsEngine

use of cz1.util.ArgsEngine in project polyGembler by c-zhou.

the class RFEstimatorRS method setParameters.

@Override
public void setParameters(String[] args) {
    // TODO Auto-generated method stub
    if (args.length == 0) {
        printUsage();
        throw new IllegalArgumentException("\n\nPlease use the above arguments/options.\n\n");
    }
    if (myArgsEngine == null) {
        myArgsEngine = new ArgsEngine();
        myArgsEngine.add("-ex", "--experiment-id", true);
        myArgsEngine.add("-i", "--hap-file", true);
        myArgsEngine.add("-o", "--prefix", true);
        myArgsEngine.add("-f", "--parent", true);
        myArgsEngine.add("-p", "--ploidy", true);
        myArgsEngine.add("-nb", "--best", true);
        myArgsEngine.add("-t", "--threads", true);
        myArgsEngine.add("-phi", "--skew-phi", true);
        myArgsEngine.add("-nd", "--drop", true);
        myArgsEngine.parse(args);
    }
    if (myArgsEngine.getBoolean("-i")) {
        in_haps = myArgsEngine.getString("-i");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your input zip file.");
    }
    if (myArgsEngine.getBoolean("-o")) {
        out_prefix = myArgsEngine.getString("-o");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your output file prefix.");
    }
    if (myArgsEngine.getBoolean("-ex")) {
        expr_id = myArgsEngine.getString("-ex");
    } else {
        expr_id = guessExperimentId();
        myLogger.warn("No experiment prefix provided, I guess it's " + expr_id + ". Please\n" + "specify it with -ex/--experiment-id option if it's incorrect.");
    }
    if (myArgsEngine.getBoolean("-f")) {
        founder_haps = myArgsEngine.getString("-f").split(":");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify the parent samples (seperated by a \":\").");
    }
    if (myArgsEngine.getBoolean("-p")) {
        int ploidy = Integer.parseInt(myArgsEngine.getString("-p"));
        Constants.ploidy(ploidy);
        Constants._haplotype_z = ploidy * 2;
        probs_uniform = new double[ploidy * 2];
        Arrays.fill(probs_uniform, .5 / ploidy);
        ploidy2 = ploidy / 2;
        shift_bits2 = mask_length * ploidy;
    }
    if (myArgsEngine.getBoolean("-nb")) {
        best_n = Integer.parseInt(myArgsEngine.getString("-nb"));
    }
    if (myArgsEngine.getBoolean("-t")) {
        THREADS = Integer.parseInt(myArgsEngine.getString("-t"));
    }
    if (myArgsEngine.getBoolean("-phi")) {
        skew_phi = Double.parseDouble(myArgsEngine.getString("-phi"));
    }
    if (myArgsEngine.getBoolean("-nd")) {
        drop_thres = Integer.parseInt(myArgsEngine.getString("-nd"));
    }
    setHaps();
}
Also used : MathIllegalArgumentException(org.apache.commons.math3.exception.MathIllegalArgumentException) ArgsEngine(cz1.util.ArgsEngine)

Example 20 with ArgsEngine

use of cz1.util.ArgsEngine in project polyGembler by c-zhou.

the class RFEstimatorRS2 method setParameters.

@Override
public void setParameters(String[] args) {
    // TODO Auto-generated method stub
    if (args.length == 0) {
        printUsage();
        throw new IllegalArgumentException("\n\nPlease use the above arguments/options.\n\n");
    }
    if (myArgsEngine == null) {
        myArgsEngine = new ArgsEngine();
        myArgsEngine.add("-ex", "--experiment-id", true);
        myArgsEngine.add("-i", "--hap-file", true);
        myArgsEngine.add("-o", "--prefix", true);
        myArgsEngine.add("-f", "--parent", true);
        myArgsEngine.add("-p", "--ploidy", true);
        myArgsEngine.add("-nb", "--best", true);
        myArgsEngine.add("-t", "--threads", true);
        myArgsEngine.add("-phi", "--skew-phi", true);
        myArgsEngine.add("-nd", "--drop", true);
        myArgsEngine.parse(args);
    }
    if (myArgsEngine.getBoolean("-i")) {
        in_haps = myArgsEngine.getString("-i");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your input zip file.");
    }
    if (myArgsEngine.getBoolean("-o")) {
        out_prefix = myArgsEngine.getString("-o");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify your output file prefix.");
    }
    if (myArgsEngine.getBoolean("-ex")) {
        expr_id = myArgsEngine.getString("-ex");
    } else {
        expr_id = guessExperimentId();
        myLogger.warn("No experiment prefix provided, I guess it's " + expr_id + ". Please\n" + "specify it with -ex/--experiment-id option if it's incorrect.");
    }
    if (myArgsEngine.getBoolean("-f")) {
        founder_haps = myArgsEngine.getString("-f").split(":");
    } else {
        printUsage();
        throw new IllegalArgumentException("Please specify the parent samples (seperated by a \":\").");
    }
    if (myArgsEngine.getBoolean("-p")) {
        int ploidy = Integer.parseInt(myArgsEngine.getString("-p"));
        Constants.ploidy(ploidy);
        Constants._haplotype_z = ploidy * 2;
        probs_uniform = new double[ploidy * 2];
        Arrays.fill(probs_uniform, .5 / ploidy);
        ploidy2 = ploidy / 2;
        shift_bits2 = mask_length * ploidy;
    }
    if (myArgsEngine.getBoolean("-nb")) {
        best_n = Integer.parseInt(myArgsEngine.getString("-nb"));
    }
    if (myArgsEngine.getBoolean("-t")) {
        THREADS = Integer.parseInt(myArgsEngine.getString("-t"));
    }
    if (myArgsEngine.getBoolean("-phi")) {
        skew_phi = Double.parseDouble(myArgsEngine.getString("-phi"));
    }
    if (myArgsEngine.getBoolean("-nd")) {
        drop_thres = Integer.parseInt(myArgsEngine.getString("-nd"));
    }
    setHaps();
}
Also used : MathIllegalArgumentException(org.apache.commons.math3.exception.MathIllegalArgumentException) ArgsEngine(cz1.util.ArgsEngine)

Aggregations

ArgsEngine (cz1.util.ArgsEngine)43 File (java.io.File)10 MathIllegalArgumentException (org.apache.commons.math3.exception.MathIllegalArgumentException)5 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GBS (cz1.simulation.model.GBS)1 Population (cz1.simulation.model.Population)1 SAMRecord (htsjdk.samtools.SAMRecord)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1