Hello,

I'm trying to convert a vector of string objects to a numeric object by
initializing the variables with values.  I use the function below to scan
through a matrix and create mass action flux relationships:

makeMassActionFluxes = function(sMatrix) {
 #Allocate a matrix with identical dimensions as the inputted stoichiometric
matrix
 temp = matrix(nrow = dim(sMatrix)[1], ncol = dim(sMatrix)[2])
velocities = vector(length = dim(sMatrix)[2])
 ## This series of 'for' loops scans the stoichiometrix matrix looking for
negative integers.
 ## Once it identifies a negative integer it pulls the row name and
exponentiates it to the
## appropriate stoichiometry, creating the flux expression.
 for (i in 1:dim(sMatrix)[1]) {
for (j in 1:dim(sMatrix)[2]) {
 if (sMatrix[i, j] >= 0) (temp[i, j] = NA)
else temp[i, j] = paste(rownames(sMatrix)[i], '^', -sMatrix[i, j], sep = '')
 }
 }
 ## Scan temp by column.  Ignore strings that begin with '1.'  Use paste()
to "multiply" strings.
 for (k in 1:dim(temp)[2]) {#Loop through columns
 velocities[k] = paste(c(temp[ , k]), sep = '', collapse = '*')
 velocities[k] = gsub('*NA', '', velocities[k], fixed = TRUE)
velocities[k] = gsub('NA*', '', velocities[k], fixed = TRUE)
 }
 return(velocities)
}

If I pass in the following example matrix, I get a list of flux expressions
('v') just like I want:

testS = matrix(c(-1, 0, 2, -1, -1, 0, 0, -1, -1, 1, 0, 0, 0, 1, 0),
nrow = 5,
ncol = 3,
 byrow = TRUE)
rownames(testS) = c("met1", "met2", "met3", "met4", "met5")
colnames(testS) = c('rxn1', 'rxn2', 'rxn3')

v = makeMassActionFluxes(testS)
v
[1] "met1^1*met2^1" "met2^1*met3^1" "met3^1"

My next step is to use an ODE generating function to initialize values for
the met variables.

state = c(met1 = 10, met2 = 10, met3 = 10, met4 = 10, met5 = 10)
parameters = 1
ODE = function(t, state, parameters, S, velocity) {
 with(as.list(c(state, parameters, S, velocity)), {
 des = S %*% v
 #The products should look like this:
#dmet1 = (-1)*met1^1*met2^1 + (0)*met2^1*met3^1 + (2)*met3^1
 #Return
list(des)
 })
 }

When I call 'makeODE' I get the following error (which I expected):

Error in S %*% v : requires numeric/complex matrix/vector arguments

I'm wondering if there is an easy way to remove the quotes on the elements
on 'v' or make 'v' into a numeric vector so that I can initialize them with
values?  Or, is there an easier way to generate the flux expressions in my
'makeMassActionFluxes' function so that eventually passing in initial values
for the met variables will be easier?

Thanks in advance!

Erin

-- 
Erin Rachael Shellman
The University of Michigan
Bioinformatics PhD Candidate
http://www.erinshellman.com
shellman@umich.edu
(937) 321.1129

	[[alternative HTML version deleted]]

