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" ))