如何在java中自动运行具有多个不同输入文件的同一个类

时间:2015-04-09 07:15:33

标签: java command-line intellij-idea command-line-arguments

我想知道如何使用不同的命令行选项运行相同的java类而无需手动更改这些命令行选项?

基本上,对于inputFile和treeFile,我有两个以上文件的100多种不同组合。我不能做"编辑配置"在IntelliJ中为treeFile和inputFile的每个组合手动获取结果。

有人可以给我一些建议,以便如何创建那些inputFile和treeFile的循环,这样我就不需要为每个组合手动指定它们了。

非常感谢您的帮助!!!!

@Option(gloss="File of provided alignment")
public File inputFile;


@Option(gloss="File of the tree topology")
public File treeFile;

我的java类代码如下:

public class UniformizationSample implements Runnable
{

@Option(gloss="File of provided alignment")
    public File inputFile;


@Option(gloss="File of the tree topology")
public File treeFile;

@Option(gloss="ESS Experiment Number")
public int rep = 1;

@Option(gloss="Rate Matrix Method")
public RateMtxNames selectedRateMtx = RateMtxNames.POLARITYSIZEGTR;

@Option(gloss = "True rate matrix generating data")
public File rateMtxFile;

@Option(gloss="Use cache or not")
public boolean cached=true;

private final PrintWriter detailWriter = BriefIO.output(Results.getFileInResultFolder("experiment.details.txt"));


public void run()  {
    ObjectMapper mapper = new ObjectMapper();
    double[][] array;
    EndPointSampler.cached=cached;

    try (FileInputStream in = new FileInputStream(rateMtxFile)) {
        array = mapper.readValue(in, double[][].class);
        long startTime = System.currentTimeMillis();
        UnrootedTreeLikelihood<MultiCategorySubstitutionModel<ExpFamMixture>> likelihood1 =
                UnrootedTreeLikelihood
                        .fromFastaFile(inputFile, selectedRateMtx)
                        .withSingleRateMatrix(array)
                        .withExpFamMixture(ExpFamMixture.rateMtxModel(selectedRateMtx))
                        .withTree(treeFile);
        Random rand = new Random(1);
        likelihood1.evolutionaryModel.samplePosteriorPaths(rand, likelihood1.observations, likelihood1.tree);
        logToFile("Total time in seconds: " + ((System.currentTimeMillis() - startTime) / 1000.0));

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {

    } catch (IOException e) {
        e.printStackTrace();
    }


}

public static void main(String [] args)
{
    Mains.instrumentedRun(args, new UniformizationSample());
}


public void logToFile(String someline) {
    this.detailWriter.println(someline);
    this.detailWriter.flush();
}


}

1 个答案:

答案 0 :(得分:1)

在IntelliJ IDEA中无法执行此操作。但是,您可以修改UniformizationSample类,以便将输入数据作为方法参数,并编写另一个Java类,它将遍历您的输入并使用必要的参数调用您的类。