CompEvol / beast2

Bayesian Evolutionary Analysis by Sampling Trees
www.beast2.org
GNU Lesser General Public License v2.1
239 stars 84 forks source link

Multiple tree loggers for discrete trait analysis #989

Closed santiagosnchez closed 3 years ago

santiagosnchez commented 3 years ago

I was able to recreate this using a dummy dataset (attached). Appears that BEAUti (v2.6.5) generates one (or more) tree logger for each partition only for the tree logfile that includes the traits. This creates a problem for down the line with treeannotator and logcombiner. It is my understanding that there should only be one logger if the tree prior is linked for all partitions. For example, I should get:

    <logger id="treeWithTraitLogger.location" spec="Logger" fileName="location_tree_with_trait.trees" logEvery="10000" mode="tree">
        <log id="TreeWithTraitLogger.0" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:gene1">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
    </logger>

But instead I'm getting:

    <logger id="treeWithTraitLogger.location" spec="Logger" fileName="location_tree_with_trait.trees" logEvery="10000" mode="tree">
        <log id="TreeWithTraitLogger.0" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:gene1">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
         <log id="TreeWithTraitLogger.0.gene2" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:gene1">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene3" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:gene1">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene2.gene3" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:LSU">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene3.gene4" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:LSU">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene4" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:gene1">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene2.gene3.gene4" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:LSU">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
        <log id="TreeWithTraitLogger.0.gene2.gene4" spec="beast.evolution.tree.TreeWithTraitLogger" tree="@Tree.t:LSU">
            <metadata idref="posterior"/>
            <metadata idref="traitedtreeLikelihood.location"/>
        </log>
    </logger>

For now, I've just been manually deleting the extra log blocks. But I'm pretty sure this is bug.

trait_tree_logger_test.zip

rbouckaert commented 3 years ago

Hi Santiago, Thanks for the bug report.

I managed to reproduce the problem by setting the relaxed clock for the first gene, then clone the others from the first. Also, linking all clock models, setting the first to relaxed, then unlinking causes a similar problem. It looks like the cloning function produces too many treeWithTraitLoggers where it should not do so. This certainly is a bug. A workaround for now might be to set up clock models for the genes before adding the discrete trait partition.

Remco

rbouckaert commented 3 years ago

Turns out this was caused by a missing ID in the discrete-trait template in the BEAST_CLASSIC package.

santiagosnchez commented 3 years ago

Great that your were able to patch the bug! Thanks, Remco!

The solution that was using is simply deleting the extra tree logger blocks directly on the XML file.