我想知道如何使用不同的命令行选项运行同一个 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();
}
}
最佳答案
在 IntelliJ IDEA 中无法执行此操作。但是,您可以修改您的 UniformizationSample
类,以便它将输入数据作为方法参数,并编写另一个 Java 类,该类将循环您的输入并使用必要的参数调用您的类。
关于java - 如何使用多个不同的输入文件自动运行java中的同一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29532127/