Пример #1
0
def readEquations(equationSource):
    if isinstance(equationSource, basestring):
        eq_file = open(equationSource, 'r')

        def read():
            line = eq_file.readline()
            line = line.replace('"', '').replace(',', '')
            return line
    else:
        global l
        l = 0

        def read():
            global l
            if l == len(equationSource): raise StopIteration
            line = equationSource[l]
            line = line.replace('"', '').replace(',', '').strip()
            l += 1
            return line + '\n'

    global newLine
    newLine = True
    global variables
    variables = []
    global functions
    functions = []
    global parameters
    parameters = []

    def useToken(key, value, Coord1, Coord2, fullLine):
        global newLine, variables, obsFunctions, parameters
        if key == 1:  #1: NAME  2: NUMBER  51: OP   4: NEWLINE  0: ENDMARKER
            if newLine == True:
                variables.append(giveVar(value))
                functions.append(
                    giveParsed(fullLine[(fullLine.find('=') +
                                         1):len(fullLine)]))
            else:
                parameters.append(giveVar(value))
            newLine = False
        elif key == 4:
            newLine = True

    tokenize(read, useToken)

    parameters = sorted(list(set(parameters)), key=spy.default_sort_key)

    for entry in variables:
        if entry in parameters:
            parameters.remove(entry)

    return variables, functions, parameters
Пример #2
0
def readEquations(equationSource):
	if isinstance(equationSource, basestring):
		eq_file = open(equationSource,'r')
		def read():
			line = eq_file.readline()
			line = line.replace('"','').replace(',','')
			return line
	else:
		global l
		l = 0
		def read():
			global l
			if l == len(equationSource): raise StopIteration
			line = equationSource[l]
			line = line.replace('"','').replace(',','').strip()
			l += 1
			return line + '\n'
	
	global newLine; newLine = True
	global variables; variables = []
	global functions; functions = []
	global parameters; parameters = []
	
	def useToken(key, value, Coord1, Coord2, fullLine):
		global newLine, variables, obsFunctions, parameters
		if key == 1: #1: NAME  2: NUMBER  51: OP   4: NEWLINE  0: ENDMARKER
			if newLine == True:
				variables.append(giveVar(value))
				functions.append(giveParsed(fullLine[(fullLine.find('=')+1):len(fullLine)]))
			else:
				parameters.append(giveVar(value))
			newLine = False
		elif key == 4:
			newLine = True
		
	tokenize(read,useToken)
	
	parameters = sorted(list(set(parameters)), key=spy.default_sort_key)
	
	for entry in variables:
		if entry in parameters:
			parameters.remove(entry)
			
	return variables, functions, parameters
Пример #3
0
def readModel(fileName, delimT):
	if delimT == 't':
		delim = '\t'
	else:
		delim = delimT
	variables = []
	parameters = []
	flows = []
	stoichiometry = []

	global l; l = -1
	
	with open(fileName, 'rb') as defFile:
		reader = csv.reader(defFile, delimiter=delim, quoting=csv.QUOTE_NONE)
		
		row = reader.next()
		for i in range(2,len(row)):
			row[i] = row[i].replace('"','')
			variables.append(giveVar(row[i]))
		
		lines = 0 
		stoichiometryList = []
		for row in reader:
			row[1] = row[1].replace('"','')
			row[1] = row[1].replace('^','**')
			flows.append(row[1])
			
			lines += 1
			for i in range(2,len(row)):
				if row[i] == '': num = 0
				else: 
					row[i] = row[i].replace('"','')
					if row[i] == '':
						row[i] = 0
					num = int(row[i])
				stoichiometryList.append(num)

		stoichiometryT = spy.Matrix(lines,len(variables),stoichiometryList)
		stoichiometry = stoichiometryT.transpose()

		def read():
			global l
			l += 1
			if l >= len(flows): raise StopIteration
			else: return flows[l]

		def useToken(key, value, Coord1, Coord2, fullLine):
			if key == 1:
				parameters.append(giveVar(value))

		tokenize(read,useToken)#get parameters from flows

	parameters = sorted(list(set(parameters)), key=spy.default_sort_key)

	for entry in variables:
		if entry in parameters:
			parameters.remove(entry)

	for f in range(len(flows)):
		flows[f] = giveParsed(flows[f])
		
	return variables, parameters, spy.Matrix(len(flows),1,flows), stoichiometry
Пример #4
0
def readModel(fileName, delimT):
    if delimT == 't':
        delim = '\t'
    else:
        delim = delimT
    variables = []
    parameters = []
    flows = []
    stoichiometry = []

    global l
    l = -1

    with open(fileName, 'rb') as defFile:
        reader = csv.reader(defFile, delimiter=delim, quoting=csv.QUOTE_NONE)

        row = reader.next()
        for i in range(2, len(row)):
            row[i] = row[i].replace('"', '')
            variables.append(giveVar(row[i]))

        lines = 0
        stoichiometryList = []
        for row in reader:
            row[1] = row[1].replace('"', '')
            row[1] = row[1].replace('^', '**')
            flows.append(row[1])

            lines += 1
            for i in range(2, len(row)):
                if row[i] == '': num = 0
                else:
                    row[i] = row[i].replace('"', '')
                    if row[i] == '':
                        row[i] = 0
                    num = int(row[i])
                stoichiometryList.append(num)

        stoichiometryT = spy.Matrix(lines, len(variables), stoichiometryList)
        stoichiometry = stoichiometryT.transpose()

        def read():
            global l
            l += 1
            if l >= len(flows): raise StopIteration
            else: return flows[l]

        def useToken(key, value, Coord1, Coord2, fullLine):
            if key == 1:
                parameters.append(giveVar(value))

        tokenize(read, useToken)  #get parameters from flows

    parameters = sorted(list(set(parameters)), key=spy.default_sort_key)

    for entry in variables:
        if entry in parameters:
            parameters.remove(entry)

    for f in range(len(flows)):
        flows[f] = giveParsed(flows[f])

    return variables, parameters, spy.Matrix(len(flows), 1,
                                             flows), stoichiometry