Skip to content

Commit f2bc6d2

Browse files
committed
Fixing media printing and loading. Enabling setting of model-specific exchange fluxes.
1 parent fe74035 commit f2bc6d2

File tree

9 files changed

+340
-78
lines changed

9 files changed

+340
-78
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ logs/*
2121
*.pdb
2222
software/mfatoolkit/bin/*
2323
software/cygwin/*
24+
software/MinGW/*
25+
software/git/*
26+
software/oldMinGW/*
27+
software/PortableApps/*
28+
software/strawberryperl/*
2429
workspace/*
2530
!.gitignore
2631
blib*

lib/ModelSEED/FIGMODEL/FIGMODELfba.pm

+4-2
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,11 @@ Description:
659659
sub setDrainRxnParameters {
660660
my ($self,$args) = @_;
661661
$args = $self->figmodel()->process_arguments($args,[],{});
662-
return $self->error_message({function => "setDrainRxnParameters",args=>$args}) if (defined($args->{error}));
662+
my $exchange = "cpd11416[c]:-10000:0;cpd15302[c]:-10000:10000;cpd08636[c]:-10000:0";
663+
if (defined($self->model()) && defined($self->modelObj())) {
664+
$exchange = $self->modelObj()->drains();
665+
}
663666
if (defined($self->{_drnRxn}) && @{$self->{_drnRxn}} > 0) {
664-
my $exchange = "cpd11416[c]:-10000:0;cpd15302[c]:-10000:10000;cpd08636[c]:-10000:0";
665667
if (defined($self->parameters()->{"exchange species"})) {
666668
$exchange = $self->parameters()->{"exchange species"};
667669
}

lib/ModelSEED/FIGMODEL/FIGMODELmodel.pm

+60
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,66 @@ sub setCache {
312312
return $self->figmodel()->setCache({package=>"FIGMODELmodel",id=>$self->id(),key=>$key,data=>$data});
313313
}
314314

315+
=head3 drains
316+
Definition:
317+
FIGMODELmodel->drains();
318+
Description:
319+
Get the drain fluxes associated with the model.
320+
=cut
321+
sub drains {
322+
my ($self) = @_;
323+
$args = ModelSEED::globals::ARGS($args,[],{});
324+
my $drainString = "cpd11416[c]:-10000:0;cpd15302[c]:-10000:10000;cpd08636[c]:-10000:0";
325+
if (-e $self->figmodel()->config('model directory')->[0].$self->owner()."/".$self->id()."/drains.txt") {
326+
my $data = ModelSEED::globals::LOADFILE($self->figmodel()->config('model directory')->[0].$self->owner()."/".$self->id()."/drains.txt");
327+
$drainString = $data->[0];
328+
}
329+
return $drainString;
330+
}
331+
332+
=head3 changeDrains
333+
Definition:
334+
FIGMODELmodel->changeDrains();
335+
Description:
336+
Changes the drain fluxes associated with the model.
337+
=cut
338+
sub changeDrains {
339+
my ($self) = @_;
340+
$args = ModelSEED::globals::ARGS($args,[],{
341+
inputs => undef,
342+
drains => undef
343+
});
344+
if (-e $self->figmodel()->config('model directory')->[0].$self->owner()."/".$self->id()."/drains.txt") {
345+
unlink($self->figmodel()->config('model directory')->[0].$self->owner()."/".$self->id()."/drains.txt");
346+
}
347+
my $drnHash = {};
348+
if (defined($args->{inputs})) {
349+
for (my $i=0; $i <@{$args->{inputs}}; $i++) {
350+
if ($args->{inputs}->[$i] !~ m/\[\w+\]$/) {
351+
$args->{inputs}->[$i] .= "[c]";
352+
}
353+
$drnHash->{$args->{inputs}->[$i]}->{max} = 10000;
354+
$drnHash->{$args->{inputs}->[$i]}->{min} = 0;
355+
}
356+
}
357+
if (defined($args->{drains})) {
358+
for (my $i=0; $i <@{$args->{drains}}; $i++) {
359+
if (!defined($drnHash->{$args->{drains}->[$i]}->{max})) {
360+
$drnHash->{$args->{drains}->[$i]}->{max} = 0;
361+
}
362+
$drnHash->{$args->{drains}->[$i]}->{min} = -10000;
363+
}
364+
}
365+
my $drainString = "cpd11416[c]:-10000:0;cpd15302[c]:-10000:10000;cpd08636[c]:-10000:0";
366+
foreach my $drn (keys(%{$drnHash})) {
367+
$drainString .= ";".$drn.":".$drnHash->{$drn}->{min}.":".$drnHash->{$drn}->{max};
368+
}
369+
if ($drainString ne "cpd11416[c]:-10000:0;cpd15302[c]:-10000:10000;cpd08636[c]:-10000:0") {
370+
ModelSEED::globals::PRINTFILE($self->figmodel()->config('model directory')->[0].$self->owner()."/".$self->id()."/drains.txt",[$drainString]);
371+
}
372+
return $drainString;
373+
}
374+
315375
=head3 aquireModelLock
316376
Definition:
317377
FIGMODELmodel->aquireModelLock();

lib/ModelSEED/ModelDriver.pm

+69-47
Original file line numberDiff line numberDiff line change
@@ -5845,7 +5845,7 @@ sub bcprintmedia {
58455845
["media",1,undef,"Name of the media formulation to be printed."],
58465846
],[@Data],"print Model SEED media formulation");
58475847
my $media = $self->figmodel()->database()->get_moose_object("media",{id => $args->{media}});
5848-
ModelSEED::globals::PRINTOBJECT({data => $media->pack(),filename => $self->ws()->directory().$args->{media}.".media"});
5848+
ModelSEED::globals::PRINTFILE($self->ws()->directory().$args->{media}.".media",$media->print());
58495849
return "Successfully printed media '".$args->{media}."' to file '". $self->ws()->directory().$args->{media}.".media'!";
58505850
}
58515851

@@ -5860,31 +5860,18 @@ This function is used to create or alter a media condition in the Model SEED dat
58605860
sub bcloadmedia {
58615861
my($self,@Data) = @_;
58625862
my $args = $self->check([
5863-
["name",1,undef,"The name of the media formulation being created or altered."],
5864-
["filename",0,undef,"The full path and name to access a file specifying the media components. [[Example media file]]."],
5865-
["compounds",0,undef," As an alternative to specifying a filename, you can specify a ';' delimited list of the compound proposed to be present in the media. Either compound names or cpd##### ids must be supplied."],
5866-
["public",0,1,"Set directory in which FBA problem output files will be stored."],
5863+
["media",1,undef,"The name of the media formulation being created or altered."],
5864+
["public",0,0,"Set directory in which FBA problem output files will be stored."],
58675865
["owner",0,($self->figmodel()->user()),"Login of the user account who will own this media condition."],
58685866
["overwrite",0,0,"If you set this parameter to '1', any existing media with the same input name will be overwritten."]
58695867
],[@Data],"Creates (or alters) a media condition in the Model SEED database");
5870-
if (defined($args->{compounds})) {
5871-
$args->{compounds} = $self->figmodel()->processIDList({
5872-
objectType => "compound",
5873-
delimiter => ";",
5874-
column => "id",
5875-
parameters => undef,
5876-
input => $args->{compounds}
5877-
});
5878-
}
5879-
my $media = $self->figmodel()->get_media()->create({
5880-
id => $args->{name},
5881-
filename => $args->{filename},
5882-
compounds => $args->{compounds},
5883-
public => $args->{public},
5884-
owner => $args->{owner},
5885-
overwrite => $args->{overwrite}
5886-
});
5887-
print "Media successfully created!\n";
5868+
my $media;
5869+
if (!-e $self->ws()->directory().$args->{media}) {
5870+
ModelSEED::globals::ERROR("Could not find media file ".$self->ws()->directory().$args->{media});
5871+
}
5872+
$media = ModelSEED::MooseDB::media->new({db => $self->figmodel()->database(),filedata => ModelSEED::globals::LOADFILE($self->ws()->directory().$args->{media})});
5873+
$media->syncWithPPODB({overwrite => $args->{overwrite}});
5874+
return "Successfully loaded media ".$args->{media}." to database as ".$media->id();
58885875
}
58895876

58905877
=head
@@ -6135,37 +6122,38 @@ Prints the specified model(s) in SBML format.
61356122
sub mdlprintsbml {
61366123
my($self,@Data) = @_;
61376124
my $args = $self->check([
6138-
["model",1,undef,"A ',' delimited list of the models in the Model SEED for which SBML files should be printed."],
6125+
["model",1,undef,"Model for which SBML files should be printed."],
6126+
["media",0,"Complete","ID of a media condition or media file for which SBML should be printed"],
61396127
],[@Data],"prints model(s) in SBML format");
6140-
my $results = $self->figmodel()->processIDList({
6128+
my $models = $self->figmodel()->processIDList({
61416129
objectType => "model",
6142-
delimiter => ",",
6130+
delimiter => ";",
61436131
column => "id",
61446132
parameters => {},
61456133
input => $args->{"model"}
61466134
});
6147-
my $message;
6148-
if (@{$results} == 1 || $args->{usequeue} == 0) {
6149-
for (my $i=0;$i < @{$results}; $i++) {
6150-
print "Now processing ".$results->[$i]."\n";
6151-
my $mdl = $self->figmodel()->get_model($results->[$i]);
6152-
if (!defined($mdl)) {
6153-
ModelSEED::globals::WARNING("Model not valid ".$args->{model});
6154-
$message .= "SBML printing failed for model ".$results->[$i].". Model not valid!\n";
6155-
} else {
6156-
my $sbml = $mdl->PrintSBMLFile();
6157-
$self->db()->print_array_to_file($self->ws()->directory().$results->[$i].".xml",$sbml);
6158-
$message .= "SBML printing succeeded for model ".$results->[$i]."!\nFile printed to ".$self->ws()->directory().$results->[$i].".xml"."!";
6159-
}
6160-
}
6161-
} else {
6162-
for (my $i=0; $i < @{$results}; $i++) {
6163-
$self->figmodel()->mdlprintsbml({
6164-
command => "mdlprintsbml?".$results->[$i],
6165-
user => $self->figmodel()->user().":".$self->ws()->id().":".$self->ws()->path(),
6166-
queue => $args->{queue}
6167-
});
6135+
if ($args->{media} =~ m/\.media$/) {
6136+
if (!-e $self->ws()->directory().$args->{media}) {
6137+
ModelSEED::globals::ERROR("Media file ".$self->ws()->directory().$args->{media}." not found");
61686138
}
6139+
$args->{media} = ModelSEED::MooseDB::media->new({
6140+
filename => $args->{media}
6141+
});
6142+
}
6143+
my $message;
6144+
for (my $i=0; $i < @{$models};$i++) {
6145+
print "Now loading model ".$results->[$i]."\n";
6146+
my $mdl = $self->figmodel()->get_model($results->[$i]);
6147+
if (!defined($mdl)) {
6148+
ModelSEED::globals::WARNING("Model not valid ".$args->{model});
6149+
$message .= "SBML printing failed for model ".$results->[$i].". Model not valid!\n";
6150+
next;
6151+
}
6152+
my $sbml = $mdl->PrintSBMLFile({
6153+
media => $args->{media}
6154+
});
6155+
ModelSEED::globals::PRINTFILE($self->ws()->directory().$results->[$i].".xml",$sbml);
6156+
$message .= "SBML printing succeeded for model ".$results->[$i]."!\nFile printed to ".$self->ws()->directory().$results->[$i].".xml"."!";
61696157
}
61706158
return $message;
61716159
}
@@ -6344,6 +6332,40 @@ sub mdlloadmodel {
63446332
print "Successfully imported ".$args->{"name"}." into Model SEED as ".$modelObj->id()."!\n\n";
63456333
}
63466334

6335+
=head
6336+
=CATEGORY
6337+
Metabolic Model Operations
6338+
=DESCRIPTION
6339+
This function changes the drain fluxes associated with a model.
6340+
=EXAMPLE
6341+
./mdlchangedrains -'''model''' "iJR904" -'''drains''' "cpd15302[c]" -'''inputs''' "cpd15302[c]"
6342+
=cut
6343+
sub mdlchangedrains {
6344+
my($self,@Data) = @_;
6345+
my $args = $self->check([
6346+
["model",1,undef,"ID of the model the drains are to be added to"],
6347+
["drains",0,undef,"\";\" delimited list of compounds for which drains should be added"],
6348+
["inputs",0,undef,"\";\" delimited list of compounds for which inputs should be added"],
6349+
],[@Data],"change drain fluxes associated with model");
6350+
$args->{drains} = ModelSEED::globals::PROCESSIDLIST({
6351+
input => $args->{drains},
6352+
validation => "^cpd\\d+\\[*\\w*\\]*$"
6353+
});
6354+
$args->{inputs} = ModelSEED::globals::PROCESSIDLIST({
6355+
input => $args->{inputs},
6356+
validation => "^cpd\\d+\\[*\\w*\\]*$"
6357+
});
6358+
my $model = $self->figmodel()->get_model($args->{model});
6359+
if (!defined($model)) {
6360+
ModelSEED::globals::ERROR("Model not valid ".$args->{model});
6361+
}
6362+
my $string = $model->changeDrains({
6363+
drains => $args->{drains},
6364+
inputs => $args->{inputs},
6365+
})
6366+
return "Successfully adjusted the drain fluxes associated with model ".$args->{model}." to ".$string;
6367+
}
6368+
63476369
=head
63486370
=CATEGORY
63496371
Metabolic Model Operations

lib/ModelSEED/ModelSEEDScripts/ms-config.pl

+24-21
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@
5151
}
5252
}
5353
my ($Config,$extension,$arguments,$delim,$os,$configFile);
54+
#Setting operating system related parameters
55+
{
56+
$extension = "";
57+
$arguments = "\$*";
58+
$delim = ":";
59+
$os = 'linux';
60+
# figure out OS from $^O variable for extension, arguments and delim:
61+
if($^O =~ /cygwin/ || $^O =~ /MSWin32/) {
62+
$os = 'windows';
63+
} elsif($^O =~ /darwin/) {
64+
$os = 'osx';
65+
}
66+
}
5467
#Identifying and parsing the conf file
5568
{
5669
# By default use config/Settings.config
@@ -83,14 +96,16 @@
8396
$Config->{Database}->{filename} =
8497
$Config->{Optional}->{dataDirectory} . "/ModelDB/ModelDB.db";
8598
}
86-
my $glpksol = `which glpsol`;
87-
chomp $glpksol;
88-
$glpksol =~ s/\/bin\/glpsol//;
89-
if(!defined($Config->{Optimizers}->{includeDirectoryGLPK}) && defined($glpksol)) {
90-
$Config->{Optimizers}->{includeDirectoryGLPK} = "$glpksol/include/";
91-
}
92-
if(!defined($Config->{Optimizers}->{libraryDirectoryGLPK}) && defined($glpksol)) {
93-
$Config->{Optimizers}->{libraryDirectoryGLPK} = "$glpksol/lib/";
99+
if ($os ne "windows") {
100+
my $glpksol = `which glpsol`;
101+
chomp $glpksol;
102+
$glpksol =~ s/\/bin\/glpsol//;
103+
if(!defined($Config->{Optimizers}->{includeDirectoryGLPK}) && defined($glpksol)) {
104+
$Config->{Optimizers}->{includeDirectoryGLPK} = "$glpksol/include/";
105+
}
106+
if(!defined($Config->{Optimizers}->{libraryDirectoryGLPK}) && defined($glpksol)) {
107+
$Config->{Optimizers}->{libraryDirectoryGLPK} = "$glpksol/lib/";
108+
}
94109
}
95110
if(lc($Config->{Database}->{type}) eq 'mysql' &&
96111
!defined($Config->{Database}->{port})) {
@@ -107,19 +122,6 @@
107122
}
108123
}
109124
}
110-
#Setting operating system related parameters
111-
{
112-
$extension = "";
113-
$arguments = "\$*";
114-
$delim = ":";
115-
$os = 'linux';
116-
# figure out OS from $^O variable for extension, arguments and delim:
117-
if($^O =~ /cygwin/ || $^O =~ /MSWin32/) {
118-
$os = 'windows';
119-
} elsif($^O =~ /darwin/) {
120-
$os = 'osx';
121-
}
122-
}
123125
#Creating config/FIGMODELConfig.txt
124126
{
125127
my $data = loadFile($directoryRoot."/lib/ModelSEED/FIGMODELConfig.txt");
@@ -346,6 +348,7 @@ sub run {
346348
my $script = <<SCRIPT;
347349
perl -e "use lib '$directoryRoot/config/';" -e "use ModelSEEDbootstrap;" -e "run();" "$directoryRoot/lib/ModelSEED/ModelDriver.pl" "$function" $arguments
348350
SCRIPT
351+
print $directoryRoot."/bin/".$function.$extension."\n";
349352
open(my $fh, ">", $directoryRoot."/bin/".$function.$extension) || die($!);
350353
print $fh $script;
351354
close($fh);

0 commit comments

Comments
 (0)