<commit_before>#!/usr/bin/env perl
########################################################################
# Authors: <NAME>, <NAME>, <NAME>
# Contact email: <EMAIL>
# Development location: Mathematics and Computer Science Division, Argonne National Lab
########################################################################
use strict;
use warnings;
use Bio::KBase::workspaceService::Helpers qw(auth get_ws_client workspace workspaceURL parseObjectMeta parseWorkspaceMeta printObjectMeta);
use Bio::KBase::fbaModelServices::Helpers qw(get_fba_client runFBACommand universalFBAScriptCode );
#Defining globals describing behavior
my $primaryArgs = ["Media ID","Compound IDs (; delimiter)"];
my $servercommand = "addmedia";
my $script = "kbfba-addmedia";
my $translation = {
	"Media ID" => "media",
	name => "name",
	"Compound IDs (; delimiter)" => "compounds",
	concentrations => "concentrations",
	maxflux => "maxflux",
	minflux => "minflux",
	workspace => "workspace",
	"defined" => "isDefined",
	type => "type",
	minimal => "isMinimal",
	auth => "auth",
	overwrite => "overwrite",
};
my $arrayparams = {
	compounds => ";",
	concentrations => ";",
	maxflux => ";",
	minflux => ";",
};
#Defining usage and options
my $specs = [
    [ 'name:s', 'Media name' ],
    [ 'concentrations=s', 'Compound concentrations (; delimiter)' ],
    [ 'minflux=s', 'Compound minimum fluxes (; delimiter)' ],
    [ 'maxflux=s', 'Compound maximum fluxes (; delimiter)' ],
    [ 'type|t=s', 'Type of media', { "default" => "unspecified" } ],
    [ 'defined|d', 'Media is defined', { "default" => 0 } ],
    [ 'minimal|m', 'Media is minimal', { "default" => 0 } ],
    [ 'workspace|w:s', 'Workspace with model', { "default" => workspace() } ]
];
my ($opt,$params) = universalFBAScriptCode($specs,$script,$primaryArgs,$translation);
if (!defined($params->{name})) {
	$params->{name} = $params->{media};
}
$params->{compounds} = [split(/;/,$params->{compounds})];
if (defined($params->{concentrations})) {
	$params->{concentrations} = [split(/;/,$params->{concentrations})];
}
if (defined($params->{minflux})) {
	$params->{minflux} = [split(/;/,$params->{minflux})];
}
if (defined($params->{maxflux})) {
	$params->{maxflux} = [split(/;/,$params->{maxflux})];
}
#Calling the server
my $output = runFBACommand($params,$servercommand,$opt);
#Checking output and report results
if (!defined($output)) {
	print "Media creation failed!\n";
} else {
	print "Successfully added media to workspace:\n";
	printObjectMeta($output);
}<commit_msg>modifying kbfba-addmedia to read media formulations from an input file<commit_after>#!/usr/bin/perl
   
use strict;
use Data::Dumper;
use Bio::KBase::workspaceService::Helpers qw(auth get_ws_client workspace workspaceURL parseObjectMeta parseWorkspaceMeta printObjectMeta);
use Bio::KBase::fbaModelServices::Helpers qw(get_fba_client runFBACommand universalFBAScriptCode );
#Defining globals describing behavior
my $primaryArgs = ["Media ID"];
my $servercommand = "addmedia";
my $script = "kbfba-addmedia";
my $translation = {
    "Media ID" => "media",
    name => "name",
    compounds => "compounds",
    concentrations => "concentrations",
    maxflux => "maxflux",
    minflux => "minflux",
    workspace => "workspace",
    "defined" => "isDefined",
    type => "type",
    minimal => "isMinimal",
    auth => "auth",
    overwrite => "overwrite",
};

 
#Defining usage and options
my $specs = [
    [ 'input=s', 'Name of file with media information (format Mg 0.05 -100 100)' ],
    [ 'compounds=s', 'Compound list (; delimiter)' ],
    [ 'concentrations=s', 'Compound concentrations (; delimiter)' ],
    [ 'minflux=s', 'Compound minimum fluxes (; delimiter)' ],
    [ 'maxflux=s', 'Compound maximum fluxes (; delimiter)' ],
    [ 'name:s', 'Media name' ],
    [ 'type|t=s', 'Type of media', { "default" => "unspecified" } ],
    [ 'defined|d', 'Media is defined', { "default" => 0 } ],
    [ 'minimal|m', 'Media is minimal', { "default" => 0 } ],
    [ 'workspace|w:s', 'Workspace with model', { "default" => workspace() } ]
];

my ($opt,$params) = universalFBAScriptCode($specs,$script,$primaryArgs,$translation);

my @media_Array;

    my @compounds;
    my @concentrations;
    my @minflux;
    my @maxflux;


my $in_fh;
if ($opt->{input}) {
    open($in_fh, "<", $opt->{input}) or die "Cannot open input file";
} 

        while (defined($_ = <$in_fh>)){
        
            chop;
            my($m_id, $conc,$minf,$maxf) = split(/\s+/,$_);
        
                push (@compounds, $m_id);
                push (@concentrations, $conc);
                push (@minflux, $minf);
                push (@maxflux, $maxf);              

        }


if (!defined($params->{name})) {
    $params->{name} = $params->{media};
}

if (defined($params->{compounds})) {
    $params->{compounds} = [split(/;/,$params->{compounds})];
}
else {
    $params->{compounds} = \@compounds;

}

if (defined($params->{concentrations})) {
    $params->{concentrations} = [split(/;/,$params->{concentrations})];
}
else{
    $params->{concentrations} = \@concentrations;

}

if (defined($params->{minflux})) {
    $params->{minflux} = [split(/;/,$params->{minflux})];
}

else{
    $params->{minflux} = \@minflux;

}
if (defined($params->{maxflux})) {
    $params->{maxflux} = [split(/;/,$params->{maxflux})];
}

else{
    $params->{maxflux} = \@maxflux;


}



#Calling the server
my $output = runFBACommand($params,$servercommand,$opt);

#Checking output and report results
if (!defined($output) ) {
    print "Media creation failed!\n";
}
elsif (!defined($params->{compounds}->[0])) {

    print "Media creation failed, compounds not found or did not used the --compounds flag!\n";

}

 else {
    print "Successfully added media to workspace:\n";
    printObjectMeta($output);
}
 
{'fraction_non_alphanumeric': 0.21603871413757345, 'fraction_numerical': 0.0024196335983408227, 'mean_word_length': 4.348428835489834, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855428', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1877, 'n_words': 431}