Closed jrom99 closed 9 months ago
I know this is the wrong place to ask, but how can I use the Math.Floor function within a "Format attribute..." window?
Hi, for the tree I am not 100% sure what you mean - if you can send me a screenshot or an example (either here or via e-mail) it would help! In any case, if TreeViewer is computing a consensus tree, you may want to make sure that the Treat trees as clock-like
option in the parameters for the Transformer module is enabled:
Normally, the program determines whether the trees are clock-like by checking whether the tips are all contemporaneous, but if you have dated samples you need to specify it manually.
For the Math.Floor
function, you should use the fully qualified name System.Math.Floor
(and then use ToString
to convert it to a string, of course).
Normally, the program determines whether the trees are clock-like by checking whether the tips are all contemporaneous, but if you have dated samples you need to specify it manually.
I have a maximum clade credibility consensus tree built using TreeAnnotator, and it uses sequences sampled at different times. BEAST uses height
/height_median
attributes instead of the sampling year.
I took a screenshot using a tree from the BEAST time-stamped sequences analysis tutorial (https://beast.community/workshop_rates_and_dates) with FigTree on the left and TreeViewer on the right:
The sequence 1979_AY540481_CAREC797984_Trinidad
is placed further to the right than what would be expected considering its sampling date.
Thank you very much for the support, I don't know how to program in C#, but the code editor and sidebar options are extremely useful! And TreeViewer itself is versatile enough that I rarely need to use them, so I was having a bit of trouble dealing with the functions namespaces.
Tree file: YFV_MCC.tree.txt
TL;DR: use a Linear transformation
Further transformation module to copy the value of the Length2
attribute into the Length
attribute. Longer answer below 😅.
Thank you for sending me the file! I think I see the problem. In the MCC tree, each branch has its Length
specified twice: once as an attribute called length
, and once in the "normal" NEWICK way (i.e., with :123
after the branch).
I believe the first one is computed as the median of the length in the all the trees that you gave to TreeAnnotator, while the second one is computed based on the median height (and is what you actually want to plot).
For example, the branch leading to 1989_AY540485_CAREC891957_Trinidad
(taxon 45
in the tree) is specified as:
45[&...,length=10.212557547856015,...]:9.150572745408908
When TreeViewer reads this file and finds two Length
attributes, it stores the first one (10.2...
, which is the median of the branch lengths) in the actual Length
attribute, and the second one (9.15...
, which is the one you want to plot) in a new Length2
attribute. So the solution is simply to copy the value of the Length2
attribute into the Length
attribute.
You can do this with a Linear transformation
Further transformation module with the following settings:
Length2
.1
(i.e., you don't actually want to change the value of the attribute).0
(again, you don't actually want to change the value).Length
.After this, Length
will be equal to Length2
across the whole tree, which should now be displayed the way you wanted it.
I'm glad to hear that you are finding the code editor useful (and also that you don't have to use it too often 😅)! Yes, normally you would stick a using System;
at the top of your C# source code file and then just invoke Math.Floor
etc. However, the attribute formatter only shows you a snippet of a single method, so you can't add using
statements and have to use fully qualified names.
After this, Length will be equal to Length2 across the whole tree, which should now be displayed the way you wanted it.
Thank you very much, it worked!
I'm using a MCC tree obtained from a BEAST analysis with dated samples, it seems that the scale/branch lengths are out of sync with the dated tips (and maybe nodes as well). On Figtree, all tips that were sampled at the same date share the same x-coordinates, but the same doesn't happen for TreeViewer, how can I make it so that TreeViewer uses the correct x-coordinate?
System information
TreeViewer version 2.2.0 OS: Ubuntu 23.10 DE: GNOME Shell 45.2