Ejemplo n.º 1
0
  public void writeAdditionalLogToFile(
      XMLWriter writer,
      BranchRatesModelGenerator branchRatesModelGenerator,
      SubstitutionModelGenerator substitutionModelGenerator) {
    if (options.hasDiscreteIntegerTraitsExcludeSpecies()) {
      writer.writeComment("write rate matrix log to file");

      String fileName =
          options.logFileName.substring(0, options.logFileName.indexOf(".log")) + "_rateMatrix.log";
      writer.writeOpenTag(
          LoggerParser.LOG,
          new Attribute[] {
            new Attribute.Default<String>(XMLParser.ID, "rateMatrixLog"),
            new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""),
            new Attribute.Default<String>(LoggerParser.FILE_NAME, fileName)
          });

      for (PartitionSubstitutionModel model : options.getPartitionTraitsSubstitutionModels()) {
        substitutionModelGenerator.writeRateLog(model, writer);
      }

      for (PartitionClockModel model : options.getPartitionTraitsClockModels()) {
        branchRatesModelGenerator.writeLog(model, writer);
      }

      writer.writeCloseTag(LoggerParser.LOG);
    }
  }
Ejemplo n.º 2
0
  /**
   * write log to screen
   *
   * @param writer XMLWriter
   * @param branchRatesModelGenerator BranchRatesModelGenerator
   */
  public void writeLogToScreen(
      XMLWriter writer,
      BranchRatesModelGenerator branchRatesModelGenerator,
      SubstitutionModelGenerator substitutionModelGenerator) {
    writer.writeComment("write log to screen");

    writer.writeOpenTag(
        LoggerParser.LOG,
        new Attribute[] {
          new Attribute.Default<String>(XMLParser.ID, "screenLog"),
          new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.echoEvery + "")
        });

    if (options.hasData()) {
      writer.writeOpenTag(
          ColumnsParser.COLUMN,
          new Attribute[] {
            new Attribute.Default<String>(ColumnsParser.LABEL, "Posterior"),
            new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"),
            new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
          });
      writer.writeIDref(CompoundLikelihoodParser.POSTERIOR, "posterior");
      writer.writeCloseTag(ColumnsParser.COLUMN);
    }

    writer.writeOpenTag(
        ColumnsParser.COLUMN,
        new Attribute[] {
          new Attribute.Default<String>(ColumnsParser.LABEL, "Prior"),
          new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"),
          new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
        });
    writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior");
    writer.writeCloseTag(ColumnsParser.COLUMN);

    if (options.hasData()) {
      writer.writeOpenTag(
          ColumnsParser.COLUMN,
          new Attribute[] {
            new Attribute.Default<String>(ColumnsParser.LABEL, "Likelihood"),
            new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"),
            new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
          });
      writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood");
      writer.writeCloseTag(ColumnsParser.COLUMN);
    }

    if (options.useStarBEAST) { // species
      writer.writeOpenTag(
          ColumnsParser.COLUMN,
          new Attribute[] {
            new Attribute.Default<String>(ColumnsParser.LABEL, "PopMean"),
            new Attribute.Default<String>(ColumnsParser.DECIMAL_PLACES, "4"),
            new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
          });
      writer.writeIDref(
          ParameterParser.PARAMETER,
          TraitData.TRAIT_SPECIES + "." + options.starBEASTOptions.POP_MEAN);
      writer.writeCloseTag(ColumnsParser.COLUMN);
    }

    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
      writer.writeOpenTag(
          ColumnsParser.COLUMN,
          new Attribute[] {
            new Attribute.Default<String>(
                ColumnsParser.LABEL, model.getPrefix() + TreeModelParser.ROOT_HEIGHT),
            new Attribute.Default<String>(ColumnsParser.SIGNIFICANT_FIGURES, "6"),
            new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
          });

      writer.writeIDref(
          ParameterParser.PARAMETER,
          model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT);

      writer.writeCloseTag(ColumnsParser.COLUMN);
    }

    for (PartitionClockModel model : options.getPartitionClockModels()) {
      writer.writeOpenTag(
          ColumnsParser.COLUMN,
          new Attribute[] {
            new Attribute.Default<String>(
                ColumnsParser.LABEL, branchRatesModelGenerator.getClockRateString(model)),
            new Attribute.Default<String>(ColumnsParser.SIGNIFICANT_FIGURES, "6"),
            new Attribute.Default<String>(ColumnsParser.WIDTH, "12")
          });

      branchRatesModelGenerator.writeAllClockRateRefs(model, writer);
      //        if (options.clockModelOptions.getRateOptionClockModel() == FixRateType.FIX_MEAN) {
      //            writer.writeIDref(ParameterParser.PARAMETER, "allClockRates");
      //            for (PartitionClockModel model : options.getPartitionClockModels()) {
      //                if (model.getClockType() == ClockType.UNCORRELATED_LOGNORMAL)
      //                    writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() +
      // ClockType.UCLD_STDEV);
      //            }
      //        } else {
      //            for (PartitionClockModel model : options.getPartitionClockModels()) {
      //                branchRatesModelGenerator.writeAllClockRateRefs(model, writer);
      //            }
      //        }
      writer.writeCloseTag(ColumnsParser.COLUMN);
    }

    if (options.hasDiscreteIntegerTraitsExcludeSpecies()) {
      for (PartitionSubstitutionModel model : options.getPartitionTraitsSubstitutionModels()) {
        substitutionModelGenerator.writeStatisticLog(model, writer);
      }
    }

    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_SCREEN_LOG, writer);

    writer.writeCloseTag(LoggerParser.LOG);

    generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_SCREEN_LOG, writer);
  }
Ejemplo n.º 3
0
  /**
   * write log to file
   *
   * @param writer XMLWriter
   * @param treePriorGenerator TreePriorGenerator
   * @param branchRatesModelGenerator BranchRatesModelGenerator
   * @param substitutionModelGenerator SubstitutionModelGenerator
   * @param treeLikelihoodGenerator TreeLikelihoodGenerator
   * @param generalTraitGenerator
   */
  public void writeLogToFile(
      XMLWriter writer,
      TreePriorGenerator treePriorGenerator,
      BranchRatesModelGenerator branchRatesModelGenerator,
      SubstitutionModelGenerator substitutionModelGenerator,
      TreeLikelihoodGenerator treeLikelihoodGenerator,
      GeneralTraitGenerator generalTraitGenerator) {
    writer.writeComment("write log to file");

    if (options.logFileName == null) {
      options.logFileName = options.fileNameStem + ".log";
    }
    writer.writeOpenTag(
        LoggerParser.LOG,
        new Attribute[] {
          new Attribute.Default<String>(XMLParser.ID, "fileLog"),
          new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""),
          new Attribute.Default<String>(LoggerParser.FILE_NAME, options.logFileName),
          new Attribute.Default<Boolean>(
              LoggerParser.ALLOW_OVERWRITE_LOG, options.allowOverwriteLog)
        });

    if (options.hasData()) {
      writer.writeIDref(CompoundLikelihoodParser.POSTERIOR, "posterior");
    }
    writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior");
    if (options.hasData()) {
      writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood");
    }

    if (options.useStarBEAST) { // species
      // coalescent prior
      writer.writeIDref(
          MultiSpeciesCoalescentParser.SPECIES_COALESCENT,
          TraitData.TRAIT_SPECIES + "." + COALESCENT);
      // prior on population sizes
      //            if (options.speciesTreePrior == TreePriorType.SPECIES_YULE) {
      writer.writeIDref(MixedDistributionLikelihoodParser.DISTRIBUTION_LIKELIHOOD, SPOPS);
      //            } else {
      //                writer.writeIDref(SpeciesTreeBMPrior.STPRIOR, STP);
      //            }
      // prior on species tree
      writer.writeIDref(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, SPECIATION_LIKE);

      writer.writeIDref(
          ParameterParser.PARAMETER,
          TraitData.TRAIT_SPECIES + "." + options.starBEASTOptions.POP_MEAN);
      writer.writeIDref(
          ParameterParser.PARAMETER, SpeciesTreeModelParser.SPECIES_TREE + "." + SPLIT_POPS);

      if (options.getPartitionTreePriors().get(0).getNodeHeightPrior()
          == TreePriorType.SPECIES_BIRTH_DEATH) {
        writer.writeIDref(
            ParameterParser.PARAMETER,
            TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME);
        writer.writeIDref(
            ParameterParser.PARAMETER,
            TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME);
      } else if (options.getPartitionTreePriors().get(0).getNodeHeightPrior()
          == TreePriorType.SPECIES_YULE) {
        writer.writeIDref(
            ParameterParser.PARAMETER,
            TraitData.TRAIT_SPECIES
                + "."
                + YuleModelParser.YULE
                + "."
                + YuleModelParser.BIRTH_RATE);
      } else {
        throw new IllegalArgumentException(
            "Get wrong species tree prior using *BEAST : "
                + options.getPartitionTreePriors().get(0).getNodeHeightPrior().toString());
      }

      // Species Tree: tmrcaStatistic
      writer.writeIDref(
          TMRCAStatisticParser.TMRCA_STATISTIC,
          SpeciesTreeModelParser.SPECIES_TREE + "." + TreeModelParser.ROOT_HEIGHT);
    }

    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
      writer.writeIDref(
          ParameterParser.PARAMETER,
          model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT);
    }

    for (Taxa taxa : options.taxonSets) {
      // make tmrca(tree.name) eay to read in log for Tracer
      writer.writeIDref(
          TMRCAStatisticParser.TMRCA_STATISTIC,
          "tmrca(" + taxa.getTreeModel().getPrefix() + taxa.getId() + ")");
    }

    //        if ( options.shareSameTreePrior ) { // Share Same Tree Prior
    //	        treePriorGenerator.setModelPrefix("");
    //        	treePriorGenerator.writeParameterLog(options.activedSameTreePrior, writer);
    //        } else { // no species
    for (PartitionTreePrior prior : options.getPartitionTreePriors()) {
      //	        	treePriorGenerator.setModelPrefix(prior.getPrefix()); // priorName.treeModel
      treePriorGenerator.writeParameterLog(prior, writer);
    }
    //	    }

    for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) {
      substitutionModelGenerator.writeLog(writer, model);
      if (model.hasCodon()) {
        writer.writeIDref(CompoundParameterParser.COMPOUND_PARAMETER, model.getPrefix() + "allMus");
      }
    }

    if (options.clockModelOptions.getRateOptionClockModel() == FixRateType.FIX_MEAN) {
      writer.writeIDref(ParameterParser.PARAMETER, "allClockRates");
      for (PartitionClockModel model : options.getPartitionClockModels()) {
        if (model.getClockType() == ClockType.UNCORRELATED_LOGNORMAL)
          writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + ClockType.UCLD_STDEV);
      }
    } else {
      for (PartitionClockModel model : options.getPartitionClockModels()) {
        branchRatesModelGenerator.writeLog(model, writer);
      }
    }

    for (PartitionClockModel model : options.getPartitionClockModels()) {
      branchRatesModelGenerator.writeLogStatistic(model, writer);
    }

    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_PARAMETERS, writer);

    if (options.hasData()) {
      treeLikelihoodGenerator.writeTreeLikelihoodReferences(writer);
    }

    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_LIKELIHOODS, writer);

    // coalescentLikelihood
    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
      PartitionTreePrior prior = model.getPartitionTreePrior();
      treePriorGenerator.writePriorLikelihoodReferenceLog(prior, model, writer);
      writer.writeText("");
    }

    for (PartitionTreePrior prior : options.getPartitionTreePriors()) {
      if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE)
        writer.writeIDref(
            CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD,
            prior.getPrefix() + COALESCENT); // only 1 coalescent
    }

    if (options.hasDiscreteIntegerTraitsExcludeSpecies()) {
      generalTraitGenerator.writeAncestralTreeLikelihoodReferences(writer);
    }

    writer.writeCloseTag(LoggerParser.LOG);

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