Ejemplo n.º 1
0
  protected BeagleTreeLikelihood createTreeLikelihood(
      PatternList patternList, //
      TreeModel treeModel, //
      BranchModel branchModel, //
      GammaSiteRateModel siteRateModel, //
      BranchRateModel branchRateModel, //
      TipStatesModel tipStatesModel, //
      boolean useAmbiguities, //
      PartialsRescalingScheme scalingScheme, //
      Map<
              Set<String>, //
              Parameter>
          partialsRestrictions, //
      XMLObject xo //
      ) throws XMLParseException {

    boolean integrateGainRate = xo.getBooleanAttribute(INTEGRATE_GAIN_RATE);

    useAmbiguities = true; // TODO No effect

    if (scalingScheme != PartialsRescalingScheme.NONE) {
      throw new XMLParseException(
          "No rescaling scheme is currently support by the mutation-death model " + xo.getId());
    }

    Parameter mu = ((MutationDeathModel) siteRateModel.getSubstitutionModel()).getDeathParameter();
    Parameter lam;
    if (!integrateGainRate) {
      lam = (Parameter) xo.getElementFirstChild(IMMIGRATION_RATE);
    } else {
      lam = new Parameter.Default("gainRate", 1.0, 0.001, 1.999);
    }
    AbstractObservationProcess observationProcess = null;

    Logger.getLogger("dr.evolution")
        .info("\n ---------------------------------\nCreating a BEAGLE ALSTreeLikelihood model.");
    for (int i = 0; i < xo.getChildCount(); ++i) {
      Object cxo = xo.getChild(i);
      if (cxo instanceof XMLObject && ((XMLObject) cxo).getName().equals(OBSERVATION_PROCESS)) {
        if (((XMLObject) cxo).getStringAttribute(OBSERVATION_TYPE).equals("singleTip")) {
          String taxonName = ((XMLObject) cxo).getStringAttribute(OBSERVATION_TAXON);
          Taxon taxon = treeModel.getTaxon(treeModel.getTaxonIndex(taxonName));
          observationProcess =
              new SingleTipObservationProcess(
                  treeModel, patternList, siteRateModel, branchRateModel, mu, lam, taxon);
          Logger.getLogger("dr.evolution").info("All traits are assumed extant in " + taxonName);
        } else { // "anyTip" observation process
          observationProcess =
              new AnyTipObservationProcess(
                  ANY_TIP, treeModel, patternList, siteRateModel, branchRateModel, mu, lam);
          Logger.getLogger("dr.evolution")
              .info("Observed traits are assumed to be extant in at least one tip node.");
        }

        observationProcess.setIntegrateGainRate(integrateGainRate);
      }
    }
    Logger.getLogger("dr.evolution")
        .info(
            "\tIf you publish results using Acquisition-Loss-Mutation (ALS) Model likelihood, please reference Alekseyenko, Lee and Suchard (2008) Syst. Biol 57: 772-784.\n---------------------------------\n");

    return new ALSBeagleTreeLikelihood(
        observationProcess,
        patternList,
        treeModel,
        branchModel,
        siteRateModel,
        branchRateModel,
        tipStatesModel,
        useAmbiguities,
        scalingScheme,
        partialsRestrictions);
  }