mayoverse / kinship2

Pedigree creation, plotting, and analytics
GNU General Public License v2.0
15 stars 7 forks source link

solve.QP Constraints are Inconsistent Error #34

Closed alexkrohn closed 8 months ago

alexkrohn commented 9 months ago

Hi there,

I've plotted this pedigree by hand and don't see glaring inconsistencies, but for some reason I'm getting an error with quadprog when plotting this pedigree. Might this have to do with #27 from @LouisLeNezet ? I have used kinship2 multiple times for similarly complex pedigrees without a problem. Unfortunately, it's very hard to traceback the error.

Code, using the attached pedigree:

pedigree <- readr::read_tsv("low-missing-pedigree-fixed.tsv")

ped.object <- pedigree(id = final.pedigree$id, dadid=final.pedigree$sire, momid = final.pedigree$dam, sex = as.integer(final.pedigree$sex.number))

plot(ped.object)

Error:

Error in solve.QP(pp, rep(0, n), t(cmat), dvec) : 
  constraints are inconsistent, no solution!
sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: aarch64-apple-darwin22.4.0 (64-bit)
Running under: macOS Ventura 13.3.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /opt/homebrew/Cellar/r/4.3.1/lib/R/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] googlesheets4_1.1.1 sequoia_2.7.2       kinship2_1.9.6      quadprog_1.5-8      Matrix_1.6-1.1      lubridate_1.9.3     forcats_1.0.0      
 [8] stringr_1.5.1       dplyr_1.1.4         purrr_1.0.2         readr_2.1.4         tidyr_1.3.1         tibble_3.2.1        ggplot2_3.5.0      
[15] tidyverse_2.0.0    

loaded via a namespace (and not attached):
 [1] gtable_0.3.4      xfun_0.42         htmlwidgets_1.6.2 devtools_2.4.5    remotes_2.4.2.1   processx_3.8.2    gargle_1.5.2      lattice_0.21-9   
 [9] callr_3.7.3       tzdb_0.4.0        vctrs_0.6.5       tools_4.3.1       ps_1.7.5          generics_0.1.3    curl_5.1.0        fansi_1.0.6      
[17] pkgconfig_2.0.3   desc_1.4.2        lifecycle_1.0.4   compiler_4.3.1    munsell_0.5.0     httpuv_1.6.11     htmltools_0.5.6.1 usethis_2.2.2    
[25] later_1.3.1       pillar_1.9.0      crayon_1.5.2      urlchecker_1.0.1  ellipsis_0.3.2    openssl_2.1.1     cachem_1.0.8      sessioninfo_1.2.2
[33] mime_0.12         tidyselect_1.2.0  digest_0.6.33     stringi_1.8.3     rprojroot_2.0.3   fastmap_1.1.1     grid_4.3.1        colorspace_2.1-0 
[41] cli_3.6.2         magrittr_2.0.3    pkgbuild_1.4.2    utf8_1.2.4        withr_3.0.0       rappdirs_0.3.3    prettyunits_1.2.0 scales_1.3.0     
[49] promises_1.2.1    bit64_4.0.5       googledrive_2.1.1 timechange_0.2.0  httr_1.4.7        bit_4.0.5         cellranger_1.1.0  askpass_1.2.0    
[57] hms_1.1.3         memoise_2.0.1     shiny_1.7.5       knitr_1.45        miniUI_0.1.1.1    profvis_0.3.8     rlang_1.1.3       Rcpp_1.0.12      
[65] xtable_1.8-4      glue_1.7.0        pkgload_1.3.3     vroom_1.6.4       jsonlite_1.8.7    rstudioapi_0.15.0 plyr_1.8.9        R6_2.5.1         
[73] fs_1.6.3         
alexkrohn commented 9 months ago

I also get an error with this same solve.QP function when trying to install kinship2 from github.

This is probably unrelated to my original error, as that version of kinship2 was installed from CRAN, but still I made #35 to (I think!) fix the install_github problem.

devtools::install_github(mayoverse/kinship2)

Downloading GitHub repo mayoverse/kinship2@HEAD
── R CMD build ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘/private/var/folders/bw/p5_hpq2n3kg5swb3x0g0ncp40000gn/T/RtmpPRIC58/remotes3cbc33b30e6a/mayoverse-kinship2-4fd94a1/DESCRIPTION’ ...
─  preparing ‘kinship2’:
✔  checking DESCRIPTION meta-information ...
   Warning: alignped1.Rd:23: unknown macro '\item'
   Warning: alignped1.Rd:30: unknown macro '\item'
   Warning: alignped1.Rd:33: unknown macro '\item'
   Warning: alignped1.Rd:46: unknown macro '\item'
   Warning: alignped1.Rd:49: unknown macro '\item'
   Warning: alignped3.Rd:31: unknown macro '\item'
   Warning: alignped3.Rd:36: unknown macro '\item'
   Warning: alignped4.Rd:32: unknown macro '\sum'
   Warning: alignped4.Rd:35: unknown macro '\sum'
   Warning: alignped4.Rd:35: unknown macro '\sum'
   Warning: alignped4.Rd:35: unknown macro '\mu'
   Warning: alignped4.Rd:35: unknown macro '\mu'
   Warning: alignped4.Rd:49: unknown macro '\item'
   Warning: alignped4.Rd:58: unknown macro '\item'
   Warning: alignped4.Rd:59: unknown macro '\ge'
   Warning: alignped4.Rd:61: unknown macro '\le'
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  looking to see if a ‘data/datalist’ file should be added
─  building ‘kinship2_1.9.7.tar.gz’

Installing package into ‘/opt/homebrew/lib/R/4.3/site-library’
(as ‘lib’ is unspecified)
* installing *source* package ‘kinship2’ ...
** using staged installation
** R
Error in parse(...) : 
  /private/var/folders/bw/p5_hpq2n3kg5swb3x0g0ncp40000gn/T/RtmpHGhsZV/R.INSTALL3d2368f43ec3/kinship2/R/alignped4.R:139:23: unexpected symbol
138:       warning = function(w) {
139:         message(Solve QP
                           ^
ERROR: unable to collate and parse R files for package ‘kinship2’
* removing ‘/opt/homebrew/lib/R/4.3/site-library/kinship2’
* restoring previous ‘/opt/homebrew/lib/R/4.3/site-library/kinship2’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/bw/p5_hpq2n3kg5swb3x0g0ncp40000gn/T//RtmpPRIC58/file3cbc30776baa/kinship2_1.9.7.tar.gz’ had non-zero exit status
LouisLeNezet commented 8 months ago

Hi @alexkrohn, It effectively seems to be a complicated pedigree. This problem should have been solved in the new version of the kinship package but I've made a mistake that you've found. Sorry for the inconvenience. If you want the kinship package will be soon deprecated on CRAN and has been moved to Pedixplorer on BioConductor. Using it I achieve to plot the following:

if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

# The following initializes usage of Bioc devel
BiocManager::install(version='devel')

BiocManager::install("Pedixplorer")
library("Pedixplorer")

ped_df <- readr::read_tsv("low-missing-pedigree-fixed.txt")

# Just a small change in the parameters and function name
ped.object <- with(ped_df, Pedigree(obj= id, dadid=sire, momid =dam, sex = sex.number))

plot(ped.object)

image

alexkrohn commented 8 months ago

Thanks! This does seem to solve it. It's a bit of a bleeding edge solution as you have to upgrade to the dev version of R (4.4 currently), but it does solve the issue. Thanks for this! I look forward to future developments in Pedixplorer