KlausVigo / phangorn

Phylogenetic analysis in R
http://klausvigo.github.io/phangorn/
204 stars 38 forks source link

Single data point causes BAB function to return error #163

Open spetersongit opened 8 months ago

spetersongit commented 8 months ago

Hello,

I'm doing a class project for undergrads where they collect morphological data on plants and use phangorn to create phylogenetic trees from their matrix of data. I decided for ease of data collection to have all categories be binary traits. Sometimes, there is a single cell of data which throws an error when using the bab() function:

Error in *tmp*[[i]] : subscript out of bounds

If I change that single cell from a 1 to a 0, the program can make trees.

An example dataset that throws the error is attached here MorphData.csv . The error is linked to cells 8, 14 or 9, 14 (Linear_S variable, Species 7 & 8). If I change either 1 in that column to a 0, this set of traits will work. Otherwise it fails.

The code I am using is: morph_data = read.csv(MorphData.csv, row.names = 1)

Reformat the data to be useful for tree analysis

morph_data = phyDat(as.matrix(morph_data), type = "USER", levels = 0:1)

Create a set of candidate trees using the Branch and Bound algorithm

morph_cand = bab(morph_data, trace = 0)

The error occurs in the bab() line.

Any help tracking down what might be happening would be huge.

bbitarello commented 2 months ago

Hello, I am not a developer of this package but as I was searching around to see if there were any issues with the bab() function, I found this. I ran your code and it did work perfectly. Whatever was giving the error for you seems to have since been resolved with the current version of the package. Cheers

Code: (make sure current package version is installed via github)

morph_data<-read.csv("https://github.com/KlausVigo/phangorn/files/14540124/MorphData.csv", row.names = 1)

morph_data <- phyDat(as.matrix(morph_data), type = "USER", levels = 0:1)

morph_cand = bab(morph_data, trace = 0)