emmanuelparadis / pegas

Population and Evolutionary Genetics Analysis System
GNU General Public License v2.0
27 stars 10 forks source link

Running haplotype() on an empty dna object #53

Closed kweitemier closed 3 years ago

kweitemier commented 3 years ago

Hello,

I wanted to report an unexpected (to me) change in the behavior of haplotype() between versions 0.12 and 0.14.

Under version 0.12 the following executes and produces an empty list:

library(pegas)
data("woodmouse")
emptyDNA <- woodmouse[0, ]
emptyHap <- haplotype(emptyDNA)
> emptyHap
Haplotypes extracted from: emptyDNA 

    Number of haplotypes: 0 
         Sequence length: 965 

Haplotype labels and frequencies:

list()
> str(emptyHap)
 'haplotype' raw[0 , 1:965] 
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : NULL
 - attr(*, "index")= list()
 - attr(*, "from")= chr "emptyDNA"

Under version 0.14 this fails with the following error:

> emptyHap <- haplotype(emptyDNA)
Error in `[.default`(x, i, , drop = FALSE) : subscript out of bounds
In addition: Warning message:
In haplotype.DNAbin(emptyDNA) :
  no segregating site detected with these options

Could the old behavior (plus a warning) be restored? Alternatively, is there a way to run haplotype() on an empty DNAbin object, or a way to produce an empty haplotype() object?

Thank you!

emmanuelparadis commented 3 years ago

Hi, Thanks for the report. Fixed and now on GH. E.

kweitemier commented 3 years ago

That did the trick. Thank you!