/*.................................................................................................................*/
 public Object doCommand(String commandName, String arguments, CommandChecker checker) {
   if (checker.compare(
       this.getClass(),
       "Sets the number of trees included in each tree block",
       "[number of trees]",
       commandName,
       "setNumberTrees")) {
     MesquiteInteger pos = new MesquiteInteger(0);
     int newNum = MesquiteInteger.fromFirstToken(arguments, pos);
     if (!MesquiteInteger.isCombinable(newNum))
       newNum =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Set Number of Trees",
               "Number of Trees:",
               numTrees,
               0,
               MesquiteInteger.infinite);
     if (newNum > 0 && newNum != numTrees) {
       numTrees = newNum;
       parametersChanged();
     }
   } else if (checker.compare(
       this.getClass(),
       "Returns the module supplying trees",
       "[name of module]",
       commandName,
       "getTreeFiller")) {
     return fillerTask;
   } else return super.doCommand(commandName, arguments, checker);
   return null;
 }
Example #2
0
 /** Called to alter data in all cells */
 public boolean operateOnData(CharacterData data) {
   if (!(data instanceof ContinuousData)) return false;
   ContinuousData cData = (ContinuousData) data;
   int numItems = cData.getNumItems();
   String[] items = new String[numItems];
   for (int i = 0; i < items.length; i++) {
     if (StringUtil.blank(cData.getItemName(i))) items[i] = "(unnamed)";
     else items[i] = cData.getItemName(i);
   }
   int d =
       ListDialog.queryList(
           containerOfModule(),
           "Rename item",
           "Rename item:",
           MesquiteString.helpString,
           items,
           0);
   if (!MesquiteInteger.isCombinable(d) || d < 0 || d >= numItems) return false;
   else {
     String s =
         MesquiteString.queryString(
             containerOfModule(), "Rename Item", "New name for " + items[d], items[d]);
     if (StringUtil.blank(s)) return false;
     cData.setItemReference(d, NameReference.getNameReference(s));
     return true;
   }
 }
Example #3
0
  /**
   * A request for the MesquiteModule to perform a command. It is passed two strings, the name of
   * the command and the arguments. This should be overridden by any module that wants to respond to
   * a command.
   */
  public Object doCommand(String commandName, String arguments, CommandChecker checker) {
    if (checker.compare(MesquiteModule.class, null, null, commandName, "paint")) {
      MesquiteInteger io = new MesquiteInteger(0);
      int column = MesquiteInteger.fromString(arguments, io);
      int row = MesquiteInteger.fromString(arguments, io);
      if (MesquiteInteger.isCombinable(row)) {
        if (!MesquiteLong.isCombinable(currentColor)) removeColor(row, true);
        else setColor(row, (int) currentColor);
      }
    } else if (checker.compare(
        this.getClass(),
        "Sets the color to be used to paint cells",
        "[name of color]",
        commandName,
        "setColor")) {
      int bc = ColorDistribution.standardColorNames.indexOf(parser.getFirstToken(arguments));
      if (bc >= 0 && MesquiteLong.isCombinable(bc)) {
        removeColor.setValue(false);
        currentColor = bc;
        savedColor = bc;
        colorString = "Color " + ColorDistribution.standardColorNames.getValue(bc);
      }
    } else if (checker.compare(
        this.getClass(),
        "Sets the color of selected taxa",
        "[name of color]",
        commandName,
        "setColorSelected")) {
      int bc = ColorDistribution.standardColorNames.indexOf(parser.getFirstToken(arguments));
      if (bc >= 0 && MesquiteLong.isCombinable(bc)) {
        for (int it = 0; it < taxa.getNumTaxa(); it++) if (taxa.getSelected(it)) setColor(it, bc);
      }
    } else if (checker.compare(
        this.getClass(), "Removes color from all the cells", null, commandName, "removeAllColor")) {
      removeAllColor(true);
    } else if (checker.compare(
        this.getClass(),
        "Sets the paint brush so that it removes colors from any cells touched",
        null,
        commandName,
        "removeColor")) {
      if (StringUtil.blank(arguments)) removeColor.setValue(!removeColor.getValue());
      else removeColor.toggleValue(parser.getFirstToken(arguments));

      if (removeColor.getValue()) {
        colorString = "Remove color";
        currentColor = MesquiteLong.unassigned;
      } else {
        colorString = "Color " + ColorDistribution.standardColorNames.getValue((int) currentColor);
        currentColor = savedColor;
      }
    } else return super.doCommand(commandName, arguments, checker);
    return null;
  }
 /** queryies the user to choose a tree and returns an integer of the tree chosen */
 public int queryUserChoose(Taxa taxa, String forMessage) {
   int ic = MesquiteInteger.unassigned;
   int numBlocks = getNumberOfTreeBlocks(taxa);
   if (MesquiteInteger.isCombinable(numBlocks)) {
     String[] s = new String[numBlocks];
     for (int i = 0; i < numBlocks; i++) {
       s[i] = getTreeBlockNameString(taxa, i);
     }
     if (forMessage == null) {
       forMessage = "Choose tree block";
     }
     return ListDialog.queryList(
         containerOfModule(), "Choose tree block", forMessage, MesquiteString.helpString, s, 0);
   } else {
     if (forMessage == null) {
       forMessage = "Number of tree block to be used";
     }
     int r = MesquiteInteger.queryInteger(containerOfModule(), "Choose tree block", forMessage, 1);
     if (MesquiteInteger.isCombinable(r)) return MesquiteTree.toInternal(r);
     else return r;
   }
 }
Example #5
0
 /*.................................................................................................................*/
 public Object doCommand(String commandName, String arguments, CommandChecker checker) {
   if (checker.compare(
       this.getClass(),
       "Sets the number of randomly chosen taxa to exclude",
       "[number]",
       commandName,
       "setNumberExcluded")) {
     int s = MesquiteInteger.fromString(parser.getFirstToken(arguments));
     if (!MesquiteInteger.isCombinable(s)) {
       s =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Number of taxa to exclude",
               "Enter the number of randomly chosen taxa to exclude",
               numExcluded);
     }
     if (MesquiteInteger.isCombinable(s)) {
       numExcluded = s;
       parametersChanged();
     }
   } else return super.doCommand(commandName, arguments, checker);
   return null;
 }
Example #6
0
 /*.................................................................................................................*/
 public boolean startJob(String arguments, Object condition, boolean hiredByName) {
   if (!MesquiteThread.isScripting()) {
     int s =
         MesquiteInteger.queryInteger(
             containerOfModule(),
             "Number of taxa to exclude",
             "Enter the number of randomly chosen taxa to exclude",
             numExcluded);
     if (MesquiteInteger.isCombinable(s)) numExcluded = s;
     else return false;
   }
   addMenuItem("Number of Taxa Excluded...", makeCommand("setNumberExcluded", this));
   return true;
 }
 /**
  * Called to provoke any necessary initialization. This helps prevent the module's intialization
  * queries to the user from happening at inopportune times (e.g., while a long chart calculation
  * is in mid-progress)
  */
 public void initialize(Taxa taxa) {
   setPreferredTaxa(taxa);
   fillerTask.initialize(taxa);
   if (!fillerTask.hasLimitedTrees(taxa)) {
     if (!MesquiteThread.isScripting() && !nTreesSet) {
       int n =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Trees per block?",
               "How many trees to include per tree block?",
               numTrees);
       if (MesquiteInteger.isCombinable(n) && n > 0) numTrees = n;
       nTreesSet = true;
     }
   }
   ntreesItem.setEnabled(!fillerTask.hasLimitedTrees(taxa));
   MesquiteTrunk.resetMenuItemEnabling();
 }
 /*.................................................................................................................*/
 public Object doCommand(String commandName, String arguments, CommandChecker checker) {
   if (checker.compare(
       this.getClass(),
       "Sets the number of trees included in each tree block",
       "[number of trees]",
       commandName,
       "setNumberTrees")) {
     MesquiteInteger pos = new MesquiteInteger(0);
     int newNum = MesquiteInteger.fromFirstToken(arguments, pos);
     if (!MesquiteInteger.isCombinable(newNum))
       newNum =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Set Number of Trees",
               "Number of Trees:",
               numTrees,
               0,
               MesquiteInteger.infinite);
     if (newNum > 0 && newNum != numTrees) {
       numTrees = newNum;
       parametersChanged();
     }
   } else if (checker.compare(
       this.getClass(),
       "Sets the module supplying trees",
       "[name of module]",
       commandName,
       "setTreeFiller")) {
     TreeBlockFiller temp =
         (TreeBlockFiller)
             replaceEmployee(
                 TreeBlockFiller.class, arguments, "Source of trees for tree blocks", fillerTask);
     if (temp != null) {
       fillerTask = temp;
       initialize(preferredTaxa);
       parametersChanged(); // ?
     }
     return temp;
   } else return super.doCommand(commandName, arguments, checker);
   return null;
 }
 /**
  * Called to provoke any necessary initialization. This helps prevent the module's intialization
  * queries to the user from happening at inopportune times (e.g., while a long chart calculation
  * is in mid-progress)
  */
 public void initialize(Taxa taxa) {
   setPreferredTaxa(taxa);
   fillerTask.initialize(taxa);
   if (!fillerTask.hasLimitedTrees(taxa)) {
     if (!MesquiteThread.isScripting() && !nTreesSet) {
       int n =
           MesquiteInteger.queryInteger(
               containerOfModule(),
               "Trees per block?",
               "How many trees to include per tree block?",
               numTrees);
       if (MesquiteInteger.isCombinable(n) && n > 0) numTrees = n;
       nTreesSet = true;
     }
   }
   if (enableNumTreesChoice() && ntreesItem == null)
     ntreesItem = addMenuItem("Number of Trees...", makeCommand("setNumberTrees", this));
   if (ntreesItem != null && fillerTask != null)
     ntreesItem.setEnabled(!fillerTask.hasLimitedTrees(taxa));
   MesquiteTrunk.resetMenuItemEnabling();
 }
Example #10
0
  public void runFilesAvailable(int fileNum) {
    String[] logFileNames = getLogFileNames();
    if ((progIndicator != null && progIndicator.isAborted()) || logFileNames == null) return;
    String[] outputFilePaths = new String[logFileNames.length];
    outputFilePaths[fileNum] = externalProcRunner.getOutputFilePath(logFileNames[fileNum]);
    String filePath = outputFilePaths[fileNum];

    if (fileNum == 0
        && outputFilePaths.length > 0
        && !StringUtil.blank(outputFilePaths[0])
        && !bootstrapOrJackknife()) { // tree file
      if (ownerModule instanceof NewTreeProcessor) {
        String treeFilePath = filePath;
        if (taxa != null) {
          TaxaSelectionSet outgroupSet =
              (TaxaSelectionSet) taxa.getSpecsSet(outgroupTaxSetString, TaxaSelectionSet.class);
          ((NewTreeProcessor) ownerModule).newTreeAvailable(treeFilePath, outgroupSet);

        } else ((NewTreeProcessor) ownerModule).newTreeAvailable(treeFilePath, null);
      }
    } else if (fileNum == 1
        && outputFilePaths.length > 1
        && !StringUtil.blank(outputFilePaths[1])
        && !bootstrapOrJackknife()) { // log file
      if (MesquiteFile.fileExists(filePath)) {
        String s = MesquiteFile.getFileLastContents(filePath);
        if (!StringUtil.blank(s))
          if (progIndicator != null) {
            parser.setString(s);
            String rep = parser.getFirstToken(); // generation number
            logln("");
            if (MesquiteInteger.isNumber(rep)) {
              int numReps = MesquiteInteger.fromString(rep) + 1;
              progIndicator.setText(
                  "Replicate: " + numReps); // + ", ln L = " + parser.getNextToken());
              if (bootstrapOrJackknife()) {
                logln("Replicate " + numReps + " of " + bootstrapreps);
              }
              logln("Replicate " + numReps + " of " + totalNumHits);

              progIndicator.spin();
              double timePerRep = 0;
              if (MesquiteInteger.isCombinable(numReps) && numReps > 0) {
                timePerRep = timer.timeSinceVeryStartInSeconds() / numReps; // this is time per rep
              }
              int timeLeft = 0;
              if (bootstrapOrJackknife()) {
                timeLeft = (int) ((bootstrapreps - numReps) * timePerRep);
              } else {
                String token = parser.getNextToken(); // algorithm
                token = parser.getNextToken(); // Tree
                token = parser.getNextToken(); // Score
                String best = parser.getNextToken(); // Best
                logln("  Score " + token + "; best found so far " + best);
                timeLeft = (int) ((totalNumHits - numReps) * timePerRep);
              }

              logln(
                  "  Running time so far "
                      + StringUtil.secondsToHHMMSS((int) timer.timeSinceVeryStartInSeconds())
                      + ", approximate time remaining "
                      + StringUtil.secondsToHHMMSS(timeLeft));
            }
          }
        count++;
      } else if (MesquiteTrunk.debugMode) logln("*** File does not exist (" + filePath + ") ***");
    }
  }
Example #11
0
  /*.................................................................................................................*/
  void formCommandFile(String dataFileName, int firstOutgroup) {
    if (parallel) {
      commands = "";
    }
    commands += getTNTCommand("mxram " + mxram);

    commands += getTNTCommand("report+0/1/0");
    commands += getTNTCommand("log " + logFileName);
    commands += getTNTCommand("p " + dataFileName);
    commands += getTNTCommand("vversion");
    if (MesquiteInteger.isCombinable(firstOutgroup) && firstOutgroup >= 0)
      commands += getTNTCommand("outgroup " + firstOutgroup);
    if (bootstrapOrJackknife()) {
      if (parallel) {
        commands += indentTNTCommand("ptnt begin parallelRun " + numSlaves + "/ram x 2 = ");
      }
      if (StringUtil.notEmpty(bootSearchScriptPath)) {
        String script = MesquiteFile.getFileContentsAsString(bootSearchScriptPath);
        if (StringUtil.notEmpty(script)) commands += script;
      } else
        commands += StringUtil.lineEnding() + bootstrapSearchArguments + StringUtil.lineEnding();
      String saveTreesString = "";
      if (resamplingAllConsensusTrees) saveTreesString = " savetrees ";
      String bootSearchString = " [xmult; bb]";
      bootSearchString = "";

      if (parallel) {
        int numRepsPerSlave = bootstrapreps / numSlaves;
        if (numRepsPerSlave * numSlaves < bootstrapreps) numRepsPerSlave++;
        if (searchStyle == BOOTSTRAPSEARCH)
          commands +=
              getTNTCommand(
                  "resample boot cut 50 "
                      + saveTreesString
                      + " replications "
                      + numRepsPerSlave
                      + " [xmult; bb] savetrees"); // + getComDelim();
        else if (searchStyle == JACKKNIFESEARCH)
          commands +=
              getTNTCommand(
                  "resample jak cut 50 "
                      + saveTreesString
                      + " replications "
                      + numRepsPerSlave
                      + " [xmult; bb] savetrees"); // + getComDelim();
        else if (searchStyle == SYMSEARCH)
          commands +=
              getTNTCommand(
                  "resample sym cut 50 "
                      + saveTreesString
                      + " replications "
                      + numRepsPerSlave
                      + " [xmult; bb] savetrees"); // + getComDelim();
        else if (searchStyle == POISSONSEARCH)
          commands +=
              getTNTCommand(
                  "resample poisson cut 50 "
                      + saveTreesString
                      + " replications "
                      + numRepsPerSlave
                      + " [xmult; bb] savetrees"); // + getComDelim();
        commands += getTNTCommand("return");
        commands += getTNTCommand("ptnt wait parallelRun");
        commands += getTNTCommand("ptnt get parallelRun");
      } else {
        if (!resamplingAllConsensusTrees) {
          commands += getTNTCommand("macro=");
          commands += getTNTCommand("ttags =");
        }
        commands += getTNTCommand("tsave *" + treeFileName);
        if (bootstrapAllowed) {
          if (searchStyle == BOOTSTRAPSEARCH)
            commands +=
                getTNTCommand(
                    "resample boot "
                        + saveTreesString
                        + " replications "
                        + bootstrapreps
                        + bootSearchString); // + getComDelim();
          else if (searchStyle == JACKKNIFESEARCH)
            commands +=
                getTNTCommand(
                    "resample jak cut 50 "
                        + saveTreesString
                        + " replications "
                        + bootstrapreps
                        + bootSearchString); // + getComDelim();
          else if (searchStyle == SYMSEARCH)
            commands +=
                getTNTCommand(
                    "resample sym cut 50 "
                        + saveTreesString
                        + " replications "
                        + bootstrapreps
                        + bootSearchString); // + getComDelim();
          else if (searchStyle == POISSONSEARCH)
            commands +=
                getTNTCommand(
                    "resample poisson cut 50 "
                        + saveTreesString
                        + " replications "
                        + bootstrapreps
                        + bootSearchString); // + getComDelim();
        }
        if (!resamplingAllConsensusTrees) commands += getTNTCommand("save *");
        else commands += getTNTCommand("save");
        commands += getTNTCommand("tsave/");
        if (!resamplingAllConsensusTrees) {
          commands += getTNTCommand("ttags -/");
          commands += getTNTCommand("macro-");
        }
      }

      // commands += getTNTCommand("proc/") ;

      commands += getTNTCommand("log/");

      //	if (!parallel)
      commands += getTNTCommand("quit");
    } else {
      // commands += getTNTCommand("tsave !5 " + treeFileName) ;   // if showing intermediate trees
      commands += getTNTCommand("tsave *" + treeFileName);
      if (StringUtil.notEmpty(searchScriptPath)) {
        String script = MesquiteFile.getFileContentsAsString(searchScriptPath);
        if (StringUtil.notEmpty(script)) commands += script;
      } else commands += searchArguments;
      commands += otherOptions;
      if (harvestOnlyStrictConsensus) commands += getTNTCommand("nelsen *");
      commands += getTNTCommand("save");
      commands += getTNTCommand("log/");

      commands += getTNTCommand("tsave/");
      commands += getTNTCommand("quit");
    }
  }