uqrmaie1 / admixtools

https://uqrmaie1.github.io/admixtools
74 stars 14 forks source link

qp3pop unique_only does not work as expected #57

Closed RvV1979 closed 10 months ago

RvV1979 commented 11 months ago

I am running qp3pop to assess admixture across a set of populations. However, when I specify the same population set for pop1, pop2, and pop3, I get redundant combinations such as, e.g. f3(A;A,A) and both f3(A;B,C) and f3(A;C,B). Setting unique_only = TRUE has no effect on this.

Short reproducible example:

library("admixtools")

pop1 = c('Chimp.REF', 'Mbuti.DG', 'Russia_Ust_Ishim.DG')
pop2 = c('Chimp.REF', 'Mbuti.DG', 'Russia_Ust_Ishim.DG')
pop3 = c('Chimp.REF', 'Mbuti.DG', 'Russia_Ust_Ishim.DG')
qp3pop(example_f2_blocks, pop1, pop2, pop3, unique_only = TRUE)

Result:

# A tibble: 27 × 7
   pop1      pop2                pop3                  est       se     z     p
   <chr>     <chr>               <chr>               <dbl>    <dbl> <dbl> <dbl>
 1 Chimp.REF Chimp.REF           Chimp.REF           0     0         NaN    NaN
 2 Chimp.REF Chimp.REF           Mbuti.DG            0     0         NaN    NaN
 3 Chimp.REF Chimp.REF           Russia_Ust_Ishim.DG 0     0         NaN    NaN
 4 Chimp.REF Mbuti.DG            Chimp.REF           0     0         NaN    NaN
 5 Chimp.REF Mbuti.DG            Mbuti.DG            0.205 0.000606  339.     0
 6 Chimp.REF Mbuti.DG            Russia_Ust_Ishim.DG 0.193 0.000587  329.     0
 7 Chimp.REF Russia_Ust_Ishim.DG Chimp.REF           0     0         NaN    NaN
 8 Chimp.REF Russia_Ust_Ishim.DG Mbuti.DG            0.193 0.000587  329.     0
 9 Chimp.REF Russia_Ust_Ishim.DG Russia_Ust_Ishim.DG 0.257 0.00202   127.     0
10 Mbuti.DG  Chimp.REF           Chimp.REF           0.205 0.000606  339.     0
#  17 more rows
#  Use `print(n = ...)` to see more rows

Expected result:

# A tibble: 3 × 7
   pop1                pop2                pop3                   est       se     z         p
   <chr>               <chr>               <chr>                <dbl>    <dbl> <dbl>     <dbl>
 1 Chimp.REF           Mbuti.DG            Russia_Ust_Ishim.DG 0.193  0.000587 329.  0        
 2 Mbuti.DG            Chimp.REF           Russia_Ust_Ishim.DG 0.0118 0.000487  24.3 4.62e-130
 3 Russia_Ust_Ishim.DG Chimp.REF           Mbuti.DG            0.0635 0.00187   34.0 4.43e-253
uqrmaie1 commented 10 months ago

The unique_only option is only effective when only pop1 is defined:

> qp3pop(example_f2_blocks, pop1, unique_only = FALSE) %>% nrow()
[1] 27
> qp3pop(example_f2_blocks, pop1, unique_only = TRUE) %>% nrow()
[1] 3

If pop1, pop2, and pop3 are all defined, it will ignore unique_only and give you all possible combinations.

RvV1979 commented 10 months ago

Thanks for the clarification. Perhaps writing this in the qp3pop help page can help prevent similar confusion for other users.