Parent Directory
|
Revision Log
Revision 1.3 - (view) (download) (as text)
1 : | hwang | 1.1 | #include <stdio.h> |
2 : | #include <string> | ||
3 : | #include <vector> | ||
4 : | #include <set> | ||
5 : | #include <iterator> | ||
6 : | #include <fstream> | ||
7 : | #include <iostream> | ||
8 : | #include <sys/timeb.h> | ||
9 : | |||
10 : | #include "RecoReadout/RecoElem.hh" | ||
11 : | #include "RecoReadout/Reaction.hh" | ||
12 : | #include "MExplorer/xduGen.hh" | ||
13 : | |||
14 : | #include "sbml/SBMLReader.h" | ||
15 : | #include "sbml/SBMLTypes.h" | ||
16 : | |||
17 : | |||
18 : | using namespace std; | ||
19 : | |||
20 : | //************************************************************************ | ||
21 : | |||
22 : | |||
23 : | RecoElem* SBMLtoRecoElem(Model_t* m); | ||
24 : | void inreaction(Reaction_t* r, vector<Reaction>& rxns); | ||
25 : | void printList (RecoElem& elem); | ||
26 : | //************************************************************************ | ||
27 : | |||
28 : | |||
29 : | |||
30 : | |||
31 : | //************************************************************************ | ||
32 : | int | ||
33 : | main(int argc, char* argv[] ) { | ||
34 : | //************************************************************************ | ||
35 : | |||
36 : | |||
37 : | SBMLDocument_t *d; | ||
38 : | Model_t *m; | ||
39 : | |||
40 : | if (argc != 2) | ||
41 : | { | ||
42 : | printf("usage: readSBML <filename>\n"); | ||
43 : | return 1; | ||
44 : | } | ||
45 : | |||
46 : | |||
47 : | d = readSBML(argv[1]); | ||
48 : | |||
49 : | m = d->model; | ||
50 : | if (0==m) { | ||
51 : | cout << "Did not read model " << argv[1] << endl; | ||
52 : | exit( 1 ); | ||
53 : | } | ||
54 : | |||
55 : | RecoElem* elem = SBMLtoRecoElem (m); | ||
56 : | |||
57 : | cout << "************************" << endl; | ||
58 : | printList(*elem); | ||
59 : | cout << "************************" << endl; | ||
60 : | |||
61 : | std::string path=""; | ||
62 : | xduGen( *elem, path ); | ||
63 : | |||
64 : | return 0; | ||
65 : | } | ||
66 : | |||
67 : | |||
68 : | |||
69 : | |||
70 : | //************************************************************************ | ||
71 : | void printList (RecoElem& elem) | ||
72 : | //************************************************************************ | ||
73 : | { | ||
74 : | |||
75 : | // I don't think there's any subelements. Model w/ one subelement, and 1 kid | ||
76 : | |||
77 : | vector<RecoElem>& subElem = elem.getSubElements(); | ||
78 : | vector<Reaction>& rxns = elem.getReactions(); | ||
79 : | |||
80 : | int nrxns= rxns.size (); | ||
81 : | int nkids= subElem.size (); | ||
82 : | |||
83 : | cout << "MY NAME: " << elem.getName() << endl; | ||
84 : | cout << " No. of reactions " << nrxns << endl; | ||
85 : | cout << " No. of kids: " << nkids << endl; | ||
86 : | |||
87 : | |||
88 : | for (int l=0; l< nrxns ; l++) { | ||
89 : | efrank | 1.2 | cout << rxns[l].asString( ) << endl; |
90 : | hwang | 1.1 | } |
91 : | |||
92 : | |||
93 : | for (int i=0; i<nkids; i++){ | ||
94 : | cout << "in deeper **** " << endl; | ||
95 : | printList(subElem[i]); | ||
96 : | cout << "back up *** " << endl; | ||
97 : | } | ||
98 : | |||
99 : | return; | ||
100 : | } | ||
101 : | |||
102 : | |||
103 : | |||
104 : | |||
105 : | |||
106 : | //********************************************************************** | ||
107 : | RecoElem* | ||
108 : | SBMLtoRecoElem(Model_t* m) { | ||
109 : | //************************************************************************ | ||
110 : | |||
111 : | string name; | ||
112 : | int id, numreactant, numproduct; | ||
113 : | |||
114 : | Reaction_t* r; | ||
115 : | Species_t* s; | ||
116 : | List_t* rlist = m->reaction; | ||
117 : | |||
118 : | |||
119 : | //not sure what to put as an id, 0 for now | ||
120 : | name=m->name; | ||
121 : | id=0; | ||
122 : | |||
123 : | efrank | 1.3 | RecoElem* elem= new RecoElem( name, id); |
124 : | hwang | 1.1 | |
125 : | vector<Reaction>& rxns = elem->getReactions(); | ||
126 : | |||
127 : | |||
128 : | //put in reactions | ||
129 : | int reactionsize= List_size(rlist); | ||
130 : | //cout << "number of reactions " << reactionsize << endl; | ||
131 : | |||
132 : | |||
133 : | |||
134 : | for (int j=0; j< reactionsize ; j++) | ||
135 : | { | ||
136 : | |||
137 : | // cout << "Reaction : " << j <<endl; | ||
138 : | r=Model_getReaction(m,j); | ||
139 : | //cout << r->name << endl; | ||
140 : | inreaction(r,rxns); | ||
141 : | |||
142 : | // cout << endl; | ||
143 : | } | ||
144 : | |||
145 : | |||
146 : | return elem; | ||
147 : | |||
148 : | |||
149 : | } | ||
150 : | //************************************************************************ | ||
151 : | void | ||
152 : | inreaction(Reaction_t* r, vector<Reaction>& rxns) { | ||
153 : | //************************************************************************ | ||
154 : | |||
155 : | int id; | ||
156 : | int dir; | ||
157 : | |||
158 : | int numreactant=Reaction_getNumReactants(r); | ||
159 : | int numproduct=Reaction_getNumProducts(r); | ||
160 : | SpeciesReference_t* sr, *pr; | ||
161 : | |||
162 : | //id not sure what to put here | ||
163 : | //direction is reversible or not. false, true | ||
164 : | efrank | 1.2 | |
165 : | Reaction::Direction reDir; | ||
166 : | hwang | 1.1 | id=0; |
167 : | dir=r->reversible; | ||
168 : | efrank | 1.2 | Reaction rxn( id, Reaction::forward ); |
169 : | if ( dir ) { | ||
170 : | rxn.setDirection( Reaction::both ); | ||
171 : | } | ||
172 : | hwang | 1.1 | |
173 : | vector<string>& reactant = rxn.getInputMetaboliteNames(); | ||
174 : | vector<string>& product = rxn.getOutputMetaboliteNames(); | ||
175 : | |||
176 : | vector<int>& inMetabN = rxn.getInputStoich(); | ||
177 : | vector<int>& outMetabN = rxn.getOutputStoich(); | ||
178 : | |||
179 : | //add reactants | ||
180 : | //add products | ||
181 : | |||
182 : | |||
183 : | |||
184 : | //figuring out the common denominator | ||
185 : | int rdem = 1; | ||
186 : | int pdem = 1; | ||
187 : | int demstoich; | ||
188 : | |||
189 : | for (int j=0; j< numreactant ; j++ ) | ||
190 : | { | ||
191 : | sr=Reaction_getReactant(r,j); | ||
192 : | rdem= rdem * sr->denominator; | ||
193 : | |||
194 : | } | ||
195 : | |||
196 : | |||
197 : | for (int m=0; m<numproduct; m++) | ||
198 : | { | ||
199 : | pr=Reaction_getProduct(r,m); | ||
200 : | pdem= pdem * pr->denominator; | ||
201 : | |||
202 : | } | ||
203 : | |||
204 : | |||
205 : | demstoich = rdem * pdem; | ||
206 : | // cout << "common denominator: " << demstoich; | ||
207 : | |||
208 : | for (int k=0; k < numreactant ; k++ ) | ||
209 : | { | ||
210 : | sr=Reaction_getReactant(r,k); | ||
211 : | // cout << "test reactant: " << sr->species << endl; | ||
212 : | |||
213 : | |||
214 : | reactant.push_back (sr->species); | ||
215 : | inMetabN.push_back( demstoich * sr->stoichiometry/sr->denominator); | ||
216 : | } | ||
217 : | |||
218 : | //cout << rxn.asString()[0]; | ||
219 : | |||
220 : | for (int l=0; l<numproduct; l++) | ||
221 : | { | ||
222 : | |||
223 : | pr=Reaction_getProduct(r,l); | ||
224 : | // cout << "product: " << pr->species << endl; | ||
225 : | |||
226 : | product.push_back(pr->species); | ||
227 : | outMetabN.push_back(demstoich * pr->stoichiometry/ pr->denominator ); | ||
228 : | } | ||
229 : | |||
230 : | rxns.push_back(rxn); | ||
231 : | |||
232 : | return; | ||
233 : | } |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |