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

View of /FigKernelScripts/pg_make_reaction_tables.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Mar 1 19:38:45 2013 UTC (6 years, 8 months ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
extract reaction table

use strict;
use Data::Dumper;
use Getopt::Long;
use SeedEnv;
use JSON::XS;

my $usage = "usage: pg_reaction_tables -d Data\n";
my $dataD;
my $rc  = GetOptions('d=s' => \$dataD,);

if ((! $rc) || (! -d $dataD)) { print STDERR $usage; exit }

opendir(MODELS,"$dataD/Models") || die "could not open $dataD/Models";
my @models = grep { $_ !~ /^\./ } readdir(MODELS);
closedir(MODELS);

open(REACT,"| sort > $dataD/reaction_genome_peg.table") || die "could not open $dataD/reaction_genome_peg.table";
foreach $_ (`cat $dataD/MODEL-ID`)
{
    if ($_ =~ /^(\S+)\t(\S+)/)
    {
	my($genome,$model) = ($1,$2);
	open(MODEL,"<$dataD/Models/$model.json") || die "could not open $dataD/Models/$model.json";
	my $json = JSON::XS->new;
	my $model;
	{
	    local $/;
	    undef $/;
	    my $txt = <MODEL>;
	    $model = $json->decode($txt);
	}
	close(MODEL);
	my $reactions = $model->[0]->{reactions};
	foreach my $reaction (@$reactions)
	{
	    my $def   = $reaction->{definition};
	    my @pegs  = @{$reaction->{features}};
	    my $pegs = (@pegs > 0) ? join(",",@pegs) : '';
	    print REACT "$def\t$genome\t$pegs\n";
	}
   }
}
close(REACT);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3