1

While executing this code the following error was obtained: I want to rbind the results to a dataframe from the for loop. The problem is in the object "y.1", the resulting dataframe has 3/4/5 values. I want a dataframe with 5 columns and substitute zeros with values else, keep it as zeros.

model_reactants is a list of reactants from the sbml.model which is a rsbml object of class "Model".

model_reactants=sapply(reactions(sbml.model), function(x) x@reactants)
x.1<- data.frame(matrix(0,ncol = 1, nrow = 4155))
y.1<- data.frame(matrix(0,ncol = 5, nrow = 4155))

for (r in 1:length(model_reactants)){
    x=names(model_reactants[r])
    y=names(model_reactants[[r]])
    x.1[r,]=c(x)
    y.1[r,]=c(y)
}

Error in `[<-.data.frame`(`*tmp*`, r, , value = c("M_13dampp_c", "M_h2o_c",  : 
replacement has 3 items, need 5

We have 4155 reactions as entries in the model. We hope to put the reactants into a dataframe as separate columns. Some reactions have from 2, 3, 4, 5, to 6 reactants and they vary in the different reaction entries. But the code we use currently repeats the values from the first and second column in entries where there are only 2 reactants.

eg: model: reaction1:
a+b-> c+d
reaction2:
e+f+g->h+i+j

expected output:
      col 1   col 2 col 3
row 1  a        b     NA
row 2  e        f     g

The sample structure of the model_reactants is given here.

dput(model_reactants[1:5]) structure(list(R_13DAMPPOX = structure(list(M_13dampp_c = , M_h2o_c = , M_o2_c = ), .Names = c("M_13dampp_c", "M_h2o_c", "M_o2_c")), R_24_25VITD2Hm = structure(list(M_h_m = , M_nadph_m = , M_o2_m = , M_25hvitd2_m = ), .Names = c("M_h_m", "M_nadph_m", "M_o2_m", "M_25hvitd2_m")), R_24_25VITD3Hm = structure(list( M_h_m = , M_nadph_m = , M_o2_m = , M_25hvitd3_m = ), .Names = c("M_h_m", "M_nadph_m", "M_o2_m", "M_25hvitd3_m")), R_25VITD2Hm = structure(list( M_h_m = , M_nadph_m = , M_o2_m = , M_25hvitd2_m = ), .Names = c("M_h_m", "M_nadph_m", "M_o2_m", "M_25hvitd2_m")), R_25VITD3Hm = structure(list( M_h_m = , M_nadph_m = , M_o2_m = , M_25hvitd3_m = ), .Names = c("M_h_m", "M_nadph_m", "M_o2_m", "M_25hvitd3_m"))), .Names = c("R_13DAMPPOX", "R_24_25VITD2Hm", "R_24_25VITD3Hm", "R_25VITD2Hm", "R_25VITD3Hm" ))

  • You need to share include what this "model_reactants" object is. – s_baldur Jul 17 '16 at 20:22
  • @snoram Updated the information about the object. – piyush chopra Jul 17 '16 at 20:27
  • Can you have a look at [this link](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) please. If you can produce a **small** example dataset, and show the expected outcome, it will be much easier to get help. – user20650 Jul 17 '16 at 21:08
  • okay, thanks for updating, but a little more info is needed please. You are clear on expected output, but not on the inputs. Can you edit your questoin with the results of `dput(model_reactants[1:5])` (if it makes sense to index in this way) please. – user20650 Jul 17 '16 at 21:58
  • @user20650 yes it sure does make sense. I am the object is int he form of slots. So the first element I am capturing it into the "x" object and the second is a list of metaolites. Sometimes containing 3, or 4, or 5 slots. Accordingly I need to capture them into the "y" object and create a dataframe. If there are 3 slots then only 3 entries should be there in the dataframe and the other two columns should display "0" or "NA" – piyush chopra Jul 17 '16 at 22:51
  • Thanks for the update. Unfortunately it does not run. (try copying and pasting it to a fresh R session) – user20650 Jul 18 '16 at 08:14

0 Answers0