This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error in `$<-.data.frame`(`*tmp*`, "feature", value = XXX) replacement has YYY rows, data has 0

Hello, I have been trying to get this MOFA tutorial to work with my data set, but keep getting this error when the model is trained.

Error in `$<-.data.frame`(`*tmp*`, "feature", value = c("chr1:3514872-3515102",  : 


replacement has 131600 rows, data has 0

My code is very similar to the tutorial:

data <- fread("C:/Users/cathe/Desktop/NordenLab/Project/06172021 MEFISTO/Works/LongDataframe10Samples.txt")
data = data.frame(data)

#create MOFA Object
MOFAobject <- create_mofa(data)
MOFAobject
plot_data_overview(MOFAobject)

#Options
data_opts <- get_default_data_options(MOFAobject)
model_opts <- get_default_model_options(MOFAobject)
train_opts <- get_default_training_options(MOFAobject)

#Build Train MOFA Object
MOFAobject <- prepare_mofa(
  object = MOFAobject,
  data_options = data_opts,
  model_options = model_opts,
  training_options = train_opts
)

#Run MOFA
outfile = file.path(getwd(),"model.hdf5")
MOFAobject.trained <- run_mofa(MOFAobject, outfile)

So there is something wrong with my data.frame, which is formatted like this:

> data
    sample       feature        value view
1      MEF 0610005C13Rik 3.465742e-01  RNA
2      MEF 0610007P14Rik 4.508857e+01  RNA
3      MEF 0610009B22Rik 3.927700e+01  RNA
4      MEF 0610009L18Rik 3.487817e+00  RNA
5      MEF 0610009O20Rik 3.056666e+01  RNA
...
779921  iPSC5 chrY:90824242-90824507    31 ATAC
779922  iPSC5 chrY:90825138-90825545    38 ATAC
779923  iPSC5 chrY:90835583-90835832    19 ATAC
779924  iPSC5 chrY:90841589-90841857    31 ATAC
779925  iPSC5 chrY:90843869-90844126    16 ATAC

Any thoughts on how to resolve this error? Similar Error and Solution : https://stackoverflow.com/questions/64164612/error-in-data-framex-name-value-replacement-has-1-row-data-has-0

r

That is not just a data.frame, it's still a data.table - print(data.frame_obj) does not print the last few rows.. Maybe try using setDF(data).

thank you for the comment. I copy/pasted the last few rows by using the tail function. Sorry for the confusion, it didn't show up exactly like that when I printed it.

I ran the following code based on your recommendation to use setDF(), but still getting the same error.

data <- fread("C:/Users/cathe/Desktop/NordenLab/Project/06172021 MEFISTO/Works/LongDataframe10Samples.txt")
data = setDF(data)

#create MOFA Object
MOFAobject <- create_mofa(data)

#Data Options
data_opts <- get_default_data_options(MOFAobject)
model_opts <- get_default_model_options(MOFAobject)
train_opts <- get_default_training_options(MOFAobject)


#Build Train MOFA Object
MOFAobject <- prepare_mofa(
  object = MOFAobject,
  data_options = data_opts,
  model_options = model_opts,
  training_options = train_opts
)

outfile = file.path(getwd(),"model2.hdf5")
MOFAobject.trained <- run_mofa(MOFAobject, outfile)

In that case, the problem is not what I thought it was. Maybe someone else has a more productive lead. Sorry I couldn't help more.

EDIT: I meant to say "not what I thought it was", not "now what I thought it was" - changes the whole meaning, sorry about that!

Could you provide example data as dput(head(data))?

I am guessing you are getting the error after this step: MOFAobject <- create_mofa(data), I'd address the developers at GitHub (MOFA2/issues), most likely the input dataframe is not in the right format.

Error is easily reproducible as:

x <- data.frame()
x$a <- 1:3
# Error in `$<-.data.frame`(`*tmp*`, a, value = 1:3) : 
#   replacement has 3 rows, data has 0

So that error might be happening in the create_mofa() step?

Here is the dput(head(data))

> dput(head(data))
structure(list(sample = c("MEF", "MEF", "MEF", "MEF", "MEF", 
"MEF"), feature = c("0610005C13Rik", "0610007P14Rik", "0610009B22Rik", 
"0610009L18Rik", "0610009O20Rik", "0610010B08Rik"), value = c(0.346574178, 
45.08857437, 39.27700337, 3.487817488, 30.56665753, 0.021197777
), view = c("RNA", "RNA", "RNA", "RNA", "RNA", "RNA")), row.names = c(NA, 
6L), class = "data.frame")

Here is their example in the tutorial, which does not cause the same error:

    > dput(head(dt))
structure(list(sample = c("sample_0_group_0", "sample_1_group_0", 
"sample_2_group_0", "sample_3_group_0", "sample_4_group_0", "sample_5_group_0"
), group = c("group_0", "group_0", "group_0", "group_0", "group_0", 
"group_0"), feature = c("feature_0_view_0", "feature_0_view_0", 
"feature_0_view_0", "feature_0_view_0", "feature_0_view_0", "feature_0_view_0"
), view = c("view_0", "view_0", "view_0", "view_0", "view_0", 
"view_0"), value = c(-2.05, 0.1, 1.44, -0.28, -0.88, -1.18)), row.names = c(NA, 
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x000001e4a5551ef0>)

0 answers

No answers yet.

Log in to answer this question.