bioFAM / MOFA

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

Error when creating object from MAE #39

Closed andreanuzzo closed 5 years ago

andreanuzzo commented 5 years ago

Hi, Thank you for the great work! I am attempting to test MOFA on my datasets, but I have troubles in converting the MultiAssayExperiment object into the MOFA object.

The MAE object was built using the MAE constructor function, and contains 3 experiments, colData and sampleMaps

> multiHMP2 <- do.call(MultiAssayExperiment, prepMultiAssay(HMP2exp, colData, sample_map))
harmonizing input:
  removing 348 sampleMap rows with 'colname' not in colnames of experiments
  removing 24 colData rownames not in sampleMap 'primary'

This is how it looks like

> multiHMP2
A MultiAssayExperiment object of 3 listed
 experiments with user-defined names and respective classes. 
 Containing an ExperimentList class object of length 3: 
 [1] metabolomics: matrix with 577 rows and 533 columns 
 [2] metagenomics: matrix with 464 rows and 1304 columns 
 [3] host_transcriptomics: matrix with 55765 rows and 251 columns 

But then

> MOFAobject <- createMOFAobject(multiHMP2)
Creating MOFA object from a MultiAssayExperiment object...
Error in FUN(X[[i]], ...) : 
  colnames(subdata) == sampleMap(data)[sampleMap(data)[, "assay"] ==  .... are not all TRUE

I tried peeking into the createMOFAobject function but I can't seem to find the necessary line. If I run assays(multiHMP2) I get

List of length 3
names(3): metabolomics metagenomics host_transcriptomics

And the MOFA object works if I try to construct it with list(assays(multiHMP2)[['metagenomics']], ...etc))

Creating MOFA object from list of matrices,
 please make sure that samples are columns and features are rows...

Warning message:
In createMOFAobject(list(assays(multiHMP2)[["metagenomics"]], assays(multiHMP2)[["metabolomics"]],  :
  View names are not specified in the data, renaming them to: view_1, view_2, view_3

I am sure I am missing something in the construction of the object, but I'm not sure what. Thanks!

rargelaguet commented 5 years ago

Hi Andrea, Honestly, I barely use MultiAssayExperiment and I am not sure where the error comes from. Are you allowed to share the data? If so, can you join the Sack group and send me the object so I can have a look? Alternatively, you can try build de MOFAobject using a list of matrices, each entry being an assay with features as rows and samples as columns. More details in the documentation of createMOFAobject

P.S. I notice that your three assays are quite "imbalanced" (i.e. transcriptomics has way too many features compared to the other assays). Sometimes this can be a problem as the small views get underrepresented in the factors, see the FAQ in the README file. I recommend you filter the RNA data to select informative features. For example, subset protein-coding genes, filter out non-expressed genes and then select the top ~2,000 most variable genes.

andreanuzzo commented 5 years ago

Thank you Ricard. I have sent you a DM on the Slack group. I know the data are imbalanced, I will massage the transcriptomics with DeSeq2, but I was just playing a bit with the package after reading the paper.

Thank you!

andreanuzzo commented 5 years ago

Solved it: my sampleMap had further samples and in a different order of samples compared to colData. Not a problem for the MultiAssayExperiment but a problem for the creation of the MOFA object, due to the hidden function that it calls.

Thanks for your help. Might be good to add a more informative error message.