Exemplo n.º 1
0
    def add_state_nodes(self, beastxml):
        """
        Add tree-related <state> sub-elements.
        """
        state = beastxml.state
        self.tree = xml.tree(state, id=self.tree_id, name="stateNode")
        xml.taxonset(self.tree, idref="taxa")
        if self.type in ["yule", "birthdeath"]:
            param = xml.parameter(state,
                                  id="birthRate.t:beastlingTree",
                                  name="stateNode")
            if self.birthrate_estimate is not None:
                param.text = str(self.birthrate_estimate)
            else:
                param.text = "1.0"
            if self.type in ["birthdeath"]:
                xml.parameter(beastxml.state,
                              text="0.5",
                              id="deathRate.t:beastlingTree",
                              name="stateNode")
                xml.parameter(beastxml.state,
                              text="0.2",
                              id="sampling.t:beastlingTree",
                              name="stateNode")

        elif self.type == "coalescent":
            xml.parameter(beastxml.state,
                          text="1.0",
                          id="popSize.t:beastlingTree",
                          name="stateNode")
        if beastxml.config.tip_calibrations:
            self.add_tip_heights(beastxml.config.tip_calibrations)
Exemplo n.º 2
0
 def add_state_nodes(self, beastxml):
     """
     Add tree-related <state> sub-elements.
     """
     state = beastxml.state
     self.tree = xml.tree(state, id=self.tree_id, name="stateNode")
     xml.taxonset(self.tree, idref="taxa")
     if beastxml.config.tip_calibrations:
         self.add_tip_heights(beastxml.config.tip_calibrations)
Exemplo n.º 3
0
    def add_taxon_set(self, parent, label, langs, define_taxa=False):
        """
        Add a TaxonSet element with the specified set of languages.

        If a TaxonSet previously defined by this method contains exactly the
        same set of taxa, a reference to that TaxonSet will be added instead.
        By default, each TaxonSet will contain references to the taxa,
        assuming that they have been defined previously (most probably in the
        definition of the tree).  If this is not the case, passing
        define_taxa=True will define, rather than refer to, the taxa.
        """
        # Kill duplicates
        langs = sorted(list(set(langs)))

        # If we've been asked to build an emtpy TaxonSet, something is very wrong,
        # so better to die loud and early
        assert langs
        # Refer to any previous TaxonSet with the same languages
        for idref, taxa in self._taxon_sets.items():
            if langs == taxa:
                xml.taxonset(parent, idref=idref)
                return
        if len(langs) == 1 and label == langs[0]:
            # Single taxa are IDs already. They cannot also be taxon set ids.
            label = "tx_{:}".format(label)
        # Otherwise, create and register a new TaxonSet
        taxonset = xml.taxonset(parent, id=label, spec="TaxonSet")
        ## If the taxonset is more than 3 languages in size, use plate notation to minimise XML filesize
        if len(langs) > 3:
            xml.taxon(xml.plate(taxonset, var="language", range=langs),
                      attrib={"id" if define_taxa else "idref": "$(language)"})
        ## Otherwise go for the more readable notation...
        else:
            for lang in langs:
                xml.taxon(taxonset,
                          attrib={"id" if define_taxa else "idref": lang})
        self._taxon_sets[label] = langs