bioFAM / MOFA

Multi-Omics Factor Analysis
GNU Lesser General Public License v3.0
231 stars 57 forks source link

Error in py_call_impl(callable, dots$args, dots$keywords): TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind' #34

Closed jonathanronen closed 5 years ago

jonathanronen commented 5 years ago

Hi. I'm encountering strange errors with data which used to work for me on a previous version of MOFA. Could you please help debug?

Error message:

[1] "No output file provided, using a temporary file..."
Error in py_call_impl(callable, dots$args, dots$keywords): TypeError: Cannot cast ufunc add output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'

Detailed traceback: 
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/entry_point.py", line 410, in train_model
    self.model = runMOFA(self.data, self.data_opts, self.model_opts, self.train_opts, self.train_opts['seed'])
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/build_model.py", line 143, in runMOFA
    net.iterate()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/BayesNet.py", line 148, in iterate
    self.nodes[node].update()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/nodes.py", line 43, in update
    self.updateParameters()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/updates.py", line 443, in updateParameters
    bar_tmp2 += Y[m]

Traceback:

1. runMOFA(MOFAobject)
2. mofa_entrypoint$train_model()
3. py_call_impl(callable, dots$args, dots$keywords)

The MOFA object looks like this: mofa object rds file

session info:

R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS: /data/local/jona/home/.Renv/versions/3.5.1/lib64/R/lib/libRblas.so
LAPACK: /data/local/jona/home/.Renv/versions/3.5.1/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=de_DE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] MOFA_0.99.12

loaded via a namespace (and not attached):
 [1] ggrepel_0.8.0               Rcpp_1.0.1                 
 [3] lattice_0.20-35             tidyr_0.8.3                
 [5] assertthat_0.2.0            digest_0.6.18              
 [7] foreach_1.4.4               IRdisplay_0.7.0            
 [9] R6_2.4.0                    GenomeInfoDb_1.18.1        
[11] plyr_1.8.4                  repr_0.18                  
[13] stats4_3.5.1                evaluate_0.13              
[15] ggplot2_3.1.0               pillar_1.3.1               
[17] zlibbioc_1.28.0             rlang_0.3.1                
[19] lazyeval_0.2.2              uuid_0.1-2                 
[21] S4Vectors_0.20.1            Matrix_1.2-14              
[23] reticulate_1.11.1           BiocParallel_1.16.5        
[25] stringr_1.4.0               pheatmap_1.0.12            
[27] RCurl_1.95-4.12             munsell_0.5.0              
[29] DelayedArray_0.8.0          compiler_3.5.1             
[31] vipor_0.4.5                 pkgconfig_2.0.2            
[33] BiocGenerics_0.28.0         base64enc_0.1-3            
[35] ggbeeswarm_0.6.0            htmltools_0.3.6            
[37] tidyselect_0.2.5            SummarizedExperiment_1.12.0
[39] tibble_2.1.1                GenomeInfoDbData_1.2.0     
[41] IRanges_2.16.0              codetools_0.2-15           
[43] matrixStats_0.54.0          crayon_1.3.4               
[45] dplyr_0.8.0.1               bitops_1.0-6               
[47] grid_3.5.1                  jsonlite_1.6               
[49] gtable_0.2.0                magrittr_1.5               
[51] scales_1.0.0                stringi_1.4.3              
[53] XVector_0.22.0              reshape2_1.4.3             
[55] MultiAssayExperiment_1.6.0  doParallel_1.0.14          
[57] cowplot_0.9.4               IRkernel_0.8.14            
[59] Rhdf5lib_1.2.1              RColorBrewer_1.1-2         
[61] iterators_1.0.10            tools_3.5.1                
[63] Biobase_2.42.0              glue_1.3.1                 
[65] beeswarm_0.2.3              purrr_0.3.2                
[67] parallel_3.5.1              rhdf5_2.24.0               
[69] colorspace_1.4-1            GenomicRanges_1.34.0       
[71] corrplot_0.84               pbdZMQ_0.3-3

mofapy version 1.1.1 on python 3.6.7.

Thank you! J.

rargelaguet commented 5 years ago

Hi, seems to converge properly in my laptop. I have updated minor things in the python package though. Can you install the last version (1.2) and try running again?

After inspecting your model I notice that your CNV is not normalised for library size. Hence you obtain a very strong Factor 1 that just captures the technical variability associated with differences in library size (see figure attached).

plot(
  library_size <- apply(model@TrainData$CNVs,2,sum),  
  getFactors(model, factors=1)[,1]
)

image

image

jonathanronen commented 5 years ago

Thanks @rargelaguet. After updating to mofapy 1.2, I get this here error:

Error in py_call_impl(callable, dots$args, dots$keywords): ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Detailed traceback: 
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/entry_point.py", line 410, in train_model
    self.model = runMOFA(self.data, self.data_opts, self.model_opts, self.train_opts, self.train_opts['seed'])
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/build_model.py", line 143, in runMOFA
    net.iterate()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/BayesNet.py", line 148, in iterate
    self.nodes[node].update()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/nodes.py", line 43, in update
    self.updateParameters()
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/updates.py", line 414, in updateParameters
    latent_variables = self.getLvIndex() # excluding covariates from the list of latent variables
  File "/home/jronen/miniconda3/envs/conda36/lib/python3.6/site-packages/mofapy/core/updates.py", line 403, in getLvIndex
    if any(self.covariates):

Traceback:

1. runMOFA(MOFAobject, outfile = tempfile())
2. mofa_entrypoint$train_model()
3. py_call_impl(callable, dots$args, dots$keywords)

Any ideas?

J.

rargelaguet commented 5 years ago

This is an error from the 1.1 version, fixed in https://github.com/bioFAM/MOFA/issues/26 Are you sure that you are using the 1.2 version?

jonathanronen commented 5 years ago

You know what, I installed a new python 3.6.8, new R 3.5.2, and everything anew and now it works. Thanks @rargelaguet!

J.

jonathanronen commented 5 years ago

PS thanks for the tip on the CNV normalization!