Skip to content

Automated gapfilling

Moritz E. Beber edited this page Sep 6, 2018 · 1 revision

Contributed by @fma91

This short tool is aimed to get easier the process of building a new model with an specific list of reaction. The reactions must be written in a deparated file in the next format using the ID_reactions from bigg:

EX_glc__D_e, PEPC,

Whitout spaces, tabs, enters or any other character wich may affect the lecture of the file. This module read the list and copy such reactions from the universal_model from bigg that contains all the reactions in the data base.

  • Usage:

import model_builder

model_builder.build_model(rxn_list_file ='reaction_list_file.txt')

  • To review the model:

model=model_builder.model

  • The resulting model must be saved using

cobra.io.write_sbml_model(model, "new_model_name.xml")

Note: the lower bounds-reactions in the generated model are 0, you have to change it acording to your needs.

Code Sample

import cobra
universe=cobra.io.load_json_model('universal_model.json') #load universe that mus be in the same folder or indicate the path of the file
model=cobra.Model() #generate a new model

def build_model(rxn_list_file): # introduce the name of the file containing the reactions that mus be in the same folder or indicate the path of the file
	rxn_list=open(rxn_list_file,'r').readline().split(',') # read file
	rxn_list.remove('\n')
	for item in rxn_list:	# loop to add reactions one by one
		model.add_reaction(universe.reactions.get_by_id(item))
		print item #printe the added reactions
	return model
Clone this wiki locally