[Bio] / FigKernelScripts / update_hope_info.pl Repository:
ViewVC logotype

View of /FigKernelScripts/update_hope_info.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Wed Jan 27 19:56:35 2010 UTC (9 years, 9 months ago) by dejongh
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.3: +3 -0 lines
added comments

# script to copy updated hope_supersets.txt and/or hope files for Subsystems
# re-run Scenarios for 'All' and for specified genomes
# The copy_dir should contain hope_supersets.txt and a subdirectory named Subsystems,
# which should contain a subdirectory for each Subsystem containing the hope files 
# (hope_reactions, hope_kegg_info, other supporting files)

use strict;
use FIG;
use Subsystem;
use model;
use File::Spec;
use File::Copy;

my $fig = new FIG;
&model::set_fig($fig);

# directory with updated hope info
my $copy_dir;
# flag - re-run all scenarios or just run updated scenarios?
my $all_scenarios = 0;
my $updated_scenarios = 0;
# flag - re-run Scenarios for all Bacteria and Archaea?
my $all_genomes = 0;

while ((@ARGV > 0) && ($ARGV[0] =~ /^-/))
{
    my $arg = shift @ARGV;
    if ($arg =~ /^-d/)
    {
	$copy_dir = shift @ARGV;
    }
    elsif ($arg =~ /^-all_genomes/)
    {
	$all_genomes = 1;
    }
    elsif ($arg =~ /^-all_scenarios/)
    {
	$all_scenarios = 1;
    }
    elsif ($arg =~ /^-updated_scenarios/)
    {
	$updated_scenarios = 1;
    }
    else
    {
	die "Unknown option $arg\n";
    }
}

my @genomes = @ARGV;

if ($all_genomes)
{
    push @genomes, $fig->genomes(1, 0, 'Bacteria');
    push @genomes, $fig->genomes(1, 0, 'Archaea');
}

if (! defined $copy_dir)
{
    print "usage: update_hope_info -d <directory with hope info> [-all_scenarios|-updated_scenarios] [-all_genomes|<list of genome ids>]\n";
    exit(-1);
}

if (! -e $copy_dir)
{
    die "$copy_dir does not exist\n";
}

my $hope_ss_file = File::Spec->catfile($copy_dir, "hope_supersets.txt");
if (-e $hope_ss_file)
{
    copy($hope_ss_file, "$FIG_Config::global/Models/hope_supersets.txt") or die("Couldn't copy hope_supersets.txt");
}

my @subsystems;

my $hope_dir = File::Spec->catfile($copy_dir, 'Subsystems');
if (-e $hope_dir)
{
    opendir (SSA, $hope_dir);
    foreach my $subdir (grep { $_ !~ /^\./ } readdir(SSA))
    {
	push @subsystems, $subdir;
    }
    close (SSA);
}

foreach my $ss (sort @subsystems)
{
    my $sub = $fig->get_subsystem($ss);

    if (! defined($sub))
    {
	print "$ss no longer exists\n";
	next;
    }

    print "Updating hope info for $ss\n";  
    copy_hope_info($sub);
}

# create a new FIG object so we don't have to worry about cached out-of-date subsystems
$fig = new FIG;
&model::set_fig($fig);

if ($all_scenarios)
{
    &run_all_scenarios;
}
elsif ($updated_scenarios)
{
    &run_updated_scenarios;
}

sub copy_hope_info
{
    my ($sub) = @_;

    my $dir = $sub->get_dir;
    my $ss_name = $sub->{name};
    $ss_name =~ s/ /_/g;
    my $hope_dir = File::Spec->catfile($copy_dir, 'Subsystems', $ss_name);
    die ("$hope_dir does not exist") if (! -e $hope_dir);
    
    # do we need to adjust read/write permissions?
    copy("$hope_dir/hope_curation_notes", "$dir/hope_curation_notes") or die("Couldn't copy $hope_dir/hope_curation_notes");
    copy("$hope_dir/hope_kegg_info", "$dir/hope_kegg_info") or die("Couldn't copy $hope_dir/hope_curation_notes");
    copy("$hope_dir/hope_reaction_links", "$dir/hope_reaction_links") or die("Couldn't copy $hope_dir/hope_curation_notes");
    copy("$hope_dir/hope_reaction_notes", "$dir/hope_reaction_notes") or die("Couldn't copy $hope_dir/hope_curation_notes");
    copy("$hope_dir/hope_reactions", "$dir/hope_reactions") or die("Couldn't copy $hope_dir/hope_curation_notes");

    $sub->incr_version();
}

# just run the scenarios that have been updated
sub run_updated_scenarios
{
    my $ss_to_superset = &model::load_superset_file;

    foreach my $ss_name (sort @subsystems)
    {
	my $group = $ss_to_superset->{$ss_name};

	if ($group eq '') 
	{
	    print "No superset defined for $ss_name; skipping ...\n";
	    next;
	}

	my $subsystem = $fig->get_subsystem($ss_name);
	next if ! defined $subsystem;
	my @ss_scenarios = $subsystem->get_hope_scenario_names;

	print "Running scenarios for 'All' in $ss_name\n";
	foreach my $name (@ss_scenarios)
	{
	    &model::run_scenario('All',$group,$ss_name,$name);
	}
    }

    &model::analyze_scenario_connections('All');    

    foreach my $genome (@genomes)
    {
	print "Updating scenarios for $genome\n";

	foreach my $ss_name (sort @subsystems)
	{
	    my $group = $ss_to_superset->{$ss_name};

	    if ($group eq '') 
	    {
		print "No superset defined for $ss_name; skipping ...\n";
		next;
	    }

	    my $subsystem = $fig->get_subsystem($ss_name);
	    next if ! defined $subsystem;
	    my @ss_scenarios = $subsystem->get_hope_scenario_names;

	    foreach my $name (@ss_scenarios)
	    {
		&model::run_scenario($genome,$group,$ss_name,$name);
		&model::compare_scenario($genome,$group,$ss_name,$name);
	    }
	}

	&model::analyze_scenario_connections($genome);    
    }
}

sub run_all_scenarios
{
    &model::run_supersets('All');
    &model::analyze_scenario_connections('All');    

    foreach my $genome (@genomes)
    {
	&model::run_supersets($genome);
	&model::compare_supersets($genome);
	&model::analyze_scenario_connections($genome);    
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3