如何使用多个不同的输入文件自动 运行 java 中的相同 class

How to run the same class in java with multiple different input files automatically

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

基本上,对于inputFile和treeFile,我有超过100种这两个文件的不同组合。我无法在 IntelliJ 中执行 "edit configurations" 以手动获取 treeFile 和 inputFile 的每个组合的结果。

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

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

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


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

我的javaclass代码如下:

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();
}


}

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