Exemplo n.º 1
0
  /*.................................................................................................................*/
  public Tree getTrees(
      TreeVector trees,
      Taxa taxa,
      MCharactersDistribution matrix,
      long seed,
      MesquiteDouble finalScore) {
    if (!initializeGetTrees(CategoricalData.class, taxa, matrix)) return null;
    setTNTSeed(seed);
    isProtein = data instanceof ProteinData;

    // David: if isDoomed() then module is closing down; abort somehow

    // write data file
    String tempDir =
        MesquiteFileUtil.createDirectoryForFiles(
            this, MesquiteFileUtil.IN_SUPPORT_DIR, "TNT", "-Run.");
    if (tempDir == null) return null;
    String dataFileName = "data.ss"; // replace this with actual file name?
    String dataFilePath = tempDir + dataFileName;

    FileInterpreterI exporter = ZephyrUtil.getFileInterpreter(this, "#InterpretTNT");
    if (exporter == null) return null;
    boolean fileSaved = false;
    String translationTable = namer.getTranslationTable(taxa);
    ((InterpretHennig86Base) exporter).setTaxonNamer(namer);

    fileSaved = ZephyrUtil.saveExportFile(this, exporter, dataFilePath, data, selectedTaxaOnly);
    if (!fileSaved) return null;

    String translationFileName = IOUtil.translationTableFileName;
    setTaxonTranslation(taxa);
    taxonNumberTranslation = getTaxonNumberTranslation(taxa);
    namer.setNumberTranslationTable(taxonNumberTranslation);

    setFileNames();

    TaxaSelectionSet outgroupSet =
        (TaxaSelectionSet) taxa.getSpecsSet(outgroupTaxSetString, TaxaSelectionSet.class);
    int firstOutgroup = MesquiteInteger.unassigned;
    if (outgroupSet != null) firstOutgroup = outgroupSet.firstBitOn();
    formCommandFile(dataFileName, firstOutgroup);
    logln("\n\nCommands given to TNT:");
    logln(commands);
    logln("");

    MesquiteString arguments = new MesquiteString();
    arguments.setValue(" proc " + commandsFileName);

    String programCommand = externalProcRunner.getExecutableCommand();

    int numInputFiles = 3;
    String[] fileContents = new String[numInputFiles];
    String[] fileNames = new String[numInputFiles];
    for (int i = 0; i < numInputFiles; i++) {
      fileContents[i] = "";
      fileNames[i] = "";
    }
    fileContents[0] = MesquiteFile.getFileContentsAsString(dataFilePath);
    fileNames[0] = dataFileName;
    fileContents[1] = commands;
    fileNames[1] = commandsFileName;
    fileContents[2] = translationTable;
    fileNames[2] = translationFileName;

    // ----------//
    boolean success =
        runProgramOnExternalProcess(
            programCommand, arguments, fileContents, fileNames, ownerModule.getName());

    if (!isDoomed()) {
      if (success) {
        desuppressProjectPanelReset();
        return retrieveTreeBlock(trees, finalScore); // here's where we actually process everything.
      } else {
        if (!beanWritten) postBean("unsuccessful [1]", false);
        beanWritten = true;
      }
    }
    desuppressProjectPanelReset();
    if (data == null) data.decrementEditInhibition();
    externalProcRunner.finalCleanup();
    return null;
  }
  /*.................................................................................................................*/
  void getArguments(
      MultipartEntityBuilder builder,
      StringBuffer sb,
      String fileName,
      String LOCproteinModel,
      String LOCdnaModel,
      String LOCotherOptions,
      int LOCbootstrapreps,
      int LOCbootstrapSeed,
      int LOCnumRuns,
      String LOCoutgroupTaxSetString,
      String LOCMultipleModelFile,
      boolean preflight) {
    if (builder == null) return;
    /*
    if (preflight)
    	arguments += " -n preflight.out ";
    else
    	arguments += " -s " + fileName + " -n file.out ";
    */

    if (isProtein) {
      if (StringUtil.blank(LOCproteinModel))
        addArgument(builder, sb, "vparam.protein_opts_", "PROTGAMMAJTT");
      else addArgument(builder, sb, "vparam.protein_opts_", LOCproteinModel);
    } else if (StringUtil.blank(LOCdnaModel))
      addArgument(builder, sb, "vparam.dna_gtrcat_", "GTRGAMMA");
    else addArgument(builder, sb, "vparam.dna_gtrcat_", "GTRGAMMA");
    //	builder.addTextBody("vparam.dna_gtrcat_",LOCdnaModel);

    /*
    		if (StringUtil.notEmpty(LOCMultipleModelFile))
    			arguments += " -q " + ShellScriptUtil.protectForShellScript(LOCMultipleModelFile);

    		if (!StringUtil.blank(LOCotherOptions))
    			arguments += " " + LOCotherOptions;

    */

    addArgument(builder, sb, "vparam.provide_parsimony_seed_", "1");
    addArgument(builder, sb, "vparam.parsimony_seed_val_", "" + randomIntSeed);

    if (bootstrapOrJackknife()) {
      if (LOCbootstrapreps > 0) {
        addArgument(builder, sb, "vparam.choose_bootstrap_", "b");
        addArgument(builder, sb, "vparam.bootstrap_value_", "" + LOCbootstrapreps);
        addArgument(builder, sb, "vparam.seed_value_", "" + LOCbootstrapSeed);
        //	addArgument(builder, sb, "vparam.bootstrap_",""+LOCbootstrapreps);
        //	addArgument(builder, sb, "vparam.mulparambootstrap_seed_",""+LOCbootstrapSeed);
      } else Debugg.println("TOO FEW BOOTSTRAP REPS");

    } else {
      addArgument(builder, sb, "vparam.specify_runs_", "1");
      addArgument(builder, sb, "vparam.altrun_number_", "" + LOCnumRuns);
      //	if (RAxML814orLater)
      // addArgument(builder, sb, "vparam.mesquite_output_","1");
    }

    TaxaSelectionSet outgroupSet = null;
    if (!StringUtil.blank(LOCoutgroupTaxSetString)) {
      outgroupSet =
          (TaxaSelectionSet) taxa.getSpecsSet(LOCoutgroupTaxSetString, TaxaSelectionSet.class);
      if (outgroupSet != null)
        addArgument(builder, sb, "vparam.outgroup_", outgroupSet.getStringList(",", true));
      arguments += " -o " + outgroupSet.getStringList(",", true);
    }
  }