Exemplo n.º 1
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;
  }
Exemplo n.º 2
0
 public void textValueChanged(TextEvent e) {
   boolean b = false;
   String s = tf.getText();
   try {
     int value = MesquiteInteger.fromString(s);
     b = (value <= maxValue && value >= minValue && value != currentValue);
   } catch (NumberFormatException ex) {
   }
   enterButton.setEnabled(b && !enterLock);
 }
Exemplo n.º 3
0
 public void acceptText() {
   String s = tf.getText();
   oldText = null;
   text = s;
   try {
     int value = MesquiteInteger.fromString(s);
     crement(value);
   } catch (NumberFormatException e) {
   }
 }
Exemplo n.º 4
0
 public boolean isTextValid() {
   boolean b = false;
   String s = tf.getText();
   try {
     int value = MesquiteInteger.fromString(s);
     b = (value <= maxValue && value >= minValue);
   } catch (NumberFormatException e) {
   }
   return b;
 }
Exemplo n.º 5
0
  /*.................................................................................................................*/
  public void processSingleXMLPreference(String tag, String content) {
    if ("bootStrapReps".equalsIgnoreCase(tag)) bootstrapreps = MesquiteInteger.fromString(content);
    if ("mxram".equalsIgnoreCase(tag)) mxram = MesquiteInteger.fromString(content);
    if ("convertGapsToMissing".equalsIgnoreCase(tag))
      convertGapsToMissing = MesquiteBoolean.fromTrueFalseString(content);
    if ("resamplingAllConsensusTrees".equalsIgnoreCase(tag))
      resamplingAllConsensusTrees = MesquiteBoolean.fromTrueFalseString(content);
    if ("harvestOnlyStrictConsensus".equalsIgnoreCase(tag))
      harvestOnlyStrictConsensus = MesquiteBoolean.fromTrueFalseString(content);
    if ("searchStyle".equalsIgnoreCase(tag)) searchStyle = MesquiteInteger.fromString(content);
    if ("searchArguments".equalsIgnoreCase(tag))
      searchArguments = StringUtil.cleanXMLEscapeCharacters(content);
    if ("bootstrapSearchArguments".equalsIgnoreCase(tag))
      bootstrapSearchArguments = StringUtil.cleanXMLEscapeCharacters(content);
    if ("otherOptions".equalsIgnoreCase(tag))
      otherOptions = StringUtil.cleanXMLEscapeCharacters(content);

    // parallel, etc.
    preferencesSet = true;
  }
  /*.................................................................................................................*/
  public void processSingleXMLPreference(String tag, String content) {

    if ("availMemory".equalsIgnoreCase(tag)) availMemory = MesquiteInteger.fromString(content);
    super.processSingleXMLPreference(tag, content);
  }
Exemplo n.º 7
0
  private boolean recalcPositions(Graphics g) {
    Font f = g.getFont();
    if (f != oldFont || !(StringUtil.stringsEqual(oldText, text))) {
      FontMetrics fm = g.getFontMetrics(f);
      sw = MesquiteInteger.maximum(fm.stringWidth("888"), fm.stringWidth(tf.getText()));
      sh = fm.getMaxAscent() + fm.getMaxDescent();
    }
    oldText = text;
    oldFont = f;
    if (oldTextBoxWidth < sw + MesquiteModule.textEdgeCompensationWidth - 1
        || oldTextBoxHeight < sh + MesquiteModule.textEdgeCompensationHeight - 1) {
      textBoxWidth = sw + MesquiteModule.textEdgeCompensationWidth; // 34
      textBoxHeight = sh + MesquiteModule.textEdgeCompensationHeight; // 18
      oldTextBoxWidth = textBoxWidth;
      oldTextBoxHeight = textBoxHeight;
      if (horizontal) {
        if (stacked) {
          totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 20;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          tf.setLocation(0, 0);
          decrementButton.setLocation(2, textBoxHeight + 4);
          incrementButton.setLocation(totalWidth - 20, textBoxHeight + 4);
        } else {
          totalWidth = textBoxWidth + 36 + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 4;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          decrementButton.setLocation(0, 2);
          tf.setLocation(
              decrementButton.getBounds().x + decrementButton.getBounds().width + 1,
              0); // 1 added to x
          incrementButton.setLocation(
              tf.getBounds().x + tf.getBounds().width + EnterButton.MIN_DIMENSION + 2,
              2); // 1 added to x
        }
        enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2);
      } else {
        if (stacked) {
          totalWidth = textBoxWidth + EnterButton.MIN_DIMENSION + 2;
          totalHeight = textBoxHeight + 20;
          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          tf.setLocation(0, 0);
          decrementButton.setLocation(2, textBoxHeight + 4);
          incrementButton.setLocation(totalWidth - 22, textBoxHeight + 4);
          enterButton.setLocation(tf.getBounds().x + tf.getBounds().width + 1, 2);
        } else {
          totalWidth = textBoxWidth; // should be 0
          totalHeight = textBoxHeight + 36 + EnterButton.MIN_DIMENSION + 2;

          setSize(totalWidth, totalHeight);
          tf.setSize(textBoxWidth, textBoxHeight);
          incrementButton.setLocation(1, 2);
          tf.setLocation(0, incrementButton.getBounds().height + 3);
          decrementButton.setLocation(
              1, tf.getBounds().y + tf.getBounds().height + EnterButton.MIN_DIMENSION + 2);
          enterButton.setLocation(1, tf.getBounds().y + tf.getBounds().height + 1);
        }
      }
      incrementButton.repaint();
      decrementButton.repaint();
      enterButton.repaint();
      repaint();
      getParent().repaint();
      return true;
    }
    if (checkBackground()) {
      repaint();
      return true;
    }
    /*	if (!getBackground().equals(getParent().getBackground())) {
    	bg =getParent().getBackground();
    	setBackground(bg);
    	//setBackground(Color.green);
    	tf.setBackground(bg);
    	decrementButton.setBackground(bg);
    	incrementButton.setBackground(bg);
    	enterButton.setBackground(bg);
    	repaint();
    	return true;
    }*/
    return false;
  }
Exemplo n.º 8
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 + ") ***");
    }
  }
Exemplo n.º 9
0
  public boolean queryOptions() {
    if (!okToInteractWithUser(
        CAN_PROCEED_ANYWAY,
        "Querying Options")) // Debugg.println needs to check that options set well enough to
                             // proceed anyway
    return true;
    boolean closeWizard = false;

    if ((MesquiteTrunk.isMacOSXBeforeSnowLeopard()) && MesquiteDialog.currentWizard == null) {
      CommandRecord cRec = null;
      cRec = MesquiteThread.getCurrentCommandRecordDefIfNull(null);
      if (cRec != null) {
        cRec.requestEstablishWizard(true);
        closeWizard = true;
      }
    }

    MesquiteInteger buttonPressed = new MesquiteInteger(1);

    queryOptionsDialog =
        new ExtensibleDialog(
            containerOfModule(),
            "TNT Options & Locations",
            buttonPressed); // MesquiteTrunk.mesquiteTrunk.containerOfModule()
    //		queryOptionsDialog.addLabel("TNT - Options and Locations");
    String helpString =
        "This module will prepare a matrix for TNT, and ask TNT do to an analysis.  A command-line version of TNT must be installed. "
            + "You can ask it to do a bootstrap analysis or not. "
            + "Mesquite will read in the trees found by TNT. ";

    queryOptionsDialog.appendToHelpString(helpString);
    queryOptionsDialog.setHelpURL(zephyrRunnerEmployer.getProgramURL());

    MesquiteTabbedPanel tabbedPanel = queryOptionsDialog.addMesquiteTabbedPanel();

    tabbedPanel.addPanel("TNT Program Details", true);
    externalProcRunner.addItemsToDialogPanel(queryOptionsDialog);
    Checkbox parallelCheckBox =
        queryOptionsDialog.addCheckBox("use PVM for parallel processing", parallel);
    parallelCheckBox.addItemListener(this);
    IntegerField slavesField =
        queryOptionsDialog.addIntegerField(
            "Number of Slaves", numSlaves, 4, 0, MesquiteInteger.infinite);
    IntegerField maxRamField =
        queryOptionsDialog.addIntegerField("mxram value", mxram, 4, 0, MesquiteInteger.infinite);

    tabbedPanel.addPanel("Search Options", true);
    Choice searchStyleChoice = null;
    if (bootstrapAllowed)
      searchStyleChoice =
          queryOptionsDialog.addPopUpMenu(
              "Type of search/resampling:",
              new String[] {
                "Regular Search",
                "Bootstrap",
                "Jackknife",
                "Symmetric Resampled",
                "Poisson Bootstrap"
              },
              searchStyle);
    queryOptionsDialog.addLabel("Regular Search Commands");
    searchField = queryOptionsDialog.addTextAreaSmallFont(searchArguments, 7, 80);
    searchScriptPathField =
        queryOptionsDialog.addTextField(
            "Path to TNT run file containing search commands", searchScriptPath, 40);
    Button browseSearchScriptPathButton =
        queryOptionsDialog.addAListenedButton("Browse...", null, this);
    browseSearchScriptPathButton.setActionCommand("browseSearchScript");
    harvestOnlyStrictConsensusBox =
        queryOptionsDialog.addCheckBox("only acquire strict consensus", harvestOnlyStrictConsensus);
    queryOptionsDialog.addHorizontalLine(1);
    //		Checkbox doBootstrapBox = queryOptionsDialog.addCheckBox("do bootstrapping", doBootstrap);
    if (bootstrapAllowed) {
      bootStrapRepsField =
          queryOptionsDialog.addIntegerField(
              "Resampling Replicates", bootstrapreps, 8, 0, MesquiteInteger.infinite);
      queryOptionsDialog.addLabel("Resampling Search Commands");
      bootstrapSearchField =
          queryOptionsDialog.addTextAreaSmallFont(bootstrapSearchArguments, 7, 80);
      bootSearchScriptPathField =
          queryOptionsDialog.addTextField(
              "Path to TNT run file containing search commands for resampled",
              bootSearchScriptPath,
              30);
      Button browseBootSearchScriptPathButton =
          queryOptionsDialog.addAListenedButton("Browse...", null, this);
      browseSearchScriptPathButton.setActionCommand("browseBootSearchScript");
      resamplingAllConsensusTreesBox =
          queryOptionsDialog.addCheckBox(
              "allow TNT to calculate consensus tree", !resamplingAllConsensusTrees);
    }

    adjustDialogText();
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addNewDialogPanel();
    useDefaultsButton = queryOptionsDialog.addAListenedButton("Set to Defaults", null, this);
    useDefaultsButton.setActionCommand("setToDefaults");

    tabbedPanel.addPanel("Other Options", true);
    convertGapsBox =
        queryOptionsDialog.addCheckBox(
            "convert gaps to missing (to avoid gap=extra state)", convertGapsToMissing);
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addLabel("Post-Search TNT Commands");
    otherOptionsField = queryOptionsDialog.addTextAreaSmallFont(otherOptions, 7, 80);
    queryOptionsDialog.addHorizontalLine(1);
    queryOptionsDialog.addNewDialogPanel();
    useDefaultsOtherOptionsButton =
        queryOptionsDialog.addAListenedButton("Set to Defaults", null, this);
    useDefaultsOtherOptionsButton.setActionCommand("setToDefaultsOtherOptions");

    tabbedPanel.cleanup();
    queryOptionsDialog.nullifyAddPanel();

    queryOptionsDialog.completeAndShowDialog("Search", "Cancel", null, null);

    if (buttonPressed.getValue() == 0) {
      boolean infererOK = (treeInferer == null || treeInferer.optionsChosen());
      if (externalProcRunner.optionsChosen() && infererOK) {
        if (bootstrapAllowed) {
          bootstrapreps = bootStrapRepsField.getValue();
          bootstrapSearchArguments = bootstrapSearchField.getText();
          bootSearchScriptPath = bootSearchScriptPathField.getText();
          harvestOnlyStrictConsensus = harvestOnlyStrictConsensusBox.getState();
          resamplingAllConsensusTrees = !resamplingAllConsensusTreesBox.getState();
          searchStyle = searchStyleChoice.getSelectedIndex();
        }
        numSlaves = slavesField.getValue();
        otherOptions = otherOptionsField.getText();
        convertGapsToMissing = convertGapsBox.getState();
        parallel = parallelCheckBox.getState();
        //				doBootstrap = doBootstrapBox.getState();
        searchArguments = searchField.getText();
        searchScriptPath = searchScriptPathField.getText();
        mxram = maxRamField.getValue();

        storeRunnerPreferences();
      }
    }
    queryOptionsDialog.dispose();
    if (closeWizard) MesquiteDialog.closeWizard();

    return (buttonPressed.getValue() == 0);
  }
Exemplo n.º 10
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");
    }
  }