evolbioinfo / gotree

Gotree is a set of command line tools and an API to manipulate phylogenetic trees. It is implemented in Go language.
GNU General Public License v2.0
120 stars 15 forks source link

Bipartition question #5

Closed richardgoater closed 4 years ago

richardgoater commented 4 years ago

Hello, thanks for a nice library!

I'm trying to implement a neighbour-joining example and I come across this issue on the penultimate step:

+---------- F                                                                             
|                                                                                         
|          +--------------------------------- E                                           
|----------|ED                                                                            
|          +---------------------- D                                                      
|                                                                                         
|                                 +---------- B                                           
|          +----------------------|BA                                                     
+----------|BAC                   +-------------------------------------------- A         
           |                                                                              
           +---------- C                                                                  

--- FAIL: TestNJ (0.00s)
panic: We cannot add the bipartition, it already exists [recovered]

It is attempting to join F and ED at this point. Can I detect this situation and do something different perhaps?

fredericlemoine commented 4 years ago

Hello, Could you provide a small example of the way you call the function? Thanks, Frederic

richardgoater commented 4 years ago

Thanks for the quick reply @fredericlemoine, I think this line is the one of interest: https://gist.github.com/richardgoater/867546a4ec48cc75e570f1f42deb79ff#file-nj-go-L85

I realise that I'm not checking for errors with the edges on lines 77-78.

EDIT: Added a test file to the gist

fredericlemoine commented 4 years ago

Hello, Wouldn't it be due to the fact that your tree is already fully resolved? It seems there is no "polytomies" left, i.e nodes with more than 3 neighbors. By the way, there is a function you can call to create a startree from taxa names directly:

t,err := tree.StarTreeFromName(taxa...)
richardgoater commented 4 years ago

Thanks for your thoughts, and thanks for the tip on creating the startree. I think there should be one more round of joining at this point, the matrix is 3 x 3 with nodes F, ED, and BAC. The implementation is probably not 100% correct, and I still need to implement the final operation when the matrix is 2 x 2.

fredericlemoine commented 4 years ago

Ok, but I don't think you can add a new bipartition, as all the internal nodes have already 3 neighbors. Are you sure you need a 2x2 matrix? (see here for example)

richardgoater commented 4 years ago

Thanks again, is there something else I can do instead of a bipartition? I've been following this example: http://www.evolution-textbook.org/content/free/tables/Ch_27/T11_EVOW_Ch27.pdf I believe the program is stuck at cycle 4, and I need to implement the "final step" here: https://gist.github.com/richardgoater/867546a4ec48cc75e570f1f42deb79ff#file-nj-go-L107

richardgoater commented 4 years ago

Hi, I think I have it working now and updated the gist. I realised I just need to assign distances to the existing nodes in the situation above (and I was also assigning distances the opposite way round, now fixed). Thanks very much for your time again, and thanks for the library.

fredericlemoine commented 4 years ago

Thanks for the update