def add_operators(self, beastxml): xml.operator(beastxml.run, id="PopulationSizeScaler.t:beastlingTree", spec="ScaleOperator", parameter="@popSize.t:beastlingTree", scaleFactor="0.5", weight="3.0")
def add_operators(self, beastxml): if beastxml.config.languages.sample_branch_lengths: updown = xml.operator( beastxml.run, attrib={ "id": "UpDown", "spec": "UpDownOperator", "scaleFactor": "0.5", "weight": "3.0"}) xml.tree(updown, idref="Tree.t:beastlingTree", name="up") xml.parameter(updown, idref="birthRate.t:beastlingTree", name="down") ### Include clock rates in up/down only if calibrations are given if beastxml.config.calibrations: for clock in beastxml.config.clocks: if clock.estimate_rate: xml.parameter(updown, idref=clock.mean_rate_id, name="down") # Birth rate scaler # Birth rate is *always* scaled. xml.operator( beastxml.run, attrib={"id": "YuleBirthRateScaler.t:beastlingTree", "spec": "ScaleOperator", "parameter": "@birthRate.t:beastlingTree", "scaleFactor": "0.5", "weight": "3.0"})
def add_frequency_operators(self, run): for name in self.parameter_identifiers(): xml.operator(run, id="frequency_sampler.s:%s" % name, spec="DeltaExchangeOperator", parameter="@freqs_param.s:%s" % name, delta="0.01", weight="1.0")
def add_frequency_operators(self, run): for fname in self.parameter_identifiers(): xml.operator( run, id="%s:pdcovarion_frequency_sampler.s" % fname, spec="DeltaExchangeOperator", parameter="@%s:visiblefrequencies.s" % fname, delta="0.01", weight="1.0")
def add_operators(self, run): if self.estimate_rate: # Scale mean clock rate xml.operator(run, id="clockScaler.c:%s" % self.name, spec="ScaleOperator", parameter="@clockRate.c:%s" % self.name, scaleFactor="0.5", weight="3.0")
def add_frequency_operators(self, run): for f in self.features: fname = "%s:%s" % (self.name, f) xml.operator(run, id="estimatedFrequencyOperator:%s" % fname, spec="DeltaExchangeOperator", parameter="@feature_freqs_param.s:%s" % fname, delta="0.01", weight="0.1")
def add_operators(self, run): BaseModel.add_operators(self, run) if self.gamma_categories > 0: xml.operator(run, id="gammaShapeScaler.s:%s" % self.name, spec="ScaleOperator", parameter="@gammaShape.s:%s" % self.name, scaleFactor="0.5", weight="0.1")
def add_operators(self, run): RelaxedClock.add_operators(self, run) # Sample lognormal stddev if self.estimate_variance: xml.operator(run, id="ucldSdevScaler.c:%s" % self.name, spec="ScaleOperator", parameter="@ucldSdev.c:%s" % self.name, scaleFactor="0.5", weight="3.0")
def _add_operators(self, run, name): xml.operator(run, id="covarion_alpha_scaler.s:%s" % name, spec="ScaleOperator", parameter="@covarion_alpha.s:%s" % name, scaleFactor="0.5", weight="1.0") xml.operator(run, id="%s:covarion_s_scaler.s" % name, spec="ScaleOperator", parameter="@covarion_s.s:%s" % name, scaleFactor="0.5", weight="1.0")
def add_operators(self, run): BaseModel.add_operators(self, run) for n, f in enumerate(self.features): fname = "%s:%s" % (self.name, f) xml.operator( run, id="onGeorateScaler.s:%s" % fname, spec="ScaleOperator", parameter="@relativeGeoRates.s:%s" % fname, indicator="@rateIndicator.s:%s" % fname, scaleAllIndependently="true", scaleFactor="0.5", weight="10.0") if self.rate_variation: xml.operator( run, id="BSSVSoperator.c:%s" % fname, spec="BitFlipBSSVSOperator", indicator="@rateIndicator.s:%s" % fname, mu="@featureClockRate:%s" % fname, weight="30.0") bssvs_bitflip = True elif not self.global_config.arbitrary_tree: # Don't scale the clock of a tree with arbitrary branch # lengths, as birthRate is also scaled and one or the other # will run away to infinity. xml.operator( run, id="BSSVSoperator.c:%s" % fname, spec="BitFlipBSSVSOperator", indicator="@rateIndicator.s:%s" % fname, mu=self.clock.mean_rate_idref, weight="30.0") bssvs_bitflip = True else: bssvs_bitflip = False xml.operator( run, id="indicatorFlip.s:%s" % fname, spec="BitFlipOperator", parameter="@rateIndicator.s:%s" % fname, weight="30.0" if bssvs_bitflip else "60.0") sampoffop = xml.operator( run, id="offGeorateSampler:%s" % fname, spec="SampleOffValues", all="false", values="@relativeGeoRates.s:%s" % fname, indicators="@rateIndicator.s:%s" % fname, weight="30.0") xml.dist(sampoffop, idref="Gamma:%s.%d.0" % (fname, n))
def add_operators(self, run): """ Add <operators> for individual feature substitution rates if rate variation is configured. """ if self.scale_precision: xml.operator(run, id="sphericalPrecisionScaler", spec="ScaleOperator", parameter="@sphericalPrecision", weight="5", scaleFactor="0.7") if self.sampling_points: xml.operator(run, id="location.sampler", spec="sphericalGeo.LocationOperatorF", location="@location.geo", likelihood="@sphericalGeographyLikelihood", weight="10")
def add_operators(self, run): RelaxedClock.add_operators(self, run) updown = xml.operator(run, id="relaxedClockGammaUpDown:%s" % self.name, spec="UpDownOperator", scaleFactor="0.5", weight="3.0") xml.parameter(updown, idref="clockRateGammaShape:%s" % self.name, name="up") xml.parameter(updown, idref="clockRateGammaScale:%s" % self.name, name="down")
def add_operators(self, run): BaseClock.add_operators(self, run) # Operate on indicators xml.operator(run, id="IndicatorsBitFlip.c:%s" % self.name, spec="BitFlipOperator", parameter="@Indicators.c:%s" % self.name, weight="15.0") # Operate on branch rates xml.operator(run, id="ClockRateScaler.c:%s" % self.name, spec="ScaleOperator", parameter="@clockrates.c:%s" % self.name, scaleFactor="0.5", weight="15.0") # Up/down for Gamma params if self.estimate_variance: updown = xml.operator(run, id="randomClockGammaUpDown:%s" % self.name, spec="UpDownOperator", scaleFactor="0.5", weight="1.0") xml.parameter(updown, idref=self.shape_id, name="up") xml.parameter(updown, idref=self.scale_id, name="down")
def add_operators(self): """ Add all <operator> elements. """ self.add_tree_operators() for clock in self.config.clocks: clock.add_operators(self.run) for model in self.config.all_models: model.add_operators(self.run) # Add one DeltaExchangeOperator for feature rates per clock for clock in self.config.clocks: clock_models = [ m for m in self.config.models if m.rate_variation and m.clock == clock ] if not clock_models: continue # Add one big DeltaExchangeOperator which operates on all # feature clock rates from all models delta = xml.operator(self.run, id="featureClockRateDeltaExchanger:%s" % clock.name, spec="DeltaExchangeOperator", weight="3.0") for model in clock_models: xml.parameter(xml.plate(delta, var="rate", range=model.all_rates), idref="featureClockRate:%s:$(rate)" % model.name) # Add weight vector if there has been any binarisation if any([ w != 1 for w in itertools.chain( *[m.weights for m in clock_models]) ]): xml.weightvector( delta, text=" ".join( itertools.chain( *[map(str, m.weights) for m in clock_models])), id="featureClockRateWeightParameter:%s" % clock.name, spec="parameter.IntegerParameter", dimension=str(sum([len(m.weights) for m in clock_models])), estimate="false")
def add_operators(self, run): """ Add <operators> for individual feature substitution rates if rate variation is configured. """ if self.frequencies == "estimate": self.add_frequency_operators(run) if self.rate_variation: # UpDownOperator to scale the Gamma distribution for this model's # feature rates updown = xml.operator(run, id="featureClockRateGammaUpDown:%s" % self.name, spec="UpDownOperator", scaleFactor="0.5", weight="0.3") xml.parameter(updown, idref="featureClockRateGammaShape:%s" % self.name, name="up") xml.parameter(updown, idref="featureClockRateGammaScale:%s" % self.name, name="down")
def add_operators(self, run): BaseClock.add_operators(self, run) # Add category operators xml.operator(run, id="rateCategoriesRandomWalkOperator.c:%s" % self.name, spec="IntRandomWalkOperator", parameter="@rateCategories.c:%s" % self.name, windowSize="1", weight="10.0") xml.operator(run, id="rateCategoriesSwapOperator.c:%s" % self.name, spec="SwapOperator", intparameter="@rateCategories.c:%s" % self.name, weight="10.0") xml.operator(run, id="rateCategoriesUniformOperator.c:%s" % self.name, spec="UniformOperator", parameter="@rateCategories.c:%s" % self.name, weight="10.0")
def _add_operators(self, run, name): xml.operator( run, id="%s:pdcovarion_origin_scaler.s" % name, spec="ScaleOperator", parameter="@%s:pdcovarion_origin.s" % name, scaleFactor="0.75", weight="0.1") xml.operator( run, id="%s:pdcovarion_s_scaler.s" % name, spec="ScaleOperator", parameter="@%s:pdcovarion_s.s" % name, scaleFactor="0.75", weight="0.1") xml.operator( run, id="%s:pdcovarion_death_scaler.s" % name, spec="ScaleOperator", parameter="@%s:pdcovarion_death.s" % name, scaleFactor="0.75", weight="0.1")
def add_operators(self, beastxml): """ Add all <operator>s which act on the tree topology and branch lengths. """ # Tree operators # Operators which affect the tree must respect the sample_topology and # sample_branch_length options. if beastxml.config.languages.sample_topology: ## Tree topology operators xml.operator(beastxml.run, attrib={"id":"SubtreeSlide.t:beastlingTree","spec":"SubtreeSlide","tree":"@Tree.t:beastlingTree","markclades":"true", "weight":"15.0"}) xml.operator(beastxml.run, attrib={"id":"narrow.t:beastlingTree","spec":"Exchange","tree":"@Tree.t:beastlingTree","markclades":"true", "weight":"15.0"}) xml.operator(beastxml.run, attrib={"id":"wide.t:beastlingTree","isNarrow":"false","spec":"Exchange","tree":"@Tree.t:beastlingTree","markclades":"true", "weight":"3.0"}) xml.operator(beastxml.run, attrib={"id":"WilsonBalding.t:beastlingTree","spec":"WilsonBalding","tree":"@Tree.t:beastlingTree","markclades":"true","weight":"3.0"}) if beastxml.config.languages.sample_branch_lengths: ## Branch length operators xml.operator(beastxml.run, attrib={"id":"UniformOperator.t:beastlingTree","spec":"Uniform","tree":"@Tree.t:beastlingTree","weight":"30.0"}) xml.operator(beastxml.run, attrib={"id":"treeScaler.t:beastlingTree","scaleFactor":"0.5","spec":"ScaleOperator","tree":"@Tree.t:beastlingTree","weight":"3.0"}) xml.operator(beastxml.run, attrib={"id":"treeRootScaler.t:beastlingTree","scaleFactor":"0.5","spec":"ScaleOperator","tree":"@Tree.t:beastlingTree","rootOnly":"true","weight":"3.0"}) ## Up/down operator which scales tree height # Add a Tip Date scaling operator if required if beastxml.config.tip_calibrations and beastxml.config.languages.sample_branch_lengths: # Get a list of taxa with non-point tip cals tip_taxa = [next(cal.langs.__iter__()) for cal in beastxml.config.tip_calibrations.values() if cal.dist != "point"] for taxon in tip_taxa: tiprandomwalker = xml.operator( beastxml.run, attrib={"id": "TipDatesandomWalker:%s" % taxon, "spec": "TipDatesRandomWalker", "windowSize": "1", "tree": "@Tree.t:beastlingTree", "weight": "3.0", }) beastxml.add_taxon_set(tiprandomwalker, taxon, (taxon,))
def add_operators(self, beastxml): """ Add all <operator>s which act on the tree topology and branch lengths. """ """ Add all <operator>s which act on the tree topology and branch lengths. """ # Tree operators # Operators which affect the tree must respect the sample_topology and # sample_branch_length options. if beastxml.config.languages.sample_topology: ## Tree topology operators xml.operator(beastxml.run, attrib={ "id": "SubtreeSlide.t:beastlingTree", "spec": "SubtreeSlide", "tree": "@Tree.t:beastlingTree", "markclades": "true", "weight": "15.0" }) xml.operator(beastxml.run, attrib={ "id": "narrow.t:beastlingTree", "spec": "Exchange", "tree": "@Tree.t:beastlingTree", "markclades": "true", "weight": "15.0" }) xml.operator(beastxml.run, attrib={ "id": "wide.t:beastlingTree", "isNarrow": "false", "spec": "Exchange", "tree": "@Tree.t:beastlingTree", "markclades": "true", "weight": "3.0" }) xml.operator(beastxml.run, attrib={ "id": "WilsonBalding.t:beastlingTree", "spec": "WilsonBalding", "tree": "@Tree.t:beastlingTree", "markclades": "true", "weight": "3.0" }) if beastxml.config.languages.sample_branch_lengths: ## Branch length operators xml.operator(beastxml.run, attrib={ "id": "UniformOperator.t:beastlingTree", "spec": "Uniform", "tree": "@Tree.t:beastlingTree", "weight": "30.0" }) xml.operator(beastxml.run, attrib={ "id": "treeScaler.t:beastlingTree", "scaleFactor": "0.5", "spec": "ScaleOperator", "tree": "@Tree.t:beastlingTree", "weight": "3.0" }) xml.operator(beastxml.run, attrib={ "id": "treeRootScaler.t:beastlingTree", "scaleFactor": "0.5", "spec": "ScaleOperator", "tree": "@Tree.t:beastlingTree", "rootOnly": "true", "weight": "3.0" }) ## Up/down operator which scales tree height if self.type in ["yule", "birthdeath"]: updown = xml.operator(beastxml.run, attrib={ "id": "UpDown", "spec": "UpDownOperator", "scaleFactor": "0.5", "weight": "3.0" }) xml.tree(updown, idref="Tree.t:beastlingTree", name="up") xml.parameter(updown, idref="birthRate.t:beastlingTree", name="down") ### Include clock rates in up/down only if calibrations are given if beastxml.config.calibrations: for clock in beastxml.config.clocks: if clock.estimate_rate: xml.parameter(updown, idref=clock.mean_rate_id, name="down") if self.type in ["yule", "birthdeath"]: # Birth rate scaler # Birth rate is *always* scaled. xml.operator(beastxml.run, attrib={ "id": "YuleBirthRateScaler.t:beastlingTree", "spec": "ScaleOperator", "parameter": "@birthRate.t:beastlingTree", "scaleFactor": "0.5", "weight": "3.0" }) elif self.type == "coalescent": xml.operator(beastxml.run, attrib={ "id": "PopulationSizeScaler.t:beastlingTree", "spec": "ScaleOperator", "parameter": "@popSize.t:beastlingTree", "scaleFactor": "0.5", "weight": "3.0" }) if self.type in ["birthdeath"]: xml.operator(beastxml.run, attrib={ "id": "SamplingScaler.t:beastlingTree", "spec": "ScaleOperator", "parameter": "@sampling.t:beastlingTree", "scaleFactor": "0.8", "weight": "1.0" }) xml.operator(beastxml.run, attrib={ "id": "DeathRateScaler.t:beastlingTree", "spec": "ScaleOperator", "parameter": "@deathRate.t:beastlingTree", "scaleFactor": "0.5", "weight": "3.0" }) # Add a Tip Date scaling operator if required if beastxml.config.tip_calibrations and beastxml.config.languages.sample_branch_lengths: # Get a list of taxa with non-point tip cals tip_taxa = [ next(cal.langs.__iter__()) for cal in beastxml.config.tip_calibrations.values() if cal.dist != "point" ] for taxon in tip_taxa: tiprandomwalker = xml.operator(beastxml.run, attrib={ "id": "TipDatesandomWalker:%s" % taxon, "spec": "TipDatesRandomWalker", "windowSize": "1", "tree": "@Tree.t:beastlingTree", "weight": "3.0", }) beastxml.add_taxon_set(tiprandomwalker, taxon, (taxon, ))