[Bio] / FigKernelPackages / FIGMODELdatabase.pm Repository:
ViewVC logotype

Annotation of /FigKernelPackages/FIGMODELdatabase.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (view) (download) (as text)

1 : chenry 1.7 use lib "/home/chenry/public_html/FIGdisk/dist/releases/snap-2006-0223/cee/lib/ModelSEED/";
2 :     use DBMaster;
3 :     use Sapling;
4 :     use ModelObjectType;
5 :    
6 : chenry 1.1 package FIGMODELdatabase;
7 :     use strict;
8 : chenry 1.2 use Fcntl qw/:DEFAULT :seek :flock/;
9 : chenry 1.1
10 :     =head1
11 :    
12 :     =head2 Introduction
13 :     Module for loading and altering data in the model database.
14 :     There will be a local and remote version of this module.
15 :     The remote version will be implemented using the server technology.
16 :    
17 :     =head2 Core Object Methods
18 :    
19 :     =head3 new
20 :     Definition:
21 :     FIGMODELdatabase = FIGMODELdatabase->new();
22 :     Description:
23 :     This is the constructor for the FIGMODELdatabase object.
24 :     =cut
25 :    
26 :     sub new {
27 :     my ($class,$DatabaseDirectory,$figmodel) = @_;
28 :     my $self;
29 :     $self->{"_database root directory"}->[0] = $DatabaseDirectory;
30 :     $self->{"_figmodel"}->[0] = $figmodel;
31 :     bless $self;
32 :     return $self;
33 :     }
34 :    
35 : chenry 1.2 =head3 figmodel
36 : chenry 1.1 Definition:
37 : chenry 1.2 FIGMODEL = FIGMODELdatabase->figmodel();
38 : chenry 1.1 Description:
39 : chenry 1.2 Returns a FIGMODEL object
40 : chenry 1.1 =cut
41 : chenry 1.2 sub figmodel {
42 :     my ($self) = @_;
43 :     return $self->{"_figmodel"}->[0];
44 : chenry 1.1 }
45 :    
46 : chenry 1.4 =head3 fail
47 :     Definition:
48 :     -1 = FIGMODEL->fail();
49 :     Description:
50 :     Standard return for failed functions.
51 :     =cut
52 :     sub fail {
53 :     my ($self) = @_;
54 :     return $self->figmodel()->fail();
55 :     }
56 :    
57 :     =head3 success
58 :     Definition:
59 :     1 = FIGMODEL->success();
60 :     Description:
61 :     Standard return for successful functions.
62 :     =cut
63 :     sub success {
64 :     my ($self) = @_;
65 :     return $self->figmodel()->success();
66 :     }
67 :    
68 : chenry 1.2 =head3 config
69 : chenry 1.1 Definition:
70 : chenry 1.2 ref::key value = FIGMODELdatabase->config(string::key);
71 : chenry 1.1 Description:
72 : chenry 1.2 Trying to avoid using calls that assume configuration data is stored in a particular manner.
73 :     Call this function to get file paths etc.
74 : chenry 1.1 =cut
75 : chenry 1.2
76 :     sub config {
77 :     my ($self,$key) = @_;
78 :    
79 :     return $self->figmodel()->config($key);
80 : chenry 1.1 }
81 :    
82 : chenry 1.7 =head3 get_object_manager
83 :     Definition:
84 :     databasehandle:database handle for input object type = FIGMODELdatabase->get_object_manager(string::type);
85 :     Description:
86 :     =cut
87 :     sub get_object_manager {
88 :     my ($self,$type) = @_;
89 : chenry 1.18 my $ppoObjects = {"bof"=>1,"reaction"=>1,"compound"=>1,"queue"=>1,"job"=>1,"mgjob"=>1,"rastjob"=>1,"rasttestjob"=>1,"model"=>1,"user"=>1,"mgmodel"=>1,"fbaresult"=>1,"media"=>1,"mediacpd"=>1,"complex"=>1,"role"=>1,"cpxrole"=>1,"cpdals"=>1,"cpdbof"=>1,"cpdgrp"=>1,"cpdrxn"=>1,"rxnals"=>1,"rxncpx"=>1,"rxngrp"=>1,"rxnmdl"=>1};
90 : chenry 1.7 if (!defined($self->{_dbhandles}->{$type})) {
91 : chenry 1.17 if (defined($ppoObjects->{$type})) {
92 : chenry 1.16 #Checking on the status of the database and returned undefined if the status is zero
93 :     if ($self->config("PPO_tbl_".$type)->{status}->[0] == 0) {
94 :     return undef;
95 :     }
96 : chenry 1.8 my $temp = DBMaster->new(-database => $self->config("PPO_tbl_".$type)->{name}->[0],
97 :     -host => $self->config("PPO_tbl_".$type)->{host}->[0],
98 :     -user => $self->config("PPO_tbl_".$type)->{user}->[0],
99 :     -password => $self->config("PPO_tbl_".$type)->{password}->[0],
100 :     -port => $self->config("PPO_tbl_".$type)->{port}->[0],
101 :     -socket => $self->config("PPO_tbl_".$type)->{"socket"}->[0]);
102 : chenry 1.10 $self->{_dbhandles}->{$type} = $temp;
103 : chenry 1.7 } else {
104 : chenry 1.9 $self->{_dbhandles}->{$type} = ModelObjectType->new($self->figmodel(),$type);
105 : chenry 1.7 }
106 :     }
107 : chenry 1.17 if (defined($ppoObjects->{$type})) {
108 : chenry 1.10 my $table = $self->config("PPO_tbl_".$type)->{table}->[0];
109 :     return $self->{_dbhandles}->{$type}->$table();
110 :     }
111 : chenry 1.7 return $self->{_dbhandles}->{$type};
112 :     }
113 :    
114 : chenry 1.18 =head3 get_object
115 :     Definition:
116 :     PPOobject:first object matching specified type and query = FIGMODELdatabase->get_object(string::type,{}:query);
117 :     Description:
118 :     =cut
119 :     sub get_object {
120 :     my ($self,$type,$query) = @_;
121 :     my $objMgr = $self->get_object_manager($type);
122 :     if (!defined($objMgr)) {
123 :     return undef;
124 :     }
125 :     my $objs = $objMgr->get_objects($query);
126 :     if (!defined($objs->[0])) {
127 :     return undef;
128 :     }
129 :     return $objs->[0];
130 :     }
131 :    
132 :     =head3 get_objects
133 :     Definition:
134 :     [PPOobject]:objects matching specified type and query = FIGMODELdatabase->get_object(string::type,{}:query);
135 :     Description:
136 :     =cut
137 :     sub get_objects {
138 :     my ($self,$type,$query) = @_;
139 :     my $objMgr = $self->get_object_manager($type);
140 :     if (!defined($objMgr)) {
141 :     return undef;
142 :     }
143 :     return $objMgr->get_objects($query);
144 :     }
145 :    
146 :     =head3 get_object_manager
147 :     Definition:
148 :     databasehandle:database handle for input object type = FIGMODELdatabase->get_object_manager(string::type);
149 :     Description:
150 :     =cut
151 :     sub check_out_new_id {
152 :     my ($self,$type) = @_;
153 :     if (!defined($self->{_dbhandles}->{id})) {
154 :     $self->{_dbhandles}->{id} = DBMaster->new(-database => $self->config("PPO_tbl_id")->{name}->[0],
155 :     -host => $self->config("PPO_tbl_id")->{host}->[0],
156 :     -user => $self->config("PPO_tbl_id")->{user}->[0],
157 :     -password => $self->config("PPO_tbl_id")->{password}->[0],
158 :     -port => $self->config("PPO_tbl_id")->{port}->[0],
159 :     -socket => $self->config("PPO_tbl_id")->{"socket"}->[0]);
160 :     }
161 :     #Get the id
162 :     my $data = $self->{_dbhandles}->{id}->backend()->dbh->selectrow_arrayref('select id,prefix,digits from ModelDB.CURRENTID where (object = "'.$type.'") for update;');
163 :     #Iterate the ID
164 :     $self->{_dbhandles}->{id}->backend()->dbh->do('UPDATE ModelDB.CURRENTID SET id = id + 1 WHERE (object = "'.$type.'");');
165 :     $self->{_dbhandles}->{id}->backend()->dbh->commit();
166 :     #Creating the id
167 :     while (length($data->[0]) < $data->[2]) {
168 :     $data->[0] = "0".$data->[0];
169 :     }
170 :     return $data->[1].$data->[0];
171 :     }
172 :    
173 : chenry 1.7 =head3 is_type
174 :     Definition:
175 :     (0/1) = FIGMODELdatabase->is_type(string::type);
176 :     Description:
177 :     Checks if the input string is an object type in the database. "1" for yes, "0" for no.
178 :     =cut
179 :     sub is_type {
180 :     my ($self,$type) = @_;
181 :     if (defined($self->figmodel()->config("object types")->{$type})) {
182 :     return 1;
183 :     }
184 :     return 0;
185 :     }
186 :    
187 :     =head3 db_link
188 :     Definition:
189 :     {string:from type IDs => [string]:list of to type IDs} = FIGMODELdatabase->db_link(string:link from type,string:link to type,{string:type=>[string]:type list]});
190 :     Description:
191 :     Returns a hash with the "from type" as keys and arrays of "to types" as values.
192 :     =cut
193 :     sub db_link {
194 :     my ($self,$fromType,$toType,$idlist) = @_;
195 :     my $result;
196 :     foreach my $id (@{$idlist}) {
197 :     if ($fromType eq "interval") {
198 :     if ($toType eq "feature") {
199 :     my $IntervalTable = $self->GetDBTable("INTERVAL TABLE");
200 :     if (defined($IntervalTable)) {
201 :     my $Row = $IntervalTable->get_row_by_key($id,"ID");
202 :     if (defined($Row) && defined($Row->{"START"}->[0]) && defined($Row->{"END"}->[0])) {
203 :     my $GeneList = $self->figmodel()->genes_of_interval($Row->{"START"}->[0],$Row->{"END"}->[0],$Row->{GENOME}->[0]);
204 :     for(my $i=0; $i < @{$GeneList}; $i++) {
205 :     $GeneList->[$i] = "fig|".$Row->{GENOME}->[0].".".$GeneList->[$i];
206 :     }
207 :     if (defined($GeneList)) {
208 :     $result->{$id} = $GeneList;
209 :     }
210 :     }
211 :     }
212 :     }
213 :     } elsif ($fromType eq "strain") {
214 :     if ($toType eq "interval") {
215 :     my $StrainTable = $self->GetDBTable("STRAIN TABLE");
216 :     if (defined($StrainTable)) {
217 :     my $Row = $StrainTable->get_row_by_key($id,"ID");
218 :     if (defined($Row) && defined($Row->{"INTERVALS"})) {
219 :     $result->{$id} = $Row->{"INTERVALS"};
220 :     }
221 :     }
222 :     } elsif ($toType eq "feature") {
223 :     my $temp = $self->db_link("strain","interval",[$id]);
224 :     if (defined($temp->{$id})) {
225 :     my $newArray;
226 :     for (my $i=0; $i < @{$temp->{$id}}; $i++) {
227 :     my $temptwo = $self->db_link("interval","feature",[$temp->{$id}->[$i]]);
228 :     if (defined($temptwo->{$temp->{$id}->[$i]})) {
229 :     push(@{$newArray},@{$temptwo->{$temp->{$id}->[$i]}});
230 :     }
231 :     }
232 :     }
233 :     }
234 : chenry 1.12 } else {
235 :     my $tbl = $self->GetLinkTable(uc($toType),uc($fromType));
236 :     if (!defined($tbl)) {
237 :     $tbl = $self->GetLinkTable(uc($fromType),uc($toType));
238 :     }
239 :     if (defined($tbl)) {
240 :     my @rows = $tbl->get_rows_by_key($id,uc($fromType));
241 :     for (my $i=0; $i < @rows; $i++) {
242 :     push(@{$result->{$id}},$rows[$i]->{uc($toType)}->[0]);
243 :     }
244 :     }
245 : chenry 1.7 }
246 :     }
247 :     return $result;
248 :     }
249 :    
250 : chenry 1.2 =head3 set_cache
251 :     Definition:
252 :     FIGMODELdatabase->set_cache(string::key,ref::data);
253 :     Description:
254 :     Caching data
255 :     =cut
256 :     sub set_cache {
257 :     my ($self,$key,$data) = @_;
258 :    
259 :     $self->{CACHE}->{$key} = $data;
260 :     }
261 :    
262 :     =head3 get_cache
263 : chenry 1.1 Definition:
264 : chenry 1.2 ref::data = FIGMODELdatabase->get_cache(string::key);
265 : chenry 1.1 Description:
266 : chenry 1.2 Caching data
267 : chenry 1.1 =cut
268 : chenry 1.2
269 :     sub get_cache {
270 :     my ($self,$key) = @_;
271 :    
272 :     return $self->{CACHE}->{$key};
273 : chenry 1.1 }
274 :    
275 :     =head3 load_multiple_column_file
276 :     Definition:
277 :     [[string]] = FIGMODELdatabase->load_multiple_column_file(string::filename,string::delimiter);
278 :     Description:
279 :     Parses the two dimensional file specified by the input filename
280 :     =cut
281 :     sub load_multiple_column_file {
282 :     my ($self,$Filename,$Delimiter) = @_;
283 :    
284 :     my $DataArrayRefArrayRef = [];
285 :     if (open (INPUT, "<$Filename")) {
286 :     while (my $Line = <INPUT>) {
287 :     chomp($Line);
288 :     my $Data = [];
289 :     $Data->[0] = $Line;
290 :     if (length($Delimiter) > 0) {
291 :     @{$Data} = split(/$Delimiter/,$Line);
292 :     }
293 :     push(@{$DataArrayRefArrayRef},$Data);
294 :     }
295 :     close(INPUT);
296 :     } else {
297 :     $self->figmodel()->error_message("FIGMODELdatabase->load_multiple_column_file(".$Filename.",".$Delimiter."): could not load file!");
298 :     }
299 :     return $DataArrayRefArrayRef;
300 :     }
301 :    
302 :     =head3 load_single_column_file
303 :     Definition:
304 :     [string] = FIGMODELdatabase->load_single_column_file(string::filename,string::delimiter);
305 :     Description:
306 :     Parses the single column file specified by the input filename
307 :     =cut
308 :     sub load_single_column_file {
309 :     my ($self,$Filename,$Delimiter) = @_;
310 : chenry 1.19 if (!defined($Delimiter)) {
311 :     $Delimiter = "";
312 :     }
313 : chenry 1.1 my $DataArrayRef = [];
314 :     if (open (INPUT, "<$Filename")) {
315 :     while (my $Line = <INPUT>) {
316 :     chomp($Line);
317 :    
318 :     if (length($Delimiter) > 0) {
319 :     my @Data = split(/$Delimiter/,$Line);
320 :     $Line = $Data[0];
321 :     }
322 :    
323 :     push(@{$DataArrayRef},$Line);
324 :     }
325 :     close(INPUT);
326 :     } else {
327 :     $self->figmodel()->error_message("FIGMODELdatabase->load_single_column_file(".$Filename.",".$Delimiter."): could not load file!");
328 :     }
329 :     return $DataArrayRef;
330 :     }
331 :    
332 : chenry 1.2 =head3 load_table
333 :     Definition:
334 :     FIGMODELTable = FIGMODELdatabase->load_table(string::filename,string::delimiter,string::item delimiter,int::heading line,[string]::hash columns);
335 :     Description:
336 :     Uses the input arguments to load the specified table.
337 :     =cut
338 :     sub load_table {
339 :     my ($self,$Filename,$Delimiter,$ItemDelimiter,$HeadingLine,$HashColumns) = @_;
340 : chenry 1.7 if (!-e $Filename) {
341 :     return undef;
342 :     }
343 : chenry 1.8 return FIGMODELTable::load_table($Filename,$Delimiter,$ItemDelimiter,$HeadingLine,$HashColumns);
344 : chenry 1.2 }
345 :    
346 :     =head3 create_table
347 :     Definition:
348 :     FIGMODELTable = FIGMODELdatabase->create_table(string::table name);
349 :     Description:
350 :     Creating table based on name
351 :     =cut
352 :     sub create_table {
353 :     my ($self,$TableName) = @_;
354 :     my $NewTable;
355 :     if ($TableName eq "BIOMASS TABLE") {
356 :     if (!-e $self->config("Reaction database directory")->[0]."masterfiles/BiomassReactionTable.txt") {
357 :     $NewTable = FIGMODELTable->new(["DATABASE","REACTANTS","EQUATION","ORGANISMS","ESSENTIAL REACTIONS"],$self->config("Reaction database directory")->[0]."masterfiles/BiomassReactionTable.txt",["DATABASE","REACTANTS","ORGANISMS"],";","|",undef);
358 :     }
359 :     }
360 :     if (defined($NewTable)) {
361 :     $NewTable->save();
362 :     }
363 :     return $NewTable;
364 :     }
365 :    
366 :     =head3 add_model_to_db
367 :     Definition:
368 :     {string => [string]}::row for new model in model table = FIGMODELdatabase->add_model_to_db(string::id,{string=>[string]}::metadata);
369 :     Description:
370 :     This function adds the input model data to the model database file if the model name is unique
371 :     The second argument provides various metadata for the model including:
372 :     owner (name of the owner of the model: default is master)
373 :     users (list of users and user groups who have rights to model: default is all)
374 :     rights (list of rights corresponding with each user in the user list: default is view)
375 :     genome (ID of the genome the model is capturing: default is UNKNOWN)
376 :     source (can be RAST, SEED, or a pubmed ID indicating where the model came from: default is SEED)
377 :     comments (can be any comment provided for the model: default is undefined)
378 :     date (date model was published/generate: default is: default is date if upload)
379 :     overwrite (indicates if an existing model with the same name should be overwritten: default is 0)
380 :     Returns FIGMODEL->success for
381 :     =cut
382 :    
383 :     sub add_model_to_db {
384 : chenry 1.4 my ($self,$id,$metadata,$ConserveModelName) = @_;
385 : chenry 1.2
386 :     #Making sure an ID has been provided
387 :     if (!defined($id)) {
388 :     $self->figmodel()->error_message("FIGMODELdatabase:add_model_to_db:No model ID provided.");
389 :     return undef;
390 :     }
391 : chenry 1.10
392 :     #Setting the user if it's not already defined
393 : chenry 1.2 if (!defined($metadata->{"owner"}->[0])) {
394 :     $metadata->{"owner"}->[0] = "master";
395 :     }
396 : chenry 1.10
397 :     #Adding the user's ID to the model ID if the user is not "master"
398 :     if ($metadata->{"owner"}->[0] ne "master") {
399 :     my $userDB = $self->get_object_manager("user");
400 :     my $userList = $userDB->get_objects( {'login' => $metadata->{"owner"}->[0]} );
401 :     if (defined($userList) && defined($userList->[0])) {
402 :     $id = $id.".".$userList->[0]->_id();
403 :     } else {
404 :     $self->figmodel()->error_message("FIGMODEL:add_model_to_db:User ".$metadata->{"owner"}->[0]." not found in database. Check username.");
405 :     return undef;
406 : chenry 1.2 }
407 :     }
408 : chenry 1.10
409 :     #Getting the object manager for the models
410 : chenry 1.14 my $modelDB;
411 :     if (defined($metadata->{source}->[0]) && $metadata->{source}->[0] eq "MGRAST") {
412 :     $modelDB = $self->get_object_manager("mgmodel");
413 :     } else {
414 :     $modelDB = $self->get_object_manager("model");
415 :     }
416 : chenry 1.10
417 : chenry 1.2 #Checking if the model already exists
418 : chenry 1.10 my $model;
419 :     my $modelList = $modelDB->get_objects( {'id' => $id} );
420 :     if (defined($modelList) && defined($modelList->[0])) {
421 :     $model = $modelList->[0];
422 :     }
423 :     #If the model exists, we update the model with the input metadata
424 :     if (defined($model)) {
425 : chenry 1.2 if (!defined($metadata) || !defined($metadata->{"overwrite"}->[0]) || $metadata->{"overwrite"}->[0] == 0) {
426 :     $self->figmodel()->error_message("FIGMODEL:add_model_to_db:".$id." already exists and overwrite request was not provided.");
427 :     return undef;
428 :     } else {
429 :     #Copying over metadata
430 :     my @Keys = keys(%{$metadata});
431 :     foreach my $key (@Keys) {
432 : chenry 1.10 if ($key ne "id" && defined($modelList->[0]->$key)) {
433 :     $modelList->[0]->$key($metadata->{$key});
434 :     }
435 : chenry 1.2 }
436 : chenry 1.10 return $self->figmodel()->get_model();
437 : chenry 1.2 }
438 :     }
439 : chenry 1.5
440 : chenry 1.10 #Setting the defaults in the provided metadata
441 :     if (!defined($metadata->{"users"}->[0])) {
442 :     $metadata->{"users"}->[0] = $metadata->{"owner"}->[0];
443 :     }
444 :     if (!defined($metadata->{"rights"}->[0])) {
445 : chenry 1.16 $metadata->{"rights"}->[0] = "view";
446 : chenry 1.10 }
447 :     if (!defined($metadata->{"genome"}->[0])) {
448 :     $metadata->{"genome"}->[0] = "unknown";
449 :     }
450 :     if (!defined($metadata->{"source"}->[0])) {
451 :     $metadata->{"source"}->[0] = "unknown";
452 :     }
453 :     if (!defined($metadata->{"message"}->[0])) {
454 :     $metadata->{"message"}->[0] = "None";
455 :     }
456 :     if (!defined($metadata->{"class"}->[0])) {
457 :     $metadata->{"class"}->[0] = "unknown";
458 :     }
459 :     if (!defined($metadata->{"version"}->[0])) {
460 :     $metadata->{"version"}->[0] = 0;
461 :     }
462 :     if (!defined($metadata->{"status"}->[0])) {
463 :     $metadata->{"status"}->[0] = -2;
464 :     }
465 :     if (!defined($metadata->{"builtDate"}->[0])) {
466 :     $metadata->{"builtDate"}->[0] = 0;
467 :     }
468 : chenry 1.16 if (!defined($metadata->{"autoCompleteMedia"}->[0])) {
469 :     $metadata->{"autoCompleteMedia"}->[0] = "Complete";
470 :     my $tbl = $self->get_table("MINIMALMEDIA");
471 :     if (defined($tbl) && defined($tbl->get_row_by_key($metadata->{"genome"}->[0],"Organism"))) {
472 :     $metadata->{"autoCompleteMedia"}->[0] = $tbl->get_row_by_key($metadata->{"genome"}->[0],"Organism")->{"Minimal media"}->[0];
473 :     }
474 :     }
475 :     if (!defined($metadata->{"biomassReaction"}->[0])) {
476 :     $metadata->{"biomassReaction"}->[0] = "NONE";
477 :     }
478 : chenry 1.10
479 :     #Adding the model to the database
480 : chenry 1.20 $model = $modelDB->create({'id' => $id,
481 : chenry 1.10 'owner' => $metadata->{"owner"}->[0],
482 : chenry 1.13 'users' => "|".$metadata->{"users"}->[0]."|",
483 : chenry 1.10 'rights' => $metadata->{"rights"}->[0],
484 :     'genome' => $metadata->{"genome"}->[0],
485 :     'source' => $metadata->{"source"}->[0],
486 :     'modificationDate' => time(),
487 : chenry 1.16 'builtDate' => $metadata->{"builtDate"}->[0],
488 :     'autocompleteDate' => -1,
489 :     'status' => $metadata->{"status"}->[0],
490 :     'version' => $metadata->{"version"}->[0],
491 :     'autocompleteVersion' => 0,
492 : chenry 1.10 'message' => $metadata->{"message"}->[0],
493 : chenry 1.11 'cellwalltype' => $metadata->{"class"}->[0],
494 : chenry 1.16 'autoCompleteMedia' => $metadata->{"autoCompleteMedia"}->[0],
495 : chenry 1.20 'biomassReaction' => $metadata->{"biomassReaction"}->[0],
496 :     'growth' => 0,
497 :     'noGrowthCompounds' => "NONE"});
498 : chenry 1.10
499 :     if (defined($model)) {
500 :     return $self->figmodel()->get_model($model->id());
501 : chenry 1.4 }
502 : chenry 1.10 return undef;
503 : chenry 1.2 }
504 :    
505 : chenry 1.7 =head3 genericLock
506 :     Definition:
507 :     FIGMODELdatabase->genericLock(string::lock name);
508 :     Description:
509 :     This function locks the database for a given lock name.
510 :     =cut
511 :     sub genericLock {
512 :     my($self,$name) = @_;
513 :     #Making the directory if it does not already exist
514 : dejongh 1.21 my $ltdirs = $self->config("locked table list filename");
515 :     my $ltdir = $ltdirs->[0];
516 :     if (!-d $ltdir) {
517 :     system("mkdir ".$ltdir);
518 : chenry 1.7 }
519 :     #Creating the lock file
520 : dejongh 1.21 my $lock = $ltdir.$name.".lock";
521 :     while(-e $lock) {
522 : chenry 1.7 sleep(2);
523 :     }
524 : dejongh 1.21 $self->print_array_to_file($lock,["LOCKED"]);
525 : chenry 1.7 return $self->figmodel()->success();
526 :     }
527 :    
528 :     =head3 genericUnlock
529 :     Definition:
530 :     FIGMODELdatabase->genericUnlock(string::lock name);
531 :     Description:
532 :     This function unlocks the database for a given lock name.
533 :     =cut
534 :     sub genericUnlock {
535 :     my($self,$name) = @_;
536 :     #Deleting the lock file
537 : dejongh 1.21 my $ltdirs = $self->config("locked table list filename");
538 :     my $ltdir = $ltdirs->[0];
539 :     my $lock = $ltdir.$name.".lock";
540 :     unlink($lock);
541 : chenry 1.7 return $self->figmodel()->success();
542 :     }
543 :    
544 : chenry 1.2 =head3 LockDBTable
545 :     Definition:
546 :     FIGMODELTable = FIGMODELdatabase->LockDBTable(string::table name);
547 :     Description:
548 :     This function checks out a table from the database for editing. This table can then no longer be checked out for editing by any other programing running.
549 :     =cut
550 :     sub LockDBTable {
551 :     my($self,$TableName) = @_;
552 : chenry 1.7 #Locking to the tablename
553 :     $self->genericLock($TableName);
554 : chenry 1.2 #Clearing the cached table data
555 : chenry 1.6 $self->figmodel()->database()->ClearDBTable($TableName);
556 : chenry 1.2 #Loading and returning the tale data from file
557 : chenry 1.5 my $currentUser = $self->figmodel()->user();
558 :     $self->figmodel()->authenticate_user("master","MasterPassword");
559 :     my $tbl = $self->GetDBTable($TableName);
560 :     $self->figmodel()->authenticate_user($currentUser,"UserPassword");
561 :     return $tbl;
562 : chenry 1.2 }
563 :    
564 :     =head3 UnlockDBTable
565 :     Definition:
566 :     status(1/0) = FIGMODELdatabase->UnlockDBTable(string::table name);
567 :     Description:
568 :     This function checks a table into the database freeing the table for editing by other programs.
569 :     =cut
570 :     sub UnlockDBTable {
571 :     my($self,$TableName) = @_;
572 :     #Unlocking the file
573 : chenry 1.7 $self->genericUnlock($TableName);
574 : chenry 1.2 return $self->figmodel()->success();
575 :     }
576 :    
577 :     =head3 ManageFileLocking
578 :     Definition:
579 :     FIGMODELdatabase->ManageFileLocking($FileHandle,$Operation,$UseFcntl);
580 :     Description:
581 :     This function handles all file locking for the FIGMODELdatabase package. Possible values for $Operation are:
582 :     LOCK_EX: exclusive lock for writing
583 :     LOCK_SH: shared lock for simultaneous reading
584 :     LOCK_UN: removes the lock
585 :     Example:
586 :     =cut
587 :    
588 :     sub ManageFileLocking {
589 :     my($self,$FileHandle,$Operation,$UseFcntl) = @_;
590 :    
591 :     #Qualifying the filehandle
592 :     $FileHandle = FIGMODEL::qualify_to_ref($FileHandle, caller());
593 :    
594 :     #Implementing the lock using flock
595 :     if (!defined($UseFcntl) || $UseFcntl == 0) {
596 :     if ($Operation == LOCK_EX) {
597 :     my $arg = pack("ssll", F_WRLCK, SEEK_SET, 0, 0);
598 :     my $rc = fcntl($FileHandle, F_SETLKW, $arg);
599 :     return $rc;
600 :     } elsif ($Operation == LOCK_SH) {
601 :     my $arg = pack("ssll", F_RDLCK, SEEK_SET, 0, 0);
602 :     my $rc = fcntl($FileHandle, F_SETLKW, $arg);
603 :     return $rc;
604 :     } elsif ($Operation == LOCK_UN) {
605 :     my $arg = pack("ssll", F_UNLCK, SEEK_SET, 0, 0);
606 :     my $rc = fcntl($FileHandle, F_SETLKW, $arg);
607 :     return $rc;
608 :     }
609 :     } else {
610 :     return CORE::flock($FileHandle, $Operation);
611 :     }
612 :     }
613 :    
614 :     =head3 update_row
615 :     Definition:
616 :     status(1/0) = FIGMODELdatabase->update_row(string::table,{string=>[string]}::row,string::unique key);
617 :     Description:
618 :     Updates the input row in the specified table
619 :     =cut
620 :     sub update_row {
621 :     my ($self,$tablename,$row,$key) = @_;
622 :    
623 :     #Checking that a table and query have been provided
624 :     if (!defined($tablename) || !defined($row) || !defined($key) || !defined($row->{$key}->[0])) {
625 :     $self->figmodel()->error_message("FIGMODELdatabase:update_row:Must provide table, key, and value.");
626 :     return $self->figmodel()->fail();
627 :     }
628 :    
629 :     #Getting the database table:may be pulled from a flat file or from SQL
630 :     my $table = $self->LockDBTable($tablename);
631 :     if (!defined($table)) {
632 :     $self->figmodel()->error_message("FIGMODEL:update_row:".$tablename." not found in database.");
633 :     return $self->figmodel()->fail();
634 :     }
635 :    
636 :     #Querying to see if the row is already in the table
637 :     $row->{"last_modified"}->[0] = time();
638 :     my $ExistingRow = $table->get_row_by_key($row->{$key}->[0],$key);
639 :     if (defined($ExistingRow)) {
640 :     $table->replace_row($ExistingRow,$row);
641 :     } else {
642 :     $table->add_row($row);
643 :     }
644 :    
645 :     #Saving updated table to database
646 :     $table->save();
647 :     $self->UnlockDBTable($tablename);
648 :    
649 :     return $self->figmodel()->success();
650 :     }
651 :    
652 :     =head3 get_row_by_key
653 :     Definition:
654 :     {string=>[string]}::table row = FIGMODELdatabase->get_row_by_key(string::table,string::value,string::key);
655 :     Description:
656 :     =cut
657 :     sub get_row_by_key {
658 :     my ($self,$tablename,$value,$key) = @_;
659 :    
660 :     #Checking that a table and query have been provided
661 :     if (!defined($tablename) || !defined($value) || !defined($key)) {
662 :     $self->figmodel()->error_message("FIGMODELdatabase:get_row_by_key:Must provide table, key, and value.");
663 :     return undef;
664 :     }
665 :    
666 :     #Getting the database table:may be pulled from a flat file or from SQL
667 :     my $table = $self->GetDBTable($tablename);
668 :     if (!defined($table)) {
669 :     $self->figmodel()->error_message("FIGMODELdatabase:get_row_by_key:".$tablename." not found in database.");
670 :     return undef;
671 :     }
672 :    
673 :     #Getting first table row matching the query
674 :     return $table->get_row_by_key($value,$key);
675 :     }
676 :    
677 : chenry 1.5 =head3 get_object_from_db
678 :     Definition:
679 :     {string=>[string]}::table row = FIGMODELdatabase->get_object_from_db(string:type,{string:key=>value});
680 :     Description:
681 :     =cut
682 :     sub get_object_from_db {
683 :     my ($self,$type,$searchhash) = @_;
684 :    
685 :     #Checking that a table and query have been provided
686 :     if (!defined($type) || !defined($searchhash)) {
687 :     $self->figmodel()->error_message("FIGMODELdatabase:get_object_from_db:Must provide type and search terms.");
688 :     return undef;
689 :     }
690 :    
691 :     #Getting the database table:may be pulled from a flat file or from SQL
692 :     my $table = $self->GetDBTable($type);
693 :     if (!defined($table)) {
694 :     return undef;
695 :     }
696 :     my @searchkeys = keys(%{$searchhash});
697 :     for (my $i=0; $i < @searchkeys; $i++) {
698 :     $table = $table->get_table_by_key($searchhash->{$searchkeys[$i]},$searchkeys[$i]);
699 :     }
700 :     return $table->get_row(0);
701 :     }
702 :    
703 :     =head3 add_object_to_db
704 :     Definition:
705 :     {string:key=>value}:object = FIGMODELdatabase->add_object_to_db({string:key=>value}:object);
706 :     Description:
707 :     =cut
708 :     sub add_object_to_db {
709 :     my ($self,$object,$update) = @_;
710 :    
711 :     #Checking that a table and query have been provided
712 :     if (!defined($object)) {
713 :     $self->figmodel()->error_message("FIGMODELdatabase:add_object_to_db:Object must be provided.");
714 :     return undef;
715 :     }
716 :    
717 :     #Locking the table or making sure it's already locked
718 :     my $newlock = 0;
719 :     if (!defined($self->{"LOCKS"}->{$object->{_type}})) {
720 :     $newlock = 1;
721 :     $self->LockDBTable($object->{_type});
722 :     }
723 :     my $tbl = $self->GetDBTable($object->{_type});
724 :    
725 :     #Checking if another object with the same primary key already exists
726 :     my $existing_object = $self->get_object_from_db($object->{_type},{$object->{_key}=>$object->{$object->{_key}}->[0]});
727 :     if (defined($existing_object)) {
728 :     if (defined($update) && $update == 1) {
729 :     my @objkeys = keys(%{$object});
730 :     for (my $i=0; $i < @objkeys; $i++) {
731 :     if ($objkeys[$i] !~ m/^_/) {
732 :     $existing_object->{$objkeys[$i]} = $object->{$objkeys[$i]};
733 :     }
734 :     }
735 :     }
736 :     return $existing_object;
737 :     }
738 :    
739 :     #Adding the object
740 :     $tbl->add_row($object);
741 :    
742 :     #If the lock is new, unlocking the table
743 :     if ($newlock == 1) {
744 :     $tbl->save();
745 :     $self->UnlockDBTable($object->{_type});
746 :     }
747 :     return $object;
748 :     }
749 :    
750 :     =head3 add_columns_to_db
751 :     Definition:
752 :     FIGMODELdatabase->add_columns_to_db({string:new column name=>value:default value});
753 :     Description:
754 :     =cut
755 :     sub add_columns_to_db {
756 :     my ($self,$type,$columns) = @_;
757 :    
758 :     if (!defined($type) || !defined($columns)) {
759 :     $self->figmodel()->error_message("FIGMODELdatabase:add_columns_to_db:Columnn and object type must be provided.");
760 :     return $self->fail();
761 :     }
762 :     #Locking the table or making sure it's already locked
763 :     my $newlock = 0;
764 :     if (!defined($self->{"LOCKS"}->{$type})) {
765 :     $newlock = 1;
766 :     $self->LockDBTable($type);
767 :     }
768 :     my $tbl = $self->GetDBTable($type);
769 :     if (!defined($tbl)) {
770 :     $self->figmodel()->error_message("FIGMODELdatabase:add_columns_to_db:could not load object table of type:".$type);
771 :     return $self->fail();
772 :     }
773 :     my @columnNames = keys(%{$columns});
774 :     $tbl->add_headings(@columnNames);
775 :     for (my $j=0; $j < $tbl->size(); $j++) {
776 :     for (my $i=0; $i < @columnNames; $i++) {
777 :     if (!defined($tbl->get_row($j)->{$columnNames[$i]})) {
778 :     $tbl->get_row($j)->{$columnNames[$i]}->[0] = $columns->{$columnNames[$i]};
779 :     }
780 :     }
781 :     }
782 :    
783 :     #If the lock is new, unlocking the table
784 :     if ($newlock == 1) {
785 :     $tbl->save();
786 :     $self->UnlockDBTable($type);
787 :     }
788 :     return $self->success();
789 :     }
790 :    
791 :    
792 :    
793 : chenry 1.2 =head3 save_table
794 :     Definition:
795 :     FIGMODELdatabase->save_table(FIGMODELTable::table);
796 :     Description:
797 :     Saves the input table to file
798 :     =cut
799 :    
800 :     sub save_table {
801 :     my ($self,$table,$filename,$delimiter,$itemdelimiter,$prefix) = @_;
802 :    
803 :     $table->save($filename,$delimiter,$itemdelimiter,$prefix);
804 :     }
805 :    
806 :     =head3 GetDBTable
807 :     Definition:
808 : chenry 1.4 (1/0) = FIGMODELdatabase->GetDBTable([string]::authorized user list,string::user ID);
809 :     Description:
810 :     Checks to see if the input user is authorized to view an object based on the authorized user list
811 :     =cut
812 :     sub check_user {
813 :     my ($self,$users,$user) = @_;
814 :    
815 :     for (my $i=0; $i < @{$users}; $i++) {
816 :     if (lc($users->[$i]) eq "all" || $users->[$i] eq $user) {
817 :     return 1;
818 :     }
819 :     }
820 :    
821 :     return 0;
822 :     }
823 :    
824 : chenry 1.6 sub ClearDBTable {
825 :     my ($self,$TableName,$Delete) = @_;
826 :    
827 :     if (defined($Delete) && $Delete eq "DELETE") {
828 :     delete $self->{"CACHE"}->{$TableName};
829 :     }
830 :     $self->{"CACHE"}->{$TableName} = undef;
831 :     }
832 :    
833 :     sub ClearDBModel {
834 :     my ($self,$ModelName,$Delete) = @_;
835 :    
836 :     if (defined($Delete) && ($Delete eq "DELETE" || $Delete eq "1")) {
837 :     delete $self->{"CACHE"}->{"MODEL_".$ModelName};
838 :     }
839 :     $self->{"CACHE"}->{"MODEL_".$ModelName} = undef;
840 :     }
841 :    
842 : chenry 1.8 =head3 create_table_prototype
843 :    
844 :     Definition:
845 :     FIGMODELTable::table = FIGMODELdatabase->create_table_prototype(string::table);
846 :     Description:
847 :     Returns a empty FIGMODELTable with all the metadata associated with the input table name
848 :    
849 :     =cut
850 :     sub create_table_prototype {
851 :     my ($self,$TableName) = @_;
852 :    
853 :     #Checking if the table definition exists in the FIGMODELconfig file
854 :     if (!defined($self->figmodel()->config($TableName))) {
855 :     $self->figmodel()->error_message("FIGMODELdatabase:create_table_prototype:Definition not found for ".$TableName);
856 :     return undef;
857 :     }
858 :     #Checking that this is a database table
859 :     if (!defined($self->config($TableName)->{tabletype}) || $self->config($TableName)->{tabletype}->[0] ne "DatabaseTable") {
860 :     $self->figmodel()->error_message("FIGMODELdatabase:create_table_prototype:".$TableName." is not a database table!");
861 :     return undef;
862 :     }
863 :     if (!defined($self->config($TableName)->{delimiter})) {
864 :     $self->config($TableName)->{delimiter}->[0] = ";";
865 :     }
866 :     if (!defined($self->config($TableName)->{itemdelimiter})) {
867 :     $self->config($TableName)->{itemdelimiter}->[0] = "|";
868 :     }
869 :     my $prefix;
870 :     if (defined($self->config($TableName)->{prefix})) {
871 :     $prefix = join("\n",@{$self->config($TableName)->{prefix}});
872 :     }
873 :     my $tbl = FIGMODELTable->new($self->config($TableName)->{columns},$self->config("Reaction database directory")->[0].$self->config($TableName)->{filename}->[0],$self->config($TableName)->{hashcolumns},$self->config($TableName)->{delimiter}->[0],$self->config($TableName)->{itemdelimiter}->[0],$prefix);
874 :     return $tbl;
875 :     }
876 :    
877 :     =head3 get_table
878 :    
879 :     Definition:
880 :     FIGMODELTable::table = FIGMODELdatabase->get_table(string::table);
881 :     Description:
882 :     Returns the requested FIGMODELTable
883 :    
884 :     =cut
885 :     sub get_table {
886 : chenry 1.10 my ($self,$TableName,$NoCache) = @_;
887 : chenry 1.8
888 : chenry 1.10 if ((!defined($NoCache) || $NoCache == 0) && defined($self->{_cache}->{$TableName})) {
889 : chenry 1.8 return $self->{_cache}->{$TableName};
890 :     }
891 :     #Checking if the table definition exists in the FIGMODELconfig file
892 :     if (!defined($self->figmodel()->config($TableName))) {
893 :     $self->figmodel()->error_message("FIGMODELdatabase:create_table_prototype:Definition not found for ".$TableName);
894 :     return undef;
895 :     }
896 :     #Checking that this is a database table
897 :     if (!defined($self->config($TableName)->{tabletype}) || $self->config($TableName)->{tabletype}->[0] ne "DatabaseTable") {
898 :     $self->figmodel()->error_message("FIGMODELdatabase:create_table_prototype:".$TableName." is not a database table!");
899 :     return undef;
900 :     }
901 :     if (!defined($self->config($TableName)->{headingline})) {
902 :     $self->config($TableName)->{headingline}->[0] = 0;
903 :     }
904 : chenry 1.18 if (!defined($self->config($TableName)->{columndelimiter})) {
905 :     $self->config($TableName)->{columndelimiter}->[0] = "\t";
906 :     } elsif ($self->config($TableName)->{columndelimiter}->[0] eq "SC") {
907 :     $self->config($TableName)->{columndelimiter}->[0] = ";";
908 : chenry 1.8 }
909 : chenry 1.18 $self->config($TableName)->{delimiter}->[0] = $self->config($TableName)->{columndelimiter}->[0];
910 : chenry 1.8 if (!defined($self->config($TableName)->{itemdelimiter})) {
911 :     $self->config($TableName)->{itemdelimiter}->[0] = "|";
912 :     }
913 :     #Loading the table
914 :     $self->{_cache}->{$TableName} = FIGMODELTable::load_table($self->config("Reaction database directory")->[0].$self->config($TableName)->{filename}->[0],$self->config($TableName)->{delimiter}->[0],$self->config($TableName)->{itemdelimiter}->[0],$self->config($TableName)->{headingline}->[0],$self->config($TableName)->{hashcolumns});
915 :     return $self->{_cache}->{$TableName};
916 :     }
917 :    
918 : chenry 1.4 =head3 GetDBTable
919 :     Definition:
920 : chenry 1.2 FIGMODELTable::table = FIGMODELdatabase->GetDBTable(string::table,int::cache entire table);
921 :     Description:
922 :     Returns a FIGMODELTable object containing the data for the specified table.
923 :     The second argument is optional, but if this argument is equal to "1" and the specified table is in SQL, the table will not be loaded entirely from SQL.
924 :     =cut
925 :     sub GetDBTable {
926 :     my ($self,$TableName) = @_;
927 :    
928 :     #Checking if the table is already loaded
929 :     if (defined($self->{"CACHE"}->{$TableName})) {
930 :     return $self->{"CACHE"}->{$TableName};
931 :     }
932 :    
933 :     #Loading the table list if it is not already loaded
934 :     if ($TableName ne "TABLE LIST" && !defined($self->{"CACHE"}->{"TABLE LIST"})) {
935 :     my $Table = $self->GetDBTable("TABLE LIST");
936 :     }
937 :    
938 :     #Declaring all variables used in this function
939 :     my ($Filename,$Delimiter,$ItemDelimiter,$HeadingLine,$HashColumns);
940 :     #Check that table list has been loaded
941 :     if ($TableName eq "TABLE LIST") {
942 : dejongh 1.21 my $names = $self->config("table list filename");
943 :     $Filename = $names->[0];
944 : chenry 1.2 $Delimiter = "\t";
945 :     $ItemDelimiter = "`";
946 :     $HeadingLine = 0;
947 :     $HashColumns->[0] = "NAME";
948 :     } elsif (!defined($self->{"CACHE"}->{"TABLE LIST"}->{$TableName})) {
949 :     return undef;
950 :     } else {
951 :     $Filename = $self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"FILENAME"}->[0];
952 :     #Translating variable filenames
953 :     $_ = $Filename;
954 :     my @MatchArray = /\{([^\}]+)\}/g;
955 :     foreach my $Tag (@MatchArray) {
956 :     if (defined($self->GetProtectVariable($Tag))) {
957 :     my $Replace = $self->GetProtectVariable($Tag);
958 :     $Tag = "\{".$Tag."\}";
959 :     $Filename =~ s/$Tag/$Replace/;
960 : dejongh 1.21 } elsif (defined($self->config($Tag))) {
961 :     my $names = $self->config($Tag);
962 :     my $Replace = $names->[0];
963 : chenry 1.2 $Tag = "\{".$Tag."\}";
964 :     $Filename =~ s/$Tag/$Replace/;
965 :     }
966 :     }
967 :     $Delimiter = $self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"DELIMITER"}->[0];
968 :     $ItemDelimiter = "";
969 :     if (defined($self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"ITEM DELIMITER"})) {
970 :     $ItemDelimiter = $self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"ITEM DELIMITER"}->[0];
971 :     }
972 :     $HeadingLine = 0;
973 :     if (defined($self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"HEADING LINE"})) {
974 :     $HeadingLine = $self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"HEADING LINE"}->[0];
975 :     }
976 :     $HashColumns = $self->{"CACHE"}->{"TABLE LIST"}->{$TableName}->[0]->{"HASH COLUMNS"};
977 :     }
978 :    
979 :     $self->{"CACHE"}->{$TableName} = FIGMODELTable::load_table($Filename,$Delimiter,$ItemDelimiter,$HeadingLine,$HashColumns);
980 :     if (!defined($self->{"CACHE"}->{$TableName})) {
981 :     $self->{"CACHE"}->{$TableName} = $self->create_table($TableName);
982 :     }
983 :    
984 : chenry 1.4 #Removing private reactions
985 :     if (lc($self->figmodel()->user()) ne "master") {
986 :     if ($TableName eq "MODELS") {
987 :     my $tbl = $self->{"CACHE"}->{$TableName};
988 :     for (my $i=0; $i < $tbl->size(); $i++) {
989 :     if ($self->check_user($tbl->get_row($i)->{users},$self->figmodel()->user()) == 0) {
990 :     my $id = $tbl->get_row($i)->{id}->[0];
991 :     $tbl->delete_row($i);
992 :     $i--;
993 :     }
994 :     }
995 :     } elsif ($TableName eq "REACTIONS" || $TableName eq "COMPOUNDS") {
996 :     my $tbl = $self->{"CACHE"}->{$TableName};
997 :     my $type = "REACTION";
998 :     if ($TableName eq "COMPOUNDS") {
999 :     $type = "COMPOUND";
1000 :     }
1001 :     my $linktbl = $self->GetLinkTable($type,"SOURCE");
1002 :     my $ModelTable = $self->GetDBTable("MODELS");
1003 :     for (my $i=0; $i < $tbl->size(); $i++) {
1004 :     my $id = $tbl->get_row($i)->{"DATABASE"}->[0];
1005 :     my $row = $linktbl->get_row_by_key($id,$type);
1006 :     if (defined($row)) {
1007 :     my $authorized = 0;
1008 :     for (my $j=0; $j < @{$row->{"SOURCE"}};$j++) {
1009 :     if ($row->{"SOURCE"}->[$j] eq "KEGG" || defined($ModelTable->get_row_by_key($row->{"SOURCE"}->[$j],"id"))) {
1010 :     $authorized = 1;
1011 :     last;
1012 :     }
1013 :     }
1014 :     if ($authorized == 0) {
1015 :     $tbl->delete_row($i);
1016 :     $i--;
1017 :     }
1018 :     }
1019 :     }
1020 :     }
1021 :     }
1022 :    
1023 : chenry 1.2 return $self->{"CACHE"}->{$TableName};
1024 :     }
1025 :    
1026 :     =head3 GetProtectVariable
1027 :     Definition:
1028 :     string::variable value = FIGMODELdatabase->GetProtectVariable(string::variable name,0/1::delete variable);
1029 :     Description:
1030 :     getting the value of the specified protected variable
1031 :     =cut
1032 :     sub GetProtectVariable {
1033 :     my ($self,$VariableName,$DeleteVariable) = @_;
1034 :     if (defined($self->{"PROTECTED VARIABLES"}->{$VariableName}->[0])) {
1035 :     my $Variable = $self->{"PROTECTED VARIABLES"}->{$VariableName}->[0];
1036 :     if (defined($DeleteVariable) && $DeleteVariable == 1) {
1037 :     delete $self->{"PROTECTED VARIABLES"}->{$VariableName};
1038 :     }
1039 :     return $Variable;
1040 :     }
1041 :     return undef;
1042 :     }
1043 :    
1044 :     =head3 SetProtectedVariable
1045 :     Definition:
1046 :     FIGMODELdatabase->SetProtectedVariable(string::variable name,string::variable value);
1047 :     Description:
1048 :     setting the value of the specified protected variable
1049 :     =cut
1050 :     sub SetProtectedVariable {
1051 :     my ($self,$VariableName,$VariableValue) = @_;
1052 :     $self->{"PROTECTED VARIABLES"}->{$VariableName}->[0] = $VariableValue;
1053 :     }
1054 :    
1055 :     =head3 GetDBModel
1056 :     Definition:
1057 :     FIGMODELTable = FIGMODELdatabase->GetDBModel(string::model id);
1058 :     Description:
1059 :     setting the value of the specified protected variable
1060 :     =cut
1061 :     sub GetDBModel {
1062 :     my ($self,$ModelName) = @_;
1063 :    
1064 :     if (defined($self->{"CACHE"}->{"MODEL_".$ModelName})) {
1065 :     return $self->{"CACHE"}->{"MODEL_".$ModelName};
1066 :     }
1067 :    
1068 :     my $model = $self->figmodel()->get_model($ModelName);
1069 :     if (!defined($model)) {
1070 :     $self->figmodel()->error_message("FIGMODELdatabase:GetDBModel: Could not find model ".$ModelName);
1071 :     return undef;
1072 :     }
1073 :     $self->SetProtectedVariable("MODEL DIRECTORY",$model->filename());
1074 :     my $ModelTable = $self->GetDBTable("MODEL BUFFER TABLE");
1075 :     if (defined($ModelTable)) {
1076 :     $self->{"CACHE"}->{"MODEL_".$ModelName} = $ModelTable;
1077 :     }
1078 :     $self->{"CACHE"}->{"MODEL BUFFER TABLE"} = undef;
1079 :     $self->GetProtectVariable("MODEL DIRECTORY",1);
1080 :    
1081 :     return $ModelTable;
1082 :     }
1083 :    
1084 :     =head3 GetDBModelGenes
1085 :     Definition:
1086 :     FIGMODELTable = FIGMODELdatabase->GetDBModelGenes(string::model id);
1087 :     Description:
1088 :     returns a FIGMODELTable with the model genes
1089 :     =cut
1090 :     sub GetDBModelGenes {
1091 : chenry 1.7 my ($self,$modelID) = @_;
1092 : chenry 1.2
1093 :     #Getting model data
1094 : chenry 1.7 my $model = $self->figmodel()->get_model($modelID);
1095 :     if (!defined($model)) {
1096 :     print STDERR "FIGMODELdatabase:GetDBModelGenes:Could not find model ".$modelID." in database!";
1097 : chenry 1.2 return undef;
1098 :     }
1099 : chenry 1.7 return $model->feature_table();
1100 : chenry 1.2 }
1101 :    
1102 :     =head3 save_cpd_translation
1103 :     Definition:
1104 :     FIGMODELdatabase->save_cpd_translation({string::model ID => string::cpd id},string::model id);
1105 :     Description:
1106 :     saving the compound translation file for a model
1107 :     =cut
1108 :     sub save_cpd_translation {
1109 :     my ($self,$tanslation,$model) = @_;
1110 :    
1111 :     my $filename = $self->figmodel()->config("Translation directory")->[0]."CpdTo".$model.".txt";
1112 :     my $filedata;
1113 :     my @cpds = keys(%{$tanslation});
1114 :     for (my $i=0; $i < @cpds; $i++) {
1115 :     push(@{$filedata},$tanslation->{$cpds[$i]}."\t".$cpds[$i]);
1116 :     }
1117 :     $self->print_array_to_file($filename,$filedata);
1118 :     }
1119 :    
1120 :     =head3 save_rxn_translation
1121 :     Definition:
1122 :     FIGMODELdatabase->save_rxn_translation({string::model ID => string::cpd id},string::model id);
1123 :     Description:
1124 :     saving the reaction translation file for a model
1125 :     =cut
1126 :     sub save_rxn_translation {
1127 :     my ($self,$tanslation,$model) = @_;
1128 :    
1129 :     my $filename = $self->figmodel()->config("Translation directory")->[0]."RxnTo".$model.".txt";
1130 :     my $filedata;
1131 :     my @rxns = keys(%{$tanslation});
1132 :     for (my $i=0; $i < @rxns; $i++) {
1133 :     push(@{$filedata},$tanslation->{$rxns[$i]}."\t".$rxns[$i]);
1134 :     }
1135 :     $self->print_array_to_file($filename,$filedata);
1136 :     }
1137 :    
1138 :     =head3 print_array_to_file
1139 :     Definition:
1140 :     FIGMODELdatabase->print_array_to_file(string::filename,[string::file lines],0/1::append);
1141 :     Description:
1142 :     saving array to file
1143 :     =cut
1144 :     sub print_array_to_file {
1145 :     my ($self,$filename,$arrayRef,$Append) = @_;
1146 :    
1147 :     if (defined($Append) && $Append == 1) {
1148 :     open (OUTPUT, ">>$filename");
1149 :     } else {
1150 :     open (OUTPUT, ">$filename");
1151 :     }
1152 :     foreach my $Item (@{$arrayRef}) {
1153 :     if (length($Item) > 0) {
1154 :     print OUTPUT $Item."\n";
1155 :     }
1156 :     }
1157 :     close(OUTPUT);
1158 :     }
1159 :    
1160 : chenry 1.3 =head3 print_multicolumn_array_to_file
1161 :     Definition:
1162 :     FIGMODELdatabase->print_multicolumn_array_to_file(string::filename,[string::file lines],string::delimiter);
1163 :     Description:
1164 :     saving array to file
1165 :     =cut
1166 :     sub print_multicolumn_array_to_file {
1167 :     my ($self,$Filename,$ArrayRef,$Delimiter) = @_;
1168 :    
1169 :     if (open (OUTPUT, ">$Filename")) {
1170 :     foreach my $Item (@{$ArrayRef}) {
1171 :     if (@{$Item} > 0) {
1172 :     print OUTPUT join($Delimiter,@{$Item})."\n";
1173 :     }
1174 :     }
1175 :     close(OUTPUT);
1176 :     } else {
1177 :     die "Cannot open $Filename: $!";
1178 :     }
1179 :     }
1180 :    
1181 : chenry 1.2 =head3 build_link_file
1182 :     Definition:
1183 :     (0/1)::status = FIGMODELdatabase->build_link_file(string::entity one,string::entity two);
1184 :     Description:
1185 :     This function prints a flatfile that makes it possible to rapidly translate one entity into another.
1186 :     The first entity is always the reference entity in the table, with one row in the table for each unique ID.
1187 :     Currently generates linking files for the following entity pairs:
1188 :     reaction->subsystem
1189 :     =cut
1190 :    
1191 :     sub build_link_file {
1192 :     my($self,$EntityOne,$EntityTwo) = @_;
1193 :    
1194 : chenry 1.12 my $Table = FIGMODELTable->new([$EntityOne,$EntityTwo,"DATA"],$self->config("Reaction database directory")->[0]."linkfiles/".$EntityOne."-".$EntityTwo.".tbl",[$EntityOne,$EntityTwo],"\t","|",undef);
1195 : chenry 1.2 if ($EntityOne eq "REACTION") {
1196 :     if ($EntityTwo eq "SUBSYSTEM") {
1197 :     my $ReactionTable = $self->GetDBTable("REACTIONS");
1198 :     for (my $i=0; $i < $ReactionTable->size(); $i++) {
1199 :     my $Row = $ReactionTable->get_row($i);
1200 :     my $Subsystems = $self->figmodel()->subsystems_of_reaction($Row->{"DATABASE"}->[0]);
1201 :     if (defined($Subsystems)) {
1202 :     $Table->add_row({"REACTION" => [$Row->{"DATABASE"}->[0]],"SUBSYSTEM" => $Subsystems});
1203 :     }
1204 :     }
1205 :     $Table->save();
1206 :     return $self->success();
1207 : chenry 1.3 } elsif ($EntityTwo eq "COMPOUND") {
1208 :     my $ReactionTable = $self->GetDBTable("REACTIONS");
1209 :     for (my $i=0; $i < $ReactionTable->size(); $i++) {
1210 :     my $Row = $ReactionTable->get_row($i);
1211 :     my ($Reactants,$Products) = $self->figmodel()->GetReactionSubstrateDataFromEquation($Row->{EQUATION}->[0]);
1212 :     for (my $i=0; $i < @{$Reactants}; $i++) {
1213 :     $Table->add_row({"REACTION" => [$Row->{"DATABASE"}->[0]],"COMPOUND" => $Reactants->{DATABASE}->[0]});
1214 :     }
1215 :     for (my $i=0; $i < @{$Products}; $i++) {
1216 :     $Table->add_row({"REACTION" => [$Row->{"DATABASE"}->[0]],"COMPOUND" => $Products->{DATABASE}->[0]});
1217 :     }
1218 :     }
1219 :     $Table->save();
1220 :     return $self->success();
1221 : chenry 1.10 } elsif ($EntityTwo eq "MODEL") {
1222 :     for (my $i=0; $i < $self->figmodel()->number_of_models(); $i++) {
1223 :     my $model = $self->figmodel()->get_model($i);
1224 :     my $rxnTbl = $model->reaction_table();
1225 :     for (my $j=0; $j < $rxnTbl->size(); $j++) {
1226 :     my $row = $rxnTbl->get_row($j);
1227 :     my $newRow = $Table->get_row_by_key($row->{LOAD}->[0],"REACTION");
1228 :     if (!defined($newRow)) {
1229 :     $Table->add_row({"REACTION"=>[$row->{LOAD}->[0]],"MODEL"=>[$model->id()]});
1230 :     } else {
1231 :     $Table->add_data($newRow,"MODEL",$model->id(),1);
1232 :     }
1233 :     }
1234 :     }
1235 :     $Table->save();
1236 :     return $self->success();
1237 : chenry 1.4 } elsif ($EntityTwo eq "SOURCE") {
1238 :     #Getting the complete list of translation files
1239 :     my @TranslationFiles = glob($self->config("Translation directory")->[0]."RxnTo*");
1240 :     for (my $i=0; $i < @TranslationFiles; $i++) {
1241 :     if ($TranslationFiles[$i] =~ m/RxnTo(.+)\.txt/) {
1242 :     my $ModelName = $1;
1243 :     if ($ModelName ne "All") {
1244 :     my $transdata = $self->load_multiple_column_file($TranslationFiles[$i],"\t");
1245 :     for (my $j=0; $j < @{$transdata}; $j++) {
1246 :     my $row = $Table->get_row_by_key($transdata->[$j]->[0],"REACTION",1);
1247 :     $Table->add_data($row,"SOURCE",$ModelName,1);
1248 :     }
1249 :     }
1250 :     }
1251 :     }
1252 :     $Table->save();
1253 :     return $self->success();
1254 :     }
1255 : chenry 1.12 } elsif ($EntityOne eq "MODEL") {
1256 :     if ($EntityTwo eq "BOF") {
1257 :     my $modelManager = $self->get_object_manager("model");
1258 :     my $models = $modelManager->get_objects();
1259 :     for (my $i=0; $i < @{$models}; $i++) {
1260 :     my $mdl = $self->figmodel()->get_model($models->[$i]->id());
1261 :     if (defined($mdl)) {
1262 :     my $biorxn = $mdl->get_biomass();
1263 :     if (defined($biorxn)) {
1264 :     $Table->add_row({MODEL => [$mdl->id()],BOF => [$biorxn->{LOAD}->[0]]});
1265 :     }
1266 :     }
1267 :     }
1268 :     $Table->save();
1269 :     return $self->success();
1270 :     }
1271 : chenry 1.4 } elsif ($EntityOne eq "COMPOUND") {
1272 : chenry 1.12 if ($EntityTwo eq "BOF") {
1273 :     my $tbl = $self->figmodel()->database()->get_table("BIOMASS");
1274 :     for (my $i=0; $i < $tbl->size(); $i++) {
1275 :     my $row = $tbl->get_row($i);
1276 :     my @array = split(/\s/,$row->{EQUATION}->[0]);
1277 :     my $sign = -1;
1278 :     for (my $j=0; $j < @array;$j++) {
1279 :     if ($array[$j] =~ m/cpd\d\d\d\d\d/) {
1280 :     my $coef = $sign;
1281 :     if ($j > 0 && $array[$j-1] =~ m/\((.+)\)/) {
1282 :     $coef = $sign*$1;
1283 :     }
1284 :     $Table->add_row({COMPOUND => [$array[$j]],BOF => [$row->{DATABASE}->[0]], DATA => [$coef]});
1285 :     } elsif ($array[$j] =~ m/=/) {
1286 :     $sign = 1;
1287 :     }
1288 :     }
1289 :     }
1290 :     $Table->save();
1291 :     return $self->success();
1292 :     } elsif ($EntityTwo eq "SOURCE") {
1293 : chenry 1.4 #Getting the complete list of translation files
1294 :     my @TranslationFiles = glob($self->config("Translation directory")->[0]."CpdTo*");
1295 :     for (my $i=0; $i < @TranslationFiles; $i++) {
1296 :     if ($TranslationFiles[$i] =~ m/CpdTo(.+)\.txt/) {
1297 :     my $ModelName = $1;
1298 :     if ($ModelName ne "All") {
1299 :     my $transdata = $self->load_multiple_column_file($TranslationFiles[$i],"\t");
1300 :     for (my $j=0; $j < @{$transdata}; $j++) {
1301 :     my $row = $Table->get_row_by_key($transdata->[$j]->[0],"COMPOUND",1);
1302 :     $Table->add_data($row,"SOURCE",$ModelName,1);
1303 :     }
1304 :     }
1305 :     }
1306 :     }
1307 :     $Table->save();
1308 :     return $self->success();
1309 : chenry 1.2 }
1310 :     } elsif ($EntityOne eq "SUBSYSTEM") {
1311 :     if ($EntityTwo eq "CLASS") {
1312 :     if (!defined($self->fig())) {
1313 :     return $self->fail();
1314 :     }
1315 :     my @SubsystemList = $self->fig()->all_subsystems();
1316 :     for (my $i=0; $i < @SubsystemList; $i++) {
1317 :     my $class = $self->fig()->subsystem_classification($SubsystemList[$i]);
1318 :     if (defined($class)) {
1319 :     my $row = $Table->get_row_by_key($SubsystemList[$i],"SUBSYSTEM",1);
1320 :     push(@{$row->{CLASS}},@{$class});
1321 :     }
1322 :     }
1323 :     $Table->save();
1324 :     return $self->success();
1325 :     }
1326 :     }
1327 :     return $self->fail();
1328 :     }
1329 :    
1330 : chenry 1.5 =head3 get_link_table
1331 :     Definition:
1332 :     FIGMODELTable::Entity link table = FIGMODELdatabase->get_link_table([string]:entity list);
1333 :     Description:
1334 :     This function returns a FIGMODELTable with two columns corresponding to the two input entity types.
1335 :     This table can be used to translate from one entity type into another.
1336 :     =cut
1337 :     sub get_link_table {
1338 :     my($self,$entityList) = @_;
1339 :    
1340 :     my $id = join("_",@{$entityList});
1341 :     if (!defined($self->{_links}->{$id})) {
1342 :     my $tbl;
1343 :     if (!-e $self->figmodel()->directory()."ReactionDB/linkfiles/".$id.".tbl") {
1344 :     $tbl = $self->$id($entityList);
1345 :     } else {
1346 :     $self->{_links}->{$id} = $self->load_table($self->figmodel()->directory()."ReactionDB/linkfiles/".$id.".tbl","\t","|",0,$entityList);
1347 :     }
1348 :     }
1349 :    
1350 :     return $self->{_links}->{$id};
1351 :     }
1352 :    
1353 :     =head3 update_link_table
1354 :     Definition:
1355 :     FIGMODELTable::Entity link table = FIGMODELdatabase->update_link_table([string]:entity list);
1356 :     Description:
1357 :    
1358 :     =cut
1359 :     sub update_link_table {
1360 :     my($self,$entityList) = @_;
1361 :    
1362 :     my $id = join("_",@{$entityList});
1363 :     $self->{_links}->{$id} = $self->$id($entityList);
1364 :     }
1365 :    
1366 :     =head3 link_generation_functions
1367 :     Description:
1368 :     The following are custom functions written for each type of link in the database
1369 :     =cut
1370 :     sub interval_model_media {
1371 :     my($self,$entityList) = @_;
1372 :     my $id = join("_",@{$entityList});
1373 :     my $headings;
1374 :     push(@{$headings},@{$entityList});
1375 :     push(@{$headings},("in silico","experiment","status"));
1376 :     my $tbl;
1377 :     if (!-e $self->figmodel()->directory()."ReactionDB/linkfiles/".$id.".tbl") {
1378 :     $tbl = FIGMODELTable->new($headings,$self->figmodel()->directory()."ReactionDB/linkfiles/".$id.".tbl",$entityList,"\t","|",undef);
1379 :     } else {
1380 :     $tbl = $self->load_table($self->figmodel()->directory()."ReactionDB/linkfiles/".$id.".tbl","\t","|",0,$entityList);
1381 :     }
1382 :    
1383 :     my $input = $self->GetDBTable("STRAIN SIMULATIONS");
1384 :     for (my $i=0; $i < $input->size(); $i++) {
1385 :     my $row = $input->get_row($i);
1386 :     if ($row->{ID}->[0] =~ m/^\d+$/) {
1387 :     for (my $j=0; $j < @{$row->{MEDIA}};$j++) {
1388 :     my $newrow = $tbl->get_table_by_key($row->{ID}->[0],"interval")->get_table_by_key($row->{MEDIA}->[$j],"media")->get_row_by_key($row->{MODEL}->[0],"model");
1389 :     if (!defined($newrow)) {
1390 :     $newrow = $tbl->add_row({"interval" => [$row->{ID}->[0]], "model" => [$row->{MODEL}->[0]], "media" => [$row->{MEDIA}->[$j]]});
1391 :     }
1392 :     $newrow->{"in silico"}->[0] = $row->{GROWTH}->[$j];
1393 :     }
1394 :     }
1395 :     }
1396 :    
1397 :     $input = $self->GetDBTable("INTERVAL TABLE");
1398 :     for (my $i=0; $i < $input->size(); $i++) {
1399 :     my $row = $input->get_row($i);
1400 :     for (my $j=0; $j < @{$row->{GROWTH}};$j++) {
1401 :     my @temp = split(/:/,$row->{GROWTH}->[$j]);
1402 :     if (@temp >= 2) {
1403 :     my $subtbl = $tbl->get_table_by_key($row->{ID}->[0],"interval")->get_table_by_key($temp[0],"media");
1404 :     for (my $k=0;$k < $subtbl->size(); $k++) {
1405 :     my $subrow = $subtbl->get_row($k);
1406 :     $subrow->{"experiment"}->[0] = $temp[1];
1407 :     if ($subrow->{"in silico"}->[0] > 0.000001) {
1408 :     if ($subrow->{"experiment"}->[0] > 0.000001) {
1409 :     $subrow->{"status"}->[0] = "CP";
1410 :     } else {
1411 :     $subrow->{"status"}->[0] = "FP";
1412 :     }
1413 :     } elsif ($subrow->{"experiment"}->[0] > 0.000001) {
1414 :     $subrow->{"status"}->[0] = "FN";
1415 :     } else {
1416 :     $subrow->{"status"}->[0] = "CN";
1417 :     }
1418 :     }
1419 :     }
1420 :     }
1421 :     }
1422 :    
1423 :     $self->save_table($tbl);
1424 :     return $tbl;
1425 :     }
1426 :    
1427 : chenry 1.2 =head3 GetLinkTable
1428 :     Definition:
1429 :     FIGMODELTable::Entity link table = FIGMODELdatabase->GetLinkTable(string::entity one,string::entity two);
1430 :     Description:
1431 :     This function returns a FIGMODELTable with two columns corresponding to the two input entity types.
1432 :     This table can be used to translate from one entity type into another.
1433 :     =cut
1434 :     sub GetLinkTable {
1435 :     my($self,$EntityOne,$EntityTwo) = @_;
1436 :    
1437 :     #Loading the table from file if it has not already been cached
1438 :     if (!defined($self->get_cache("LINK-".$EntityOne."-".$EntityTwo))) {
1439 :     if (-e $self->config("Reaction database directory")->[0]."linkfiles/".$EntityOne."-".$EntityTwo.".tbl") {
1440 :     $self->set_cache("LINK-".$EntityOne."-".$EntityTwo,$self->load_table($self->config("Reaction database directory")->[0]."linkfiles/".$EntityOne."-".$EntityTwo.".tbl","\t","|",0,[$EntityOne,$EntityTwo]));
1441 :     }
1442 :     }
1443 :    
1444 :     return $self->get_cache("LINK-".$EntityOne."-".$EntityTwo);
1445 :     }
1446 :    
1447 :     =head3 mg_model_data
1448 :     Definition:
1449 :     MGRAST::Metadata::meta data for model = FIGMODELdatabase->mg_model_data(string::metagenome id);
1450 :     Description:
1451 :     Returns the metadata object for the specified genome id
1452 :     =cut
1453 :     sub mg_model_data {
1454 :     my($self,$genome_id) = @_;
1455 :    
1456 :     if (!defined($self->{_mg_model_data})) {
1457 :     require MGRAST::Metadata;
1458 :     my $mddb = MGRAST::Metadata->new();
1459 :     my $results = $mddb->_handle()->Search->get_objects({});
1460 :     foreach (@$results){
1461 :     $self->{_mg_model_data}->{$_->job()->genome_id} = $_;
1462 :     }
1463 :     }
1464 :    
1465 :     return $self->{_mg_model_data}->{$genome_id};
1466 :     }
1467 :    
1468 :     =head3 get_genome_feature_table
1469 :     Definition:
1470 :     FIGMODELTable = FIGMODELdatabase->get_genome_feature_table(string::genome id,0/1::get sequences);
1471 :     Description:
1472 :     This functions gets the genome data for the input genome ID from the SEED using the all_features_detailed_fast function.
1473 :     The data is then formatted into a FIGMODELTable object and returned.
1474 :     =cut
1475 :     sub get_genome_feature_table {
1476 :     my($self,$OrganismID,$GetSequences) = @_;
1477 :    
1478 :     #Returning the cached table if it exists
1479 :     if (defined($self->get_cache($OrganismID."-FEATURETABLE"))) {
1480 :     return $self->get_cache($OrganismID."-FEATURETABLE");
1481 :     }
1482 :    
1483 :     #Creating a new table
1484 : dejongh 1.21 my $names = $self->config("database message file directory");
1485 :     my $featuretbl = new FIGMODELTable(["ID","ALIASES","TYPE","LOCATION","MIN LOCATION","MAX LOCATION","ROLES","SEQUENCE"],$names->[0]."Features-".$OrganismID.".txt",["ID","ALIASES","TYPE","ROLES"],"\t","|",undef);
1486 : chenry 1.2
1487 :     #Getting the data for the genome from the SEED
1488 :     my $source = "SEED";
1489 :     my $owner = "master";
1490 :     my $name = "Unknown";
1491 :     my $taxonomy = "Unknown";
1492 :     my $size = "NA";
1493 :     if ($OrganismID =~ m/^444\d\d\d\d\.\d+$/) {
1494 :     $source = "MGRAST";
1495 :     } else {
1496 :     #Getting fig object for genome
1497 :     my $fig = $self->figmodel()->fig($OrganismID);
1498 :     $source = $fig->{_source};
1499 :     $owner = $fig->{_owner};
1500 :     #If a fig object exists, it is used to get the genome data
1501 :     if (defined($fig)) {
1502 :     if ($fig->{_source} =~ m/^RAST/) {
1503 :     $name = $fig->{_name};
1504 :     $taxonomy = $fig->{_taxonomy};
1505 :     $size = $fig->{_size};
1506 :     } else {
1507 :     $name = $fig->orgname_of_orgid($OrganismID);
1508 :     $taxonomy = $fig->taxonomy_of($OrganismID);
1509 :     $taxonomy =~ s/;\s/;/g;
1510 :     $taxonomy =~ s/;/|/g;
1511 :     $size = $fig->genome_szdna($OrganismID);
1512 :     }
1513 :     my $GenomeData = $fig->all_features_detailed_fast($OrganismID);
1514 :     #Sorting GenomeData by gene location on the chromosome
1515 :     my @Sorted = sort { $a->[4] <=> $b->[4] } @$GenomeData;
1516 :     $GenomeData = ();
1517 :     push(@{$GenomeData},@Sorted);
1518 :     #Inserting the data from the two dimensional array into the table object
1519 :     foreach my $Row (@{$GenomeData}) {
1520 :     my $RoleArray;
1521 :     if (defined($Row->[6])) {
1522 :     push(@{$RoleArray},$self->figmodel()->roles_of_function($Row->[6]));
1523 :     } else {
1524 :     $RoleArray = ["NONE"];
1525 :     }
1526 :     my $AliaseArray;
1527 :     push(@{$AliaseArray},split(/,/,$Row->[2]));
1528 :     if (defined($GetSequences) && $GetSequences == 1) {
1529 :     my $Sequence = $fig->get_translation($Row->[0]);
1530 :     if (defined($Sequence) && length($Sequence) > 0) {
1531 :     $featuretbl->add_row({"ID" => [$Row->[0]],"ALIASES" => $AliaseArray,"TYPE" => [$Row->[3]],"LOCATION" => [$Row->[1]],"MIN LOCATION" => [$Row->[4]],"MAX LOCATION" => [$Row->[5]],"ROLES" => $RoleArray,"SEQUENCE" => [$Sequence]});
1532 :     } else {
1533 :     $featuretbl->add_row({"ID" => [$Row->[0]],"ALIASES" => $AliaseArray,"TYPE" => [$Row->[3]],"LOCATION" => [$Row->[1]],"MIN LOCATION" => [$Row->[4]],"MAX LOCATION" => [$Row->[5]],"ROLES" => $RoleArray});
1534 :     }
1535 :     } else {
1536 :     $featuretbl->add_row({"ID" => [$Row->[0]],"ALIASES" => $AliaseArray,"TYPE" => [$Row->[3]],"LOCATION" => [$Row->[1]],"MIN LOCATION" => [$Row->[4]],"MAX LOCATION" => [$Row->[5]],"ROLES" => $RoleArray});
1537 :     }
1538 :     }
1539 :     }
1540 :     }
1541 :    
1542 :     $featuretbl->set_metadata("NAME",$name);
1543 :     $featuretbl->set_metadata("TAXONOMY",$taxonomy);
1544 :     $featuretbl->set_metadata("SOURCE",$source);
1545 :     $featuretbl->set_metadata("OWNER",$owner);
1546 :     $featuretbl->set_metadata("SIZE",$size);
1547 :     $self->set_cache($OrganismID."-FEATURETABLE",$featuretbl);
1548 :     return $featuretbl;
1549 :     }
1550 :    
1551 :     =head3 get_media
1552 :     Definition:
1553 :     {string=>[string]} = FIGMODELdatabase->get_media(string::media id);
1554 :     Description:
1555 :     Returns the media row from the media table
1556 :     =cut
1557 :     sub get_media {
1558 :     my($self,$id) = @_;
1559 :    
1560 :     my $tbl = $self->GetDBTable("MEDIA");
1561 :     if (!defined($tbl)) {
1562 :     return undef;
1563 :     }
1564 :    
1565 :     if ($id =~ m/^\d+$/) {
1566 :     return $tbl->get_row($id);
1567 :     }
1568 :     return $tbl->get_row_by_key($id,"NAME");
1569 :     }
1570 :    
1571 :     =head3 get_media_number
1572 :     Definition:
1573 :     int = FIGMODELdatabase->get_media_number();
1574 :     Description:
1575 :     Returns the number of media formulations in the database
1576 :     =cut
1577 :     sub get_media_number {
1578 :     my($self) = @_;
1579 :    
1580 :     my $tbl = $self->GetDBTable("MEDIA");
1581 :     return $tbl->size();
1582 :     }
1583 :    
1584 :     =head3 get_compound
1585 :     Definition:
1586 :     {string=>[string]}::compound data = FIGMODEL->get_compound(string::compound ID);
1587 :     Description:
1588 :     =cut
1589 :     sub get_compound {
1590 :     my ($self,$id) = @_;
1591 :    
1592 :     if ($id =~ m/^\d+$/) {
1593 :     my $cpdtbl = $self->GetDBTable("COMPOUNDS");
1594 :     if (!defined($cpdtbl)) {
1595 :     return undef;
1596 :     }
1597 :     return $cpdtbl->get_row($id);
1598 :     }
1599 :     return $self->get_row_by_key("COMPOUNDS",$id,"DATABASE");
1600 :     }
1601 :    
1602 :     =head3 get_compound_number
1603 :     Definition:
1604 :     int = FIGMODEL->get_compound_number();
1605 :     Description:
1606 :     =cut
1607 :     sub get_compound_number {
1608 :     my ($self) = @_;
1609 :    
1610 :     my $cpdtbl = $self->database()->GetDBTable("COMPOUNDS");
1611 :     if (!defined($cpdtbl)) {
1612 :     return 0;
1613 :     }
1614 :     return $cpdtbl->size();
1615 :     }
1616 :    
1617 :     =head3 ConsolidateMediaFiles
1618 :     Definition:
1619 :     FIGMODELdatabase->ConsolidateMediaFiles();
1620 :     Description:
1621 :     This function consolidates all of the various media formulations in the Media directory into a single file.
1622 :     This file is formated as a FIGMODELTable, and it is used by the mpifba code to determine media formulations.
1623 :     The file will be in the masterfiles directory names: MediaTable.txt.
1624 :     =cut
1625 :     sub ConsolidateMediaFiles {
1626 :     my ($self) = @_;
1627 :    
1628 :     #Creating a new media table
1629 : dejongh 1.21 my $names = $self->config("Reaction database directory");
1630 :     my $MediaTable = FIGMODELTable->new(["NAME","NAMES","COMPOUNDS","MAX","MIN"],$names->[0]."masterfiles/MediaTable.txt",["NAME","COMPOUNDS"],";","|",undef);
1631 : chenry 1.2 #Loading media formulations into table
1632 : dejongh 1.21 my $mediadir = $self->config("Media directory");
1633 :     my @Filenames = glob($mediadir->[0]."*");
1634 : chenry 1.2 foreach my $Filename (@Filenames) {
1635 :     if ($Filename !~ m/Test/ && $Filename =~ m/\/([^\/]+)\.txt/) {
1636 :     my $MediaName = $1;
1637 :     my $MediaFormulation = $self->load_table($Filename,";","",0,undef);
1638 :     my ($CompoundList,$NameList,$MaxList,$MinList);
1639 :     for (my $i=0; $i < $MediaFormulation->size(); $i++) {
1640 : chenry 1.3 if ($MediaFormulation->get_row($i)->{"VarName"}->[0] =~ m/cpd\d\d\d\d\d/) {
1641 :     push(@{$CompoundList},$MediaFormulation->get_row($i)->{"VarName"}->[0]);
1642 :     my $CompoundData = $self->get_compound($MediaFormulation->get_row($i)->{"VarName"}->[0]);
1643 :     if (defined($CompoundData) && defined($CompoundData->{NAME}->[0])) {
1644 :     push(@{$NameList},$CompoundData->{NAME}->[0]);
1645 :     }
1646 :     push(@{$MinList},$MediaFormulation->get_row($i)->{"Min"}->[0]);
1647 :     push(@{$MaxList},$MediaFormulation->get_row($i)->{"Max"}->[0]);
1648 : chenry 1.2 }
1649 :     }
1650 :     $MediaTable->add_row({"NAME" => [$MediaName],"NAMES" => $NameList,"COMPOUNDS" => $CompoundList,"MAX" => $MaxList,"MIN" => $MinList});
1651 :     }
1652 :     }
1653 :    
1654 :     #Saving the table
1655 :     $MediaTable->save();
1656 :    
1657 :     return $MediaTable;
1658 :     }
1659 :    
1660 : chenry 1.5 =head3 FillInMissingMediaFiles
1661 :     Definition:
1662 :     FIGMODELdatabase->FillInMissingMediaFiles();
1663 :     Description:
1664 :     =cut
1665 :    
1666 :     sub FillInMissingMediaFiles {
1667 :     my($self) = @_;
1668 :    
1669 :     my $tbl = $self->GetDBTable("MEDIA");
1670 :     for (my $i=0; $i < $tbl->size(); $i++) {
1671 :     my $row = $tbl->get_row($i);
1672 :     if (!-e $self->figmodel()->config("Media directory")->[0].$row->{NAME}->[0].".txt") {
1673 :     my $output = ["VarName;VarType;VarCompartment;Min;Max"];
1674 :     for (my $j=0; $j < @{$row->{COMPOUNDS}}; $j++) {
1675 :     push(@{$output},$row->{COMPOUNDS}->[$j].";DRAIN_FLUX;e;".$row->{MIN}->[$j].";".$row->{MAX}->[$j]);
1676 :     }
1677 :     $self->print_array_to_file($self->figmodel()->config("Media directory")->[0].$row->{NAME}->[0].".txt",$output);
1678 :     }
1679 :     }
1680 :     }
1681 :    
1682 : chenry 1.2 =head3 ProcessDatabaseWithMFAToolkit
1683 :     Definition:
1684 :     FIGMODELdatabase->ProcessDatabaseWithMFAToolkit(string||[string]::list of entities to be processed);
1685 :     Description:
1686 :     This function uses the MFAToolkit to process the entire reaction database. This involves balancing reactions, calculating thermodynamic data, and parsing compound structure files for charge and formula.
1687 :     This function should be run when reactions are added or changed, or when structures are added or changed.
1688 :     The database should probably be backed up before running the function just in case something goes wrong.
1689 :     =cut
1690 :    
1691 :     sub ProcessDatabaseWithMFAToolkit {
1692 :     my($self,$processlist) = @_;
1693 :     #Checking that the processlist exists
1694 :     if (!defined($processlist) || $processlist eq "ALL") {
1695 :     my @FilenameList = glob($self->config("compound directory")->[0]."cpd*");
1696 :     for (my $j=0; $j < @FilenameList; $j++) {
1697 :     if ($FilenameList[$j] =~ m/(cpd\d\d\d\d\d)/) {
1698 :     push(@{$processlist},$1);
1699 :     }
1700 :     }
1701 :     @FilenameList = glob($self->config("reaction directory")->[0]."rxn*");
1702 :     for (my $j=0; $j < @FilenameList; $j++) {
1703 :     if ($FilenameList[$j] =~ m/(rxn\d\d\d\d\d)/) {
1704 :     push(@{$processlist},$1);
1705 :     }
1706 :     }
1707 :     }
1708 :     #Getting unique directory for output
1709 :     my $outputfolder = $self->figmodel()->filename();
1710 :     #Ensuring that the newcompounds and newreactions directories exist
1711 :     if (!-d $self->config("Reaction database directory")->[0]."newreactions/") {
1712 :     system("mkdir ".$self->config("Reaction database directory")->[0]."newreactions/");
1713 :     }
1714 :     if (!-d $self->config("Reaction database directory")->[0]."newcompounds/") {
1715 :     system("mkdir ".$self->config("Reaction database directory")->[0]."newcompounds/");
1716 :     }
1717 :     if (!-d $self->config("Reaction database directory")->[0]."oldreactions/") {
1718 :     system("mkdir ".$self->config("Reaction database directory")->[0]."oldreactions/");
1719 :     }
1720 :     if (!-d $self->config("Reaction database directory")->[0]."oldcompounds/") {
1721 :     system("mkdir ".$self->config("Reaction database directory")->[0]."oldcompounds/");
1722 :     }
1723 :     #Printing the process list to file if it exists
1724 :     $self->print_array_to_file($self->config("MFAToolkit input files")->[0].$outputfolder."-processList.txt",$processlist);
1725 :     #Eliminating the mfatoolkit errors from the compound and reaction files
1726 :     for (my $j=0; $j < @{$processlist}; $j++) {
1727 :     my $Data = $self->figmodel()->LoadObject($processlist->[$j]);
1728 :     for (my $i=0; $i < @{$Data->{"orderedkeys"}}; $i++) {
1729 :     if ($Data->{"orderedkeys"}->[$i] eq "MFATOOLKIT ERRORS") {
1730 :     splice(@{$Data->{"orderedkeys"}},$i,1);
1731 :     last;
1732 :     }
1733 :     }
1734 :     $self->figmodel()->SaveObject($Data);
1735 :     }
1736 :     #Running the mfatoolkit
1737 :     system($self->figmodel()->GenerateMFAToolkitCommandLineCall($outputfolder,"processdatabase","NONE",["ArgonneProcessing"],{"entities to process" => $outputfolder."-processList.txt"},"DBProcessing-".$outputfolder.".log"));
1738 :     #Backing up the current reaction and compound directories
1739 :     for (my $i=0; $i < @{$processlist}; $i++) {
1740 :     if ($processlist->[$i] =~ m/cpd\d\d\d\d\d/) {
1741 :     system("cp ".$self->config("compound directory")->[0].$processlist->[$i]." ".$self->config("Reaction database directory")->[0]."oldcompounds/".$processlist->[$i]);
1742 :     system("cp ".$self->config("Reaction database directory")->[0]."newcompounds/".$processlist->[$i]." ".$self->config("compound directory")->[0].$processlist->[$i]);
1743 :     } elsif ($processlist->[$i] =~ m/rxn\d\d\d\d\d/) {
1744 :     system("cp ".$self->config("reaction directory")->[0].$processlist->[$i]." ".$self->config("Reaction database directory")->[0]."oldreactions/".$processlist->[$i]);
1745 :     system("cp ".$self->config("Reaction database directory")->[0]."newreactions/".$processlist->[$i]." ".$self->config("reaction directory")->[0].$processlist->[$i]);
1746 :     }
1747 :     }
1748 :     system("rm ".$self->config("MFAToolkit input files")->[0].$outputfolder."-processList.txt");
1749 :     $self->figmodel()->clearing_output($outputfolder,"DBProcessing-".$outputfolder.".log");
1750 :     return $self->figmodel()->success();
1751 :     }
1752 :    
1753 : chenry 1.5 =head3 check_for_file
1754 :     Definition:
1755 :     [string]:filelines = FIGMODELdatabase->check_for_file([string]:filename)
1756 :     Description:
1757 :     =cut
1758 :     sub check_for_file {
1759 :     my ($self,$input) = @_;
1760 :    
1761 :     if (@{$input} == 1 && -e $input->[0]) {
1762 :     return $self->load_single_column_file($input->[0]);
1763 :     }
1764 :     return $input;
1765 :     }
1766 :    
1767 : chenry 1.7 =head3 convert_ids_to_search_terms
1768 :     Definition:
1769 :     {string:term => [string]:IDs} = FIGMODELdatabase->convert_ids_to_search_terms([string]:IDs)
1770 :     Description:
1771 :     =cut
1772 :     sub convert_ids_to_search_terms {
1773 :     my ($self,$IDList) = @_;
1774 :    
1775 :     #Converting the $IDList into a flat array ref of IDs
1776 :     my $NewIDList;
1777 :     if (defined($IDList) && ref($IDList) ne 'ARRAY') {
1778 :     my @TempArray = split(/,/,$IDList);
1779 :     for (my $j=0; $j < @TempArray; $j++) {
1780 :     push(@{$NewIDList},$TempArray[$j]);
1781 :     }
1782 :     } elsif (defined($IDList)) {
1783 :     for (my $i=0; $i < @{$IDList}; $i++) {
1784 :     my @TempArray = split(/,/,$IDList->[$i]);
1785 :     for (my $j=0; $j < @TempArray; $j++) {
1786 :     push(@{$NewIDList},$TempArray[$j]);
1787 :     }
1788 :     }
1789 :     }
1790 :    
1791 :     #Determining the type of each ID
1792 :     my $TypeLists;
1793 :     if (defined($NewIDList)) {
1794 :     for (my $i=0; $i < @{$NewIDList}; $i++) {
1795 :     if ($NewIDList->[$i] ne "ALL") {
1796 :     if ($NewIDList->[$i] =~ m/^fig\|(\d+\.\d+)\.(.+)$/) {
1797 :     push(@{$TypeLists->{"feature"}},$NewIDList->[$i]);
1798 :     } elsif ($NewIDList->[$i] =~ m/^figint\|(\d+\.\d+)\.(.+)$/) {
1799 :     push(@{$TypeLists->{"interval"}},$2);
1800 :     } elsif ($NewIDList->[$i] =~ m/^figstr\|(\d+\.\d+)\.(.+)$/) {
1801 :     push(@{$TypeLists->{"strain"}},$2);
1802 :     } elsif ($NewIDList->[$i] =~ m/^figmodel\|(.+)$/) {
1803 :     push(@{$TypeLists->{"model"}},$2);
1804 :     } elsif ($NewIDList->[$i] =~ m/^fig\|(\d+\.\d+)$/ || $NewIDList->[$i] =~ m/^(\d+\.\d+)$/) {
1805 :     push(@{$TypeLists->{"genome"}},$1);
1806 :     } elsif ($NewIDList->[$i] =~ m/^(rxn\d\d\d\d\d)$/) {
1807 :     push(@{$TypeLists->{"reaction"}},$1);
1808 :     } elsif ($NewIDList->[$i] =~ m/^(cpd\d\d\d\d\d)$/) {
1809 :     push(@{$TypeLists->{"compound"}},$1);
1810 :     } else {
1811 :     push(@{$TypeLists->{"model"}},$NewIDList->[$i]);
1812 :     }
1813 :     }
1814 :     }
1815 :     }
1816 :    
1817 :     return $TypeLists;
1818 :     }
1819 :    
1820 :     =head3 get_erdb_table
1821 :     Definition:
1822 :     = FIGMODELdatabase->get_erdb_table()
1823 :     Description:
1824 :     =cut
1825 :     sub get_erdb_table {
1826 :     # my ($self) = @_;
1827 :     # my $obj = Sapling->new();
1828 :     #
1829 :     # my @ids = $obj->GetFlat("Model","Model(class) = ? and Model(totalGenes) > ?",["Gram positive","1000"],"id");
1830 :     # print "All ids:".join(",",@ids)."\n";
1831 :     #
1832 :     # my @objects = $obj->GetList("Model","Model(class) = ? and Model(totalGenes) > ?",["Gram positive","1000"]);
1833 :     #
1834 :     # #Changing feild
1835 :     # $obj->UpdateEntity("Model",$objects[0]->PrimaryValue("id"),%$hash);
1836 :     #
1837 :     # #Inserting new object
1838 :     # $obj->InsertObject("Model",%$hash);
1839 :     #
1840 :     # #Deleting element and everything attached to element
1841 :     # $obj->Delete("Model","iJR904");
1842 :     #
1843 :     # my @ids = $obj->GetFlat("Model","Model(class) = ? and Model(totalGenes) > ?",["Gram positive","1000"],"id");
1844 :     #
1845 :     #
1846 :     #
1847 :     #
1848 :     # my @value = $objects[0]->Value("id");
1849 :     # print "Single value:".$value[0]."\n";
1850 :     # print "Single value:".$objects[0]->PrimaryValue("id")."\n";
1851 :     #
1852 :     # my @info = $obj->GetAll("Model","Model(class) = ? and Model(totalGenes) > ?",["Gram positive","1000"],["id","totalGenes"]);
1853 :     # print "ID:".$info[0]->[0]."\tTotal genes:".$info[0]->[1]."\n";
1854 :     }
1855 :    
1856 : chenry 1.17 sub load_ppo {
1857 :     my($self,$object) = @_;
1858 :     if ($object eq "media") {
1859 :     my $mediaTbl = $self->figmodel()->database()->get_table("MEDIA");
1860 :     for (my $i=0; $i < $mediaTbl->size(); $i++) {
1861 :     my $row = $mediaTbl->get_row($i);
1862 :     my $aerobic = 0;
1863 :     for (my $j=0; $j < @{$row->{COMPOUNDS}}; $j++) {
1864 :     if ($row->{COMPOUNDS}->[$j] eq "cpd00007" && $row->{MAX}->[$j] > 0) {
1865 :     $aerobic = 1;
1866 :     last;
1867 :     }
1868 :     }
1869 :     my $mediaMgr = $self->figmodel()->database()->get_object_manager("media");
1870 :     $mediaMgr->create({id=>$row->{NAME}->[0],owner=>"master",modificationDate=>time(),creationDate=>time(),aerobic=>$aerobic});
1871 :     }
1872 :     } elsif ($object eq "mediacpd") {
1873 :     my $mediaTbl = $self->figmodel()->database()->get_table("MEDIA");
1874 :     for (my $i=0; $i < $mediaTbl->size(); $i++) {
1875 :     my $row = $mediaTbl->get_row($i);
1876 :     my $alreadySeed;
1877 :     for (my $j=0; $j < @{$row->{COMPOUNDS}}; $j++) {
1878 :     if (!defined($alreadySeed->{$row->{COMPOUNDS}->[$j]})) {
1879 :     $alreadySeed->{$row->{COMPOUNDS}->[$j]} = 1;
1880 :     my $max = 100;
1881 :     my $conc = 0.001;
1882 :     if (defined($row->{MAX}->[$j])) {
1883 :     $max = $row->{MAX}->[$j];
1884 :     }
1885 :     my $mediaMgr = $self->figmodel()->database()->get_object_manager("mediacpd");
1886 :     $mediaMgr->create({MEDIA=>$row->{NAME}->[0],COMPOUND=>$row->{COMPOUNDS}->[$j],concentration=>$conc,maxFlux=>$max});
1887 :     } else {
1888 :     print "Compound ".$row->{COMPOUNDS}->[$j]." repeated in ".$row->{NAME}->[0]." media!\n";
1889 :     }
1890 :     }
1891 :     }
1892 :     } elsif ($object eq "compound") {
1893 :     my $tbl = $self->figmodel()->database()->get_table("COMPOUNDS");
1894 :     for (my $i=0; $i < $tbl->size(); $i++) {
1895 :     my $row = $tbl->get_row($i);
1896 :     my $name = $row->{NAME}->[0];
1897 :     for (my $j=1; $j < @{$row->{NAME}}; $j++) {
1898 :     if (length($name) > 32) {
1899 :     $name = $row->{NAME}->[$j];
1900 :     last;
1901 :     }
1902 :     }
1903 :     if (length($name) > 32) {
1904 :     $name = substr($name,32);
1905 :     }
1906 :     my $dataHash = {id=>$row->{DATABASE}->[0],name=>$name,owner=>"master",users=>"all",modificationDate=>time(),creationDate=>time()};
1907 :     if (defined($row->{STRINGCODE}->[0])) {
1908 :     $dataHash->{stringcode} = $row->{STRINGCODE}->[0];
1909 :     }
1910 :     if (defined($row->{DELTAG}->[0])) {
1911 :     $dataHash->{deltaG} = $row->{DELTAG}->[0];
1912 :     }
1913 :     if (defined($row->{DELTAGERR}->[0])) {
1914 :     $dataHash->{deltaGErr} = $row->{DELTAGERR}->[0];
1915 :     }
1916 :     if (defined($row->{FORMULA}->[0])) {
1917 :     $dataHash->{formula} = $row->{FORMULA}->[0];
1918 :     }
1919 :     if (defined($row->{MASS}->[0])) {
1920 :     $dataHash->{mass} = $row->{MASS}->[0];
1921 :     }
1922 :     if (defined($row->{CHARGE}->[0])) {
1923 :     $dataHash->{charge} = $row->{CHARGE}->[0];
1924 :     }
1925 :     my $fileData = FIGMODELObject->load($self->config("compound directory")->[0].$row->{DATABASE}->[0],"\t");
1926 :     if (defined($fileData->{PKA})) {
1927 :     $dataHash->{pKa} = join(";",@{$fileData->{PKA}});
1928 :     }
1929 :     if (defined($fileData->{PKB})) {
1930 :     $dataHash->{pKb} = join(";",@{$fileData->{PKB}});
1931 :     }
1932 :     if (defined($fileData->{STRUCTURAL_CUES})) {
1933 :     $dataHash->{structuralCues} = join(";",@{$fileData->{STRUCTURAL_CUES}});
1934 :     }
1935 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("compound");
1936 :     $cpdMgr->create($dataHash);
1937 :     }
1938 :     } elsif ($object eq "cpdals") {
1939 :     my $aliasHash;
1940 :     my $tbl = $self->figmodel()->database()->get_table("COMPOUNDS");
1941 :     for (my $i=0; $i < $tbl->size(); $i++) {
1942 :     my $row = $tbl->get_row($i);
1943 :     for (my $j=0; $j < @{$row->{NAME}}; $j++) {
1944 :     if (!defined($aliasHash->{$row->{DATABASE}->[0]}->{name}->{lc($row->{NAME}->[$j])})) {
1945 :     $aliasHash->{$row->{DATABASE}->[0]}->{name}->{lc($row->{NAME}->[$j])} = 1;
1946 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("cpdals");
1947 :     $cpdMgr->create({COMPOUND=>$row->{DATABASE}->[0],alias=>$row->{NAME}->[$j],type=>"name"});
1948 :     my @searchNames = $self->figmodel()->ConvertToSearchNames($row->{NAME}->[$j]);
1949 :     for (my $k=0; $k < @searchNames; $k++) {
1950 :     if (!defined($aliasHash->{$row->{DATABASE}->[0]}->{searchname}->{lc($searchNames[$k])})) {
1951 :     $aliasHash->{$row->{DATABASE}->[0]}->{searchname}->{lc($searchNames[$k])} = 1;
1952 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("cpdals");
1953 :     $cpdMgr->create({COMPOUND=>$row->{DATABASE}->[0],alias=>lc($searchNames[$k]),type=>"searchname"});
1954 :     }
1955 :     }
1956 :     }
1957 :     }
1958 :     }
1959 :     my @files = glob($self->figmodel()->config("Translation directory")->[0]."CpdTo*");
1960 :     for (my $i=0; $i < @files; $i++) {
1961 :     if ($files[$i] !~ m/CpdToAll/ && $files[$i] =~ m/CpdTo(.+)\.txt/) {
1962 :     my $type = $1;
1963 :     my $data = $self->load_multiple_column_file($files[$i],"\t");
1964 :     for (my $j=0; $j < @{$data}; $j++) {
1965 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("cpdals");
1966 :     $cpdMgr->create({COMPOUND=>$data->[$j]->[0],alias=>$data->[$j]->[1],type=>$type});
1967 :     }
1968 :     }
1969 :     }
1970 :     my $data = $self->load_multiple_column_file($self->figmodel()->config("Translation directory")->[0]."ObsoleteCpdIDs.txt","\t");
1971 :     for (my $j=0; $j < @{$data}; $j++) {
1972 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("cpdals");
1973 :     $cpdMgr->create({COMPOUND=>$data->[$j]->[0],alias=>$data->[$j]->[1],type=>"obsolete"});
1974 :     }
1975 : chenry 1.18 } elsif ($object eq "reaction") {
1976 :     my $tbl = $self->figmodel()->database()->get_table("REACTIONS");
1977 :     for (my $i=0; $i < $tbl->size(); $i++) {
1978 :     my $row = $tbl->get_row($i);
1979 :     my $name = $row->{DATABASE}->[0];
1980 :     if (defined($row->{NAME}->[0])){
1981 :     $name = $row->{NAME}->[0];
1982 :     for (my $j=1; $j < @{$row->{NAME}}; $j++) {
1983 :     if (length($name) > 250 && length($row->{NAME}->[$j]) < 32) {
1984 :     $name = $row->{NAME}->[$j];
1985 :     last;
1986 :     }
1987 :     }
1988 :     if (length($name) > 250) {
1989 :     $name = substr($name,250);
1990 :     }
1991 :     }
1992 :     my $rxnObj = $self->figmodel()->LoadObject($row->{DATABASE}->[0]);
1993 :     my $thermodynamicReversibility = "<=>";
1994 :     my $definition = "NONE";
1995 :     if (defined($rxnObj) && defined($rxnObj->{DEFINITION}->[0])) {
1996 :     $definition = $rxnObj->{DEFINITION}->[0];
1997 :     }
1998 :     if (defined($rxnObj) && defined($rxnObj->{"THERMODYNAMIC REVERSIBILITY"}->[0])) {
1999 :     $thermodynamicReversibility = $rxnObj->{"THERMODYNAMIC REVERSIBILITY"}->[0];
2000 :     }
2001 :     my $dataHash = {id=>$row->{DATABASE}->[0],name=>$name,thermoReversibility=>$thermodynamicReversibility,reversibility=>$self->figmodel()->reversibility_of_reaction($row->{DATABASE}->[0]),definition=>$definition,code=>$row->{CODE}->[0],equation=>$row->{EQUATION}->[0],owner=>"master",users=>"all",modificationDate=>time(),creationDate=>time()};
2002 :     if (defined($row->{ENZYME}->[0])) {
2003 :     $dataHash->{enzyme} = "|".join("|",@{$row->{ENZYME}})."|";
2004 :     }
2005 :     if (defined($row->{DELTAG}->[0])) {
2006 :     $dataHash->{deltaG} = $row->{DELTAG}->[0];
2007 :     }
2008 :     if (defined($row->{DELTAGERR}->[0])) {
2009 :     $dataHash->{deltaGErr} = $row->{DELTAGERR}->[0];
2010 :     }
2011 :    
2012 :     if (defined($rxnObj->{STRUCTURAL_CUES})) {
2013 :     $dataHash->{structuralCues} = "|".join("|",@{$rxnObj->{STRUCTURAL_CUES}})."|";
2014 :     }
2015 :     my $rxnMgr = $self->figmodel()->database()->get_object_manager("reaction");
2016 :     $rxnMgr->create($dataHash);
2017 :     my ($reactants,$products) = $self->figmodel()->GetReactionSubstrateDataFromEquation($row->{EQUATION}->[0]);
2018 :     if (defined($reactants)) {
2019 :     for (my $j=0; $j < @{$reactants}; $j++) {
2020 :     my $cpdrxnMgr = $self->figmodel()->database()->get_object_manager("cpdrxn");
2021 :     $cpdrxnMgr->create({COMPOUND=>$reactants->[$j]->{DATABASE}->[0],REACTION=>$row->{DATABASE}->[0],coefficient=>-1*$reactants->[$j]->{COEFFICIENT}->[0],compartment=>$reactants->[$j]->{COMPARTMENT}->[0],cofactor=>"false"});
2022 :     }
2023 :     }
2024 :     if (defined($products)) {
2025 :     for (my $j=0; $j < @{$products}; $j++) {
2026 :     my $cpdrxnMgr = $self->figmodel()->database()->get_object_manager("cpdrxn");
2027 :     $cpdrxnMgr->create({COMPOUND=>$products->[$j]->{DATABASE}->[0],REACTION=>$row->{DATABASE}->[0],coefficient=>$products->[$j]->{COEFFICIENT}->[0],compartment=>$products->[$j]->{COMPARTMENT}->[0],cofactor=>"false"});
2028 :     }
2029 :     }
2030 :     }
2031 :     } elsif ($object eq "rxnals") {
2032 :     my @files = glob($self->figmodel()->config("Translation directory")->[0]."RxnTo*");
2033 :     for (my $i=0; $i < @files; $i++) {
2034 :     if ($files[$i] !~ m/RxnToAll/ && $files[$i] =~ m/RxnTo(.+)\.txt/) {
2035 :     my $type = $1;
2036 :     my $data = $self->load_multiple_column_file($files[$i],"\t");
2037 :     for (my $j=0; $j < @{$data}; $j++) {
2038 :     my $rxnMgr = $self->figmodel()->database()->get_object_manager("rxnals");
2039 :     $rxnMgr->create({REACTION=>$data->[$j]->[0],alias=>$data->[$j]->[1],type=>$type});
2040 :     }
2041 :     }
2042 :     }
2043 :     my $data = $self->load_multiple_column_file($self->figmodel()->config("Translation directory")->[0]."ObsoleteRxnIDs.txt","\t");
2044 :     for (my $j=0; $j < @{$data}; $j++) {
2045 :     my $rxnMgr = $self->figmodel()->database()->get_object_manager("rxnals");
2046 :     $rxnMgr->create({REACTION=>$data->[$j]->[0],alias=>$data->[$j]->[1],type=>"obsolete"});
2047 :     }
2048 :     } elsif ($object eq "bof") {
2049 :     my $aliasHash;
2050 :     my $tbl = $self->figmodel()->database()->get_table("BIOMASS");
2051 :     my $botTempTbl = $self->figmodel()->database()->GetDBTable("BIOMASS TEMPLATE");
2052 :     my $groupHash;
2053 :     my $grpIndex = {L=>"pkg00001",W=>"pkg00001",C=>"pkg00001"};
2054 :     my $mdlMgr = $self->figmodel()->database()->get_object_manager("model");
2055 :     for (my $i=0; $i < $tbl->size(); $i++) {
2056 :     my $row = $tbl->get_row($i);
2057 :     my $cpdMgr = $self->figmodel()->database()->get_object_manager("bof");
2058 :     my $data = {id=>$row->{DATABASE}->[0],name=>"Biomass",equation=>$row->{EQUATION}->[0],protein=>"0.5284",DNA=>"0.026",RNA=>"0.0655",lipid=>"0.075",cellWall=>"0.25",cofactor=>"0.10",modificationDate=>time(),creationDate=>time()};
2059 :     $data->{owner} = "master";
2060 :     $data->{users} = "all";
2061 :     my $mdlObjs = $mdlMgr->get_objects({biomassReaction=>$row->{DATABASE}->[0]});
2062 :     if (defined($mdlObjs->[0]) && !defined($mdlObjs->[1])) {
2063 :     $data->{owner} = $mdlObjs->[0]->owner();
2064 :     $data->{users} = $mdlObjs->[0]->users();
2065 :     }
2066 :     my ($lccdata,$coef,$package);
2067 :     my ($reactants,$products) = $self->figmodel()->GetReactionSubstrateDataFromEquation($row->{EQUATION}->[0]);
2068 :     #Populating the compound biomass table
2069 :     my $hash;
2070 :     for (my $j=0; $j < @{$reactants}; $j++) {
2071 :     my $category = "U";#Unknown
2072 :     my $tempRow = $botTempTbl->get_row_by_key($reactants->[$j]->{DATABASE}->[0],"ID");
2073 :     if (defined($tempRow) && $tempRow->{CLASS}->[0] eq "LIPIDS") {
2074 :     $category = "L";#Lipid
2075 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "CELL WALL") {
2076 :     $category = "W";#Cell wall
2077 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "COFACTOR") {
2078 :     $category = "C";#Cofactor
2079 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "ENERGY") {
2080 :     $category = "E";#Energy
2081 :     } elsif (defined($tempRow)) {
2082 :     $category = "M";#Macromolecule
2083 :     }
2084 :     $lccdata->{$category}->{$reactants->[$j]->{DATABASE}->[0]} = "-".$reactants->[$j]->{COEFFICIENT}->[0];
2085 :     if (!defined($hash->{$reactants->[$j]->{DATABASE}->[0]}->{$row->{DATABASE}->[0]}->{$reactants->[$j]->{COMPARTMENT}->[0]})) {
2086 :     $hash->{$reactants->[$j]->{DATABASE}->[0]}->{$row->{DATABASE}->[0]}->{$reactants->[$j]->{COMPARTMENT}->[0]} = 1;
2087 :     my $cpdbofMgr = $self->figmodel()->database()->get_object_manager("cpdbof");
2088 :     $cpdbofMgr->create({COMPOUND=>$reactants->[$j]->{DATABASE}->[0],BIOMASS=>$row->{DATABASE}->[0],coefficient=>(-1*$reactants->[$j]->{COEFFICIENT}->[0]),compartment=>$reactants->[$j]->{COMPARTMENT}->[0],category=>$category});
2089 :     }
2090 :     }
2091 :     for (my $j=0; $j < @{$products}; $j++) {
2092 :     my $category = "U";#Unknown
2093 :     my $tempRow = $botTempTbl->get_row_by_key($products->[$j]->{DATABASE}->[0],"ID");
2094 :     if (defined($tempRow) && $tempRow->{CLASS}->[0] eq "LIPIDS") {
2095 :     $category = "L";#Lipid
2096 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "CELL WALL") {
2097 :     $category = "W";#Cell wall
2098 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "COFACTOR") {
2099 :     $category = "C";#Cofactor
2100 :     } elsif (defined($tempRow) && $tempRow->{CLASS}->[0] eq "ENERGY") {
2101 :     $category = "E";#Energy
2102 :     } elsif (defined($tempRow)) {
2103 :     $category = "M";#Macromolecule
2104 :     }
2105 :     $lccdata->{$category}->{$products->[$j]->{DATABASE}->[0]} = "-".$products->[$j]->{COEFFICIENT}->[0];
2106 :     if (!defined($hash->{$products->[$j]->{DATABASE}->[0]}->{$row->{DATABASE}->[0]}->{$products->[$j]->{COMPARTMENT}->[0]})) {
2107 :     $hash->{$products->[$j]->{DATABASE}->[0]}->{$row->{DATABASE}->[0]}->{$products->[$j]->{COMPARTMENT}->[0]} = 1;
2108 :     my $cpdbofMgr = $self->figmodel()->database()->get_object_manager("cpdbof");
2109 :     $cpdbofMgr->create({COMPOUND=>$products->[$j]->{DATABASE}->[0],BIOMASS=>$row->{DATABASE}->[0],coefficient=>$products->[$j]->{COEFFICIENT}->[0],compartment=>$products->[$j]->{COMPARTMENT}->[0],category=>$category});
2110 :     }
2111 :     }
2112 :     my $types = ["L","C","W"];
2113 :     my $typeNames = {L=>"Lipid",C=>"Cofactor",W=>"CellWall"};
2114 :     for (my $j=0; $j < @{$types}; $j++) {
2115 :     if (!defined($lccdata->{$types->[$j]})) {
2116 :     $coef->{$types->[$j]} = "NONE";
2117 :     $package->{$types->[$j]} = "NONE";
2118 :     } else {
2119 :     my @list = sort(keys(%{$lccdata->{$types->[$j]}}));
2120 :     for (my $k=0; $k < @list; $k++) {
2121 :     $coef->{$types->[$j]} .= $lccdata->{$types->[$j]}->{$list[$k]}.";";
2122 :     }
2123 :     my $key = join(";",@list);
2124 :     if (!defined($groupHash->{$types->[$j]}->{$key})) {
2125 :     $groupHash->{$types->[$j]}->{$key} = $grpIndex->{$types->[$j]};
2126 :     for (my $k=0; $k < @list; $k++) {
2127 :     print "Creating compound group:";
2128 :     my $cpdGrpMgr = $self->figmodel()->database()->get_object_manager("cpdgrp");
2129 :     $cpdGrpMgr->create({COMPOUND=>$list[$k],grouping=>$grpIndex->{$types->[$j]},type=>$typeNames->{$types->[$j]}."Package"});
2130 :     print "DONE\n";
2131 :     }
2132 :     $grpIndex->{$types->[$j]}++;
2133 :     }
2134 :     $package->{$types->[$j]} = $groupHash->{$types->[$j]}->{$key};
2135 :     }
2136 :     }
2137 :     $data->{cofactorPackage} = $package->{"C"};
2138 :     $data->{lipidPackage} = $package->{"L"};
2139 :     $data->{cellWallPackage} = $package->{"W"};
2140 :     $data->{DNACoef} = "-0.284|1|-0.216|-0.216|-0.284";
2141 :     $data->{RNACoef} = "1|-0.262|-0.323|-0.199|-0.215";
2142 :     $data->{proteinCoef} = "1|-0.0637|-0.0999|-0.0653|-0.0790|-0.0362|-0.0472|-0.0637|-0.0529|-0.0277|-0.0133|-0.0430|-0.0271|-0.0139|-0.0848|-0.0200|-0.0393|-0.0362|-0.0751|-0.0456|-0.0660";
2143 :     $data->{lipidCoef} = $coef->{"L"};
2144 :     $data->{cellWallCoef} = $coef->{"W"};
2145 :     $data->{cofactorCoef} = $coef->{"C"};
2146 :     $data->{energy} = 40;
2147 :     if (defined($row->{"ESSENTIAL REACTIONS"})) {
2148 :     $data->{essentialRxn} = join("|",@{$row->{"ESSENTIAL REACTIONS"}});
2149 :     }
2150 :     print "Creating biomass reaction.";
2151 :     $cpdMgr->create($data);
2152 :     print "Done.\n";
2153 :     }
2154 : chenry 1.17 }
2155 :     }
2156 :    
2157 : chenry 1.20 =head3 add_biomass_reaction_from_file
2158 :     Definition:
2159 :     (success/fail) = FIGMODELdatabase>add_biomass_reaction_from_file(string:biomass ID);
2160 :     =cut
2161 :     sub add_biomass_reaction_from_file {
2162 :     my($self,$biomassID) = @_;
2163 :     my $object = $self->LoadObject($biomassID);
2164 :     #Parsing equation
2165 :     my ($reactants,$products) = $self->figmodel()->GetReactionSubstrateDataFromEquation($object->{EQUATION}->[0]);
2166 :     #Populating the compound biomass table
2167 :     my $energy = 0;
2168 :     my $compounds;
2169 :     $compounds->{RNA} = {cpd00002=>0,cpd00012=>0,cpd00038=>0,cpd00052=>0,cpd00062=>0};
2170 :     $compounds->{protein} = {cpd00001=>0,cpd00023=>0,cpd00033=>0,cpd00035=>0,cpd00039=>0,cpd00041=>0,cpd00051=>0,cpd00053=>0,cpd00054=>0,cpd00060=>0,cpd00065=>0,cpd00066=>0,cpd00069=>0,cpd00084=>0,cpd00107=>0,cpd00119=>0,cpd00129=>0,cpd00132=>0,cpd00156=>0,cpd00161=>0,cpd00322=>0};
2171 :     $compounds->{DNA} = {cpd00012=>0,cpd00115=>0,cpd00241=>0,cpd00356=>0,cpd00357=>0};
2172 :     for (my $j=0; $j < @{$reactants}; $j++) {
2173 :     my $category = "U";
2174 :     if ($reactants->[$j]->{DATABASE}->[0] eq "cpd00002" || $reactants->[$j]->{DATABASE}->[0] eq "cpd00001") {
2175 :     $category = "E";
2176 :     if ($energy < $reactants->[$j]->{COEFFICIENT}->[0]) {
2177 :     $energy = floor($reactants->[$j]->{COEFFICIENT}->[0]);
2178 :     }
2179 :     }
2180 :     if (defined($compounds->{protein}->{$reactants->[$j]->{DATABASE}->[0]})) {
2181 :     $compounds->{protein}->{$reactants->[$j]->{DATABASE}->[0]} = $reactants->[$j]->{COEFFICIENT}->[0];
2182 :     $category = "P";
2183 :     } elsif (defined($compounds->{RNA}->{$reactants->[$j]->{DATABASE}->[0]})) {
2184 :     $compounds->{RNA}->{$reactants->[$j]->{DATABASE}->[0]} = $reactants->[$j]->{COEFFICIENT}->[0];
2185 :     $category = "R";
2186 :     } elsif (defined($compounds->{DNA}->{$reactants->[$j]->{DATABASE}->[0]})) {
2187 :     $compounds->{DNA}->{$reactants->[$j]->{DATABASE}->[0]} = $reactants->[$j]->{COEFFICIENT}->[0];
2188 :     $category = "D";
2189 :     }
2190 :     my $cpdbofMgr = $self->database()->get_object_manager("cpdbof");
2191 :     $cpdbofMgr->create({COMPOUND=>$reactants->[$j]->{DATABASE}->[0],BIOMASS=>$biomassID,coefficient=>-1*$reactants->[$j]->{COEFFICIENT}->[0],compartment=>$reactants->[$j]->{COMPARTMENT}->[0],category=>$category});
2192 :     }
2193 :     for (my $j=0; $j < @{$products}; $j++) {
2194 :     my $category = "U";
2195 :     if ($products->[$j]->{DATABASE}->[0] eq "cpd00008" || $products->[$j]->{DATABASE}->[0] eq "cpd00009" || $products->[$j]->{DATABASE}->[0] eq "cpd00067") {
2196 :     $category = "E";
2197 :     if ($energy < $products->[$j]->{COEFFICIENT}->[0]) {
2198 :     $energy = floor($products->[$j]->{COEFFICIENT}->[0]);
2199 :     }
2200 :     } elsif ($products->[$j]->{DATABASE}->[0] eq "cpd11416") {
2201 :     $category = "M";
2202 :     }
2203 :     my $cpdbofMgr = $self->database()->get_object_manager("cpdbof");
2204 :     $cpdbofMgr->create({COMPOUND=>$products->[$j]->{DATABASE}->[0],BIOMASS=>$biomassID,coefficient=>$products->[$j]->{COEFFICIENT}->[0],compartment=>$products->[$j]->{COMPARTMENT}->[0],category=>$category});
2205 :     }
2206 :     my $package = {lipid=>"NONE",cellWall=>"NONE",cofactor=>"NONE"};
2207 :     my $coef = {protein=>"NONE",DNA=>"NONE",RNA=>"NONE",lipid=>"NONE",cellWall=>"NONE",cofactor=>"NONE"};
2208 :     my $types = ["protein","DNA","RNA","lipid","cellWall","cofactor"];
2209 :     my $packages;
2210 :     my $packageHash;
2211 :     for (my $i=0; $i < @{$types}; $i++) {
2212 :     my @entities = sort(keys(%{$compounds->{$types->[$i]}}));
2213 :     if (@entities > 0 && $types->[$i] eq "lipid" && $types->[$i] eq "cellWall" && $types->[$i] eq "cofactor") {
2214 :     my $cpdgrpMgr = $self->get_object_manager("cpdgrp");
2215 :     my $cpdgrpObs = $cpdgrpMgr->get_objects({type=>$types->[$i]."Package"});
2216 :     for (my $j=0; $j < @{$cpdgrpObs}; $j++) {
2217 :     $packages->{$types->[$i]}->{$cpdgrpObs->[$j]->grouping()}->{$cpdgrpObs->[$j]->COMPOUND()} = 1;
2218 :     }
2219 :     my @packageList = keys(%{$packages->{$types->[$i]}});
2220 :     for (my $j=0; $j < @packageList; $j++) {
2221 :     $packageHash->{join("|",sort(keys(%{$packages->{$types->[$i]}->{$packageList[$j]}})))} = $packageList[$j];
2222 :     }
2223 :     if (defined($packageHash->{join("|",@entities)})) {
2224 :     $package->{$types->[$i]} = $packageHash->{join("|",@entities)};
2225 :     } else {
2226 :     my $newPackageID = $self->check_out_new_id($types->[$i]."Pkg");
2227 :     my @cpdList = keys(%{$compounds->{$types->[$i]}});
2228 :     for (my $j=0; $j < @cpdList; $j++) {
2229 :     $cpdgrpMgr = $self->get_object_manager("cpdgrp");
2230 :     $cpdgrpMgr->create({COMPOUND=>$cpdList[$j],grouping=>$newPackageID,type=>$types->[$i]."Package"});
2231 :     }
2232 :     }
2233 :     }
2234 :     for (my $j=0; $j < @entities; $j++) {
2235 :     if ($j > 0) {
2236 :     $coef->{$types->[$i]} .= "|";
2237 :     }
2238 :     $coef->{$types->[$i]} .= $compounds->{$types->[$i]}->{$entities[$j]};
2239 :     }
2240 :     }
2241 :     my $data = {owner=>"master",name=>$object->{NAME}->[0],users=>"all",equation=>$object->{EQUATION}->[0],modificationData=>time(),creationDate=>time(),id=>$biomassID,cofactorPackage=>$package->{cofactor},lipidPackage=>$package->{lipid},cellWallPackage=>$package->{cellWall},protein=>"0",DNA=>"0",RNA=>"0",lipid=>"0",cellWall=>"0",cofactor=>"0",proteinCoef=>$coef->{protein},DNACoef=>$coef->{DNA},RNACoef=>$coef->{RNA},lipidCoef=>$coef->{lipid},cellWallCoef=>$coef->{cellWall},cofactorCoef=>$coef->{cofactor},energy=>$energy};
2242 :     my $bofMgr = $self->database()->get_object_manager("bof");
2243 :     my $bofObj = $bofMgr->get_objects({id=>$biomassID});
2244 :     if (!defined($bofObj->[0])) {
2245 :     $bofMgr->create($data);
2246 :     } else {
2247 :     $bofObj->[0]->owner($data->{owner});
2248 :     $bofObj->[0]->name($data->{name});
2249 :     $bofObj->[0]->users($data->{users});
2250 :     $bofObj->[0]->equation($data->{equation});
2251 :     $bofObj->[0]->modificationData($data->{modificationData});
2252 :     $bofObj->[0]->creationDate($data->{creationDate});
2253 :     $bofObj->[0]->cofactorPackage($data->{cofactorPackage});
2254 :     $bofObj->[0]->lipidPackage($data->{lipidPackage});
2255 :     $bofObj->[0]->cellWallPackage($data->{cellWallPackage});
2256 :     $bofObj->[0]->protein($data->{protein});
2257 :     $bofObj->[0]->DNA($data->{DNA});
2258 :     $bofObj->[0]->RNA($data->{RNA});
2259 :     $bofObj->[0]->lipid($data->{lipid});
2260 :     $bofObj->[0]->cellWall($data->{cellWall});
2261 :     $bofObj->[0]->cofactor($data->{cofactor});
2262 :     $bofObj->[0]->proteinCoef($data->{proteinCoef});
2263 :     $bofObj->[0]->DNACoef($data->{DNACoef});
2264 :     $bofObj->[0]->RNACoef($data->{RNACoef});
2265 :     $bofObj->[0]->lipidCoef($data->{lipidCoef});
2266 :     $bofObj->[0]->cellWallCoef($data->{cellWallCoef});
2267 :     $bofObj->[0]->cofactorCoef($data->{cofactorCoef});
2268 :     $bofObj->[0]->energy($data->{energy});
2269 :     }
2270 :     }
2271 :    
2272 : chenry 1.1 1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3