Trees | Indices | Help |
---|
|
1 # Copyright 2001 by Tarjei Mikkelsen. All rights reserved. 2 # This code is part of the Biopython distribution and governed by its 3 # license. Please see the LICENSE file that should have been included 4 # as part of this package. 5 6 """ 7 This module provides code to convert Bio.Pathway.System objects into 8 a text file that can be used as input for the MetaTool program. 9 10 For more information on MetaTool, please refer to: 11 12 http://www2.bioinf.mdc-berlin.de/metabolic/metatool/ 13 14 """ 15 16 from Bio.Pathway import Reaction 17 from Bio.Pathway import System 18 19 20 # NOTE: Change enzyme name creation to allow for a function to be passed 21 # in that can be applied to r.data to extract a name 2224 """Converts a Bio.Pathway.System object to a MetaTool input string. 25 26 Note that to be a valid input string, the enzyme names of the reactions 27 in the system must conform to the MetaTool requirements. 28 29 Enzyme names are automatically genrated from the catalys attribute of 30 each reaction using the following scheme: 31 32 enzyme_name = "_".join([str(x[0]) for x in r.catalysts]) 33 34 If an enzyme name has already been used, a positive integer will be 35 appended to this name to meet the MetaTool input requirements. If this 36 behaviour is undesired, set the optional parameter 'generate_names' to 37 false. All enzyme names will the be 'E_x', where x is an unique integer. 38 39 The optional parameters metext and metint can be used to specify the 40 external and internal metabolites according to the following rules: 41 42 1. If metext is set, the species in it will be considered external. 43 All other species will be considered internal. 44 45 2. Otherwise, if metint is set, the species in it will be considered 46 internal. All other species will be considered external. 47 48 3. Otherwise, all species will be considered external. 49 50 If specified, metext and metint must not contains species that are not 51 contained in the input system. 52 """ 53 if not isinstance(system, System): 54 raise TypeError, "Input is not a System object" 55 # Build the ENZREV and ENZIRREV strings: 56 enzrev = [] 57 enzirrev = [] 58 enz_names = {} 59 enz_map = {} 60 for r in system.reactions(): 61 # build an unique enzyme name 62 enz_name = "" 63 if r.catalysts and generate_names: 64 enz_name += "_".join([str(x[0]) for x in r.catalysts]) 65 else: 66 enz_name += "E" 67 if enz_names.has_key(enz_name): 68 enz_names[enz_name] += 1 69 enz_name += "_" + str(enz_names[enz_name]) 70 else: 71 enz_names[enz_name] = 0 72 # keep (name, reaction) pair for later 73 enz_map[enz_name] = r 74 # add to the corresponding list 75 if r.reversible: 76 enzrev.append(enz_name) 77 else: 78 enzirrev.append(enz_name) 79 # create the actual strings: 80 enzrev_str = "-ENZREV\n" + " ".join(enzrev) + "\n" 81 enzirrev_str = "-ENZIRREV\n" + " ".join(enzirrev) + "\n" 82 # Build the METINT and METEXT strings: 83 metabolites = system.species() 84 metint_str = "-METINT\n" 85 metext_str = "-METEXT\n" 86 if metext: 87 for m in metext: 88 if m in metabolites: 89 metabolites.remove(m) 90 else: 91 raise ValueError, "metext contains an unknown metabolite" 92 for m in metint: 93 if not m in metabolites: 94 raise ValueError, "metint contains an unknown metabolite" 95 metext_str += " ".join([str(m) for m in metext]) + "\n" 96 metint_str += " ".join([str(m) for m in metabolites]) + "\n" 97 elif metint: 98 for m in metint: 99 if m in metabolites: 100 metabolites.remove(m) 101 else: 102 raise ValueError, "metint contains an unknown metabolite" 103 for m in metext: 104 if not m in metabolites: 105 raise ValueError, "metext contains an unknown metabolite" 106 metint_str += " ".join([str(m) for m in metint]) + "\n" 107 metext_str += " ".join([str(m) for m in metabolites]) + "\n" 108 else: 109 metext_str += " ".join([str(m) for m in metabolites]) + "\n" 110 metint_str += "\n" 111 # Build the CAT string 112 cat_str = "-CAT\n" 113 for e in enz_map.keys(): 114 r = enz_map[e] 115 cat_str += e + " : " 116 # change the reaction string rep to the MetaTool format 117 reaction_str = str(r) 118 reaction_str = reaction_str.replace("-->","=") 119 reaction_str = reaction_str.replace("<=>","=") 120 cat_str += reaction_str + " .\n" 121 # Return the complete MetaTool input string: 122 return enzrev_str + "\n" + \ 123 enzirrev_str + "\n" + \ 124 metint_str + "\n" + \ 125 metext_str + "\n" + \ 126 cat_str + "\n"127
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Sep 15 09:26:41 2008 | http://epydoc.sourceforge.net |