【问题标题】:How to run the same class in java with multiple different input files automatically如何在具有多个不同输入文件的java中自动运行同一个类
【发布时间】:2015-06-14 10:37:36
【问题描述】:

我想知道如何在不手动更改这些命令行选项的情况下运行具有不同命令行选项的同一个 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();
}


}

【问题讨论】:

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


    【解决方案1】:

    在 IntelliJ IDEA 中没有办法做到这一点。但是,您可以修改您的 UniformizationSample 类,使其将输入数据作为方法参数,并编写另一个 Java 类来循环您的输入并使用必要的参数调用您的类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-15
      • 2017-09-21
      相关资源
      最近更新 更多