예제 #1
0
 public void setValueAt(Object aValue, int row, int col) {
   //            PartitionData partition = options.getPartitionDataNoSpecies().get(row);
   PartitionData partition = options.getNonTraitsDataList().get(row);
   switch (col) {
     case 0:
       String name = ((String) aValue).trim();
       if (name.length() > 0) {
         partition.setName(name);
       }
       break;
     case 5:
       //                    partition.setPloidyType((PloidyType) aValue);
       //                    break;
       //                case 6:
       partition.setPartitionSubstitutionModel((PartitionSubstitutionModel) aValue);
       break;
     case 6:
       partition.setPartitionClockModel((PartitionClockModel) aValue);
       break;
     case 7:
       partition.setPartitionTreeModel((PartitionTreeModel) aValue);
       break;
   }
   fireDataChanged();
 }
예제 #2
0
  public void linkClocks() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }
    Object[] modelArray = options.getPartitionClockModels(selectedPartitionData).toArray();

    if (selectClockDialog == null) {
      selectClockDialog = new SelectClockDialog(frame);
    }

    int result = selectClockDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionClockModel model = selectClockDialog.getModel();
      if (selectClockDialog.getMakeCopy()) {
        model.setName(selectClockDialog.getName());
      }

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionClockModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
예제 #3
0
  public void unlinkTrees() { // reuse previous PartitionTreePrior
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionTreeModel model = partition.getPartitionTreeModel();
      if (!model.getName().equals(partition.getName())
          && partition.getTraitType() == null) { // not a trait
        PartitionTreeModel newTree = new PartitionTreeModel(options, partition);

        // this prevents partition not broken, and used for unsharing tree prior only,
        // because sharing uses shareSameTreePrior, unsharing uses getPartitionTreePrior
        //                newTree.setPartitionTreePrior(newPrior); // important

        partition.setPartitionTreeModel(newTree);
      }
    }

    options.linkTreePriors(frame.getCurrentPartitionTreePrior());

    modelsChanged();

    fireDataChanged();
    options.taxonSets.clear();
    options.taxonSetsMono.clear();
    repaint();
  }
예제 #4
0
 public Object getValueAt(int row, int col) {
   //            PartitionData partition = options.getPartitionDataNoSpecies().get(row);
   PartitionData partition = options.getNonTraitsDataList().get(row);
   switch (col) {
     case 0:
       return partition.getName();
     case 1:
       return partition.getFileName();
     case 2:
       return "" + partition.getTaxaCount();
     case 3:
       return "" + partition.getSiteCount(); // sequence length
     case 4:
       return partition.getDataType();
     case 5:
       //                    return partition.getPloidyType();
       //                case 6:
       return partition.getPartitionSubstitutionModel().getName();
     case 6:
       return partition.getPartitionClockModel().getName();
     case 7:
       return partition.getPartitionTreeModel().getName();
     default:
       throw new IllegalArgumentException("unknown column, " + col);
   }
 }
예제 #5
0
  public void linkTrees() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    if (options.allowDifferentTaxa) { // BEAST cannot handle multi <taxa> ref for 1 tree
      if (selectedPartitionData.size() > 1) {
        if (!options.validateDiffTaxa(selectedPartitionData)) {
          JOptionPane.showMessageDialog(
              this,
              "To accommodate different taxa for each partition trees cannot be linked.",
              "Illegal Configuration",
              JOptionPane.ERROR_MESSAGE);
          return;
        }
      }
    }

    Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray();

    if (selectTreeDialog == null) {
      selectTreeDialog = new SelectTreeDialog(frame);
    }

    int result = selectTreeDialog.showDialog(treeArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionTreeModel model = selectTreeDialog.getTree();
      if (selectTreeDialog.getMakeCopy()) {
        model.setName(selectTreeDialog.getName());
      }
      PartitionTreePrior prior = model.getPartitionTreePrior();
      options.linkTreePriors(prior);

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionTreeModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    options.taxonSets.clear();
    options.taxonSetsMono.clear();
    repaint();
  }
예제 #6
0
  public void unlinkClocks() { // reuse previous PartitionTreePrior
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionClockModel model = partition.getPartitionClockModel();
      if (!model.getName().equals(partition.getName())) {
        PartitionClockModel newModel = new PartitionClockModel(options, partition);
        partition.setPartitionClockModel(newModel);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
예제 #7
0
  public void linkModels() {
    int[] selRows = dataTable.getSelectedRows();
    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    DataType dateType = null;
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);
      if (dateType == null) {
        dateType = partition.getPartitionSubstitutionModel().getDataType();
      } else {
        if (partition.getPartitionSubstitutionModel().getDataType() != dateType) {
          JOptionPane.showMessageDialog(
              this,
              "Can only link the models for data partitions \n"
                  + "of the same data type (e.g., nucleotides)",
              "Unable to link models",
              JOptionPane.ERROR_MESSAGE);
        }
      }

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    Object[] modelArray =
        options.getPartitionSubstitutionModels(dateType, selectedPartitionData).toArray();

    if (selectModelDialog == null) {
      selectModelDialog = new SelectModelDialog(frame);
    }

    int result = selectModelDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionSubstitutionModel model = selectModelDialog.getModel();
      if (selectModelDialog.getMakeCopy()) {
        model.setName(selectModelDialog.getName());
      }

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionSubstitutionModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
예제 #8
0
  public void unlinkModels() {
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionSubstitutionModel model = partition.getPartitionSubstitutionModel();
      if (!model.getName().equals(partition.getName())) {
        PartitionSubstitutionModel newModel = new PartitionSubstitutionModel(options, partition);
        partition.setPartitionSubstitutionModel(newModel);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
예제 #9
0
  private void showAlignment() {

    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      JFrame frame = new JFrame();
      frame.setSize(800, 600);

      PartitionData partition = options.dataPartitions.get(row);
      Alignment alignment = partition.getAlignment();

      // alignment == null if partition is trait
      // http://code.google.com/p/beast-mcmc/issues/detail?id=343
      if (alignment == null) {
        JOptionPane.showMessageDialog(
            this,
            "Cannot display traits currently. Use the traits panel to view and edit these.",
            "Illegal Argument Exception",
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      AlignmentViewer viewer = new AlignmentViewer();
      if (alignment.getDataType().getType() == DataType.NUCLEOTIDES) {
        viewer.setCellDecorator(new StateCellDecorator(new NucleotideDecorator(), false));
      } else if (alignment.getDataType().getType() == DataType.AMINO_ACIDS) {
        viewer.setCellDecorator(new StateCellDecorator(new AminoAcidDecorator(), false));
      } else {
        // no colouring
      }
      viewer.setAlignmentBuffer(new BeautiAlignmentBuffer(alignment));

      JPanel panel = new JPanel(new BorderLayout());
      panel.setOpaque(false);
      panel.add(viewer, BorderLayout.CENTER);

      JPanel infoPanel = new JPanel(new BorderLayout());
      infoPanel.setOpaque(false);
      panel.add(infoPanel, BorderLayout.SOUTH);

      frame.setContentPane(panel);
      frame.setVisible(true);
    }
  }
예제 #10
0
  /**
   * write tree log to file
   *
   * @param writer XMLWriter
   */
  public void writeTreeLogToFile(XMLWriter writer) {
    writer.writeComment("write tree log to file");

    if (options.useStarBEAST) { // species
      // species tree log
      writer.writeOpenTag(
          TreeLoggerParser.LOG_TREE,
          new Attribute[] {
            new Attribute.Default<String>(
                XMLParser.ID, TraitData.TRAIT_SPECIES + "." + TREE_FILE_LOG), // speciesTreeFileLog
            new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY, options.logEvery + ""),
            new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT, "true"),
            new Attribute.Default<String>(
                TreeLoggerParser.FILE_NAME,
                options.fileNameStem + "." + options.starBEASTOptions.SPECIES_TREE_FILE_NAME),
            new Attribute.Default<String>(TreeLoggerParser.SORT_TRANSLATION_TABLE, "true")
          });

      writer.writeIDref(SpeciesTreeModelParser.SPECIES_TREE, SP_TREE);

      if (options.hasData()) {
        // we have data...
        writer.writeIDref("posterior", "posterior");
      }
      writer.writeCloseTag(TreeLoggerParser.LOG_TREE);
    }

    // gene tree log
    // TODO make code consistent to MCMCPanel
    for (PartitionTreeModel tree : options.getPartitionTreeModels()) {
      String treeFileName;
      if (options.substTreeLog) {
        treeFileName =
            options.fileNameStem
                + "."
                + tree.getPrefix()
                + "(time)."
                + STARBEASTOptions.TREE_FILE_NAME;
      } else {
        treeFileName =
            options.fileNameStem
                + "."
                + tree.getPrefix()
                + STARBEASTOptions.TREE_FILE_NAME; // stem.partitionName.tree
      }

      if (options.treeFileName.get(0).endsWith(".txt")) {
        treeFileName += ".txt";
      }

      List<Attribute> attributes = new ArrayList<Attribute>();

      attributes.add(
          new Attribute.Default<String>(
              XMLParser.ID, tree.getPrefix() + TREE_FILE_LOG)); // partionName.treeFileLog
      attributes.add(
          new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY, options.logEvery + ""));
      attributes.add(new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT, "true"));
      attributes.add(new Attribute.Default<String>(TreeLoggerParser.FILE_NAME, treeFileName));
      attributes.add(
          new Attribute.Default<String>(TreeLoggerParser.SORT_TRANSLATION_TABLE, "true"));

      // if (options.clockModelOptions.getRateOptionClockModel() == FixRateType.RElATIVE_TO &&
      // tree.containsUncorrelatedRelaxClock()) { //TODO: Sibon's discretized branch length stuff
      //    double aveFixedRate =
      // options.clockModelOptions.getSelectedRate(options.getPartitionClockModels());
      //    attributes.add(new Attribute.Default<String>(TreeLoggerParser.NORMALISE_MEAN_RATE_TO,
      // Double.toString(aveFixedRate)));
      // }

      // generate <logTree>
      writer.writeOpenTag(TreeLoggerParser.LOG_TREE, attributes);

      //            writer.writeOpenTag(TreeLoggerParser.LOG_TREE,
      //                    new Attribute[]{
      //                            new Attribute.Default<String>(XMLParser.ID, tree.getPrefix() +
      // TREE_FILE_LOG), // partionName.treeFileLog
      //                            new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY,
      // options.logEvery + ""),
      //                            new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT,
      // "true"),
      //                            new Attribute.Default<String>(TreeLoggerParser.FILE_NAME,
      // treeFileName),
      //                            new
      // Attribute.Default<String>(TreeLoggerParser.SORT_TRANSLATION_TABLE, "true")
      //                    });

      writer.writeIDref(TreeModel.TREE_MODEL, tree.getPrefix() + TreeModel.TREE_MODEL);

      for (PartitionClockModel model :
          options.getPartitionClockModels(options.getAllPartitionData(tree))) {
        if (options.getAllPartitionData(model).get(0).getTraitType() == null) {
          switch (model.getClockType()) {
            case STRICT_CLOCK:
              writer.writeIDref(
                  StrictClockBranchRatesParser.STRICT_CLOCK_BRANCH_RATES,
                  model.getPrefix() + BranchRateModel.BRANCH_RATES);
              break;

            case UNCORRELATED_EXPONENTIAL:
            case UNCORRELATED_LOGNORMAL:
              writer.writeIDref(
                  DiscretizedBranchRatesParser.DISCRETIZED_BRANCH_RATES,
                  options.noDuplicatedPrefix(model.getPrefix(), tree.getPrefix())
                      + BranchRateModel.BRANCH_RATES);
              break;

            case RANDOM_LOCAL_CLOCK:
              writer.writeIDref(
                  RandomLocalClockModelParser.LOCAL_BRANCH_RATES,
                  model.getPrefix() + BranchRateModel.BRANCH_RATES);
              break;

            case AUTOCORRELATED_LOGNORMAL:
              writer.writeIDref(
                  ACLikelihoodParser.AC_LIKELIHOOD,
                  options.noDuplicatedPrefix(model.getPrefix(), tree.getPrefix())
                      + BranchRateModel.BRANCH_RATES);
              break;

            default:
              throw new IllegalArgumentException("Unknown clock model");
          }
        }
      }

      if (options.hasData()) {
        // we have data...
        writer.writeIDref("posterior", "posterior");
      }

      if (options.hasDiscreteIntegerTraitsExcludeSpecies()) {
        for (PartitionData partitionData :
            options.getAllPartitionData(
                tree)) { // Each TD except Species has one AncestralTreeLikelihood
          if (partitionData.getTraitType() != null
              && (!partitionData.getName().equalsIgnoreCase(TraitData.TRAIT_SPECIES.toString())))
            writer.writeIDref(
                AncestralStateTreeLikelihoodParser.RECONSTRUCTING_TREE_LIKELIHOOD,
                partitionData.getPrefix() + TreeLikelihoodParser.TREE_LIKELIHOOD);
        }
      }

      writer.writeCloseTag(TreeLoggerParser.LOG_TREE);
    } // end For loop

    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TREES_LOG, writer);

    if (options.substTreeLog) {
      if (options.useStarBEAST) { // species
        // TODO: species sub tree
      }

      // gene tree
      for (PartitionTreeModel tree : options.getPartitionTreeModels()) {
        // write tree log to file
        writer.writeOpenTag(
            TreeLoggerParser.LOG_TREE,
            new Attribute[] {
              new Attribute.Default<String>(XMLParser.ID, tree.getPrefix() + SUB_TREE_FILE_LOG),
              new Attribute.Default<String>(TreeLoggerParser.LOG_EVERY, options.logEvery + ""),
              new Attribute.Default<String>(TreeLoggerParser.NEXUS_FORMAT, "true"),
              new Attribute.Default<String>(
                  TreeLoggerParser.FILE_NAME,
                  options.fileNameStem
                      + "."
                      + tree.getPrefix()
                      + "(subst)."
                      + STARBEASTOptions.TREE_FILE_NAME),
              new Attribute.Default<String>(
                  TreeLoggerParser.BRANCH_LENGTHS, TreeLoggerParser.SUBSTITUTIONS)
            });
        writer.writeIDref(TreeModel.TREE_MODEL, tree.getPrefix() + TreeModel.TREE_MODEL);

        for (PartitionClockModel model :
            options.getPartitionClockModels(options.getAllPartitionData(tree))) {
          if (options.getAllPartitionData(model).get(0).getTraitType() == null) {
            switch (model.getClockType()) {
              case STRICT_CLOCK:
                writer.writeIDref(
                    StrictClockBranchRatesParser.STRICT_CLOCK_BRANCH_RATES,
                    model.getPrefix() + BranchRateModel.BRANCH_RATES);
                break;

              case UNCORRELATED_EXPONENTIAL:
              case UNCORRELATED_LOGNORMAL:
                writer.writeIDref(
                    DiscretizedBranchRatesParser.DISCRETIZED_BRANCH_RATES,
                    options.noDuplicatedPrefix(model.getPrefix(), tree.getPrefix())
                        + BranchRateModel.BRANCH_RATES);
                break;

              case RANDOM_LOCAL_CLOCK:
                writer.writeIDref(
                    RandomLocalClockModelParser.LOCAL_BRANCH_RATES,
                    model.getPrefix() + BranchRateModel.BRANCH_RATES);
                break;

              case AUTOCORRELATED_LOGNORMAL:
                writer.writeIDref(
                    ACLikelihoodParser.AC_LIKELIHOOD,
                    options.noDuplicatedPrefix(model.getPrefix(), tree.getPrefix())
                        + BranchRateModel.BRANCH_RATES);
                break;

              default:
                throw new IllegalArgumentException("Unknown clock model");
            }
          }
        }

        writer.writeCloseTag(TreeLoggerParser.LOG_TREE);
      }
    }

    generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_TREES_LOG, writer);
  }