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

View of /FigKernelPackages/UnvSubsys.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Mon Sep 12 02:39:37 2005 UTC (14 years, 5 months ago) by overbeek
Branch: MAIN
Changes since 1.1: +94 -5 lines
commit incomplete, bug ridden display_subsys.cgi

package UnvSubsys;

use Subsystem;
use Carp;
use FIG;

use Data::Dumper;
use strict;

sub new
{
    my($class, $ssa, $fig, $colors, $aliases) = @_;

    $ssa =~ s/ /_/g;


	### { Roles =>Roles,
        ###   RoleIndex => ToRoleIndexHash,
        ###   RoleSubsets => ColSubsets,
        ###   Genomes => Genomes,
        ###   GenomeIndex => ToGenomeIndexHash,
        ###   PegHash => PegHash,
        ###   Colors  => ColorHash,
        ###   Aliases => AliasHash,
        ###   Curator => Curator,
        ###   Notes => Notes,
        ###   Reactions => ReactionHash
        ### }
	### 
	### Roles = pointer to a list of [Role,Abbrev,[ReactionURLs]]
	###
	### ToRoleIndexHash = a pointer to a hash: key=Role Value=RoleIndex
	###
	### ColSubsets = pointer to a list of [SubsetName,[RoleIndexesFrom0]]
	### 
	### Genomes is a pointer to a list of [Genome,Variant]
	###
	### ToGenomeIndexHash = a pointer to a hash: key=Genome value=GenomeIndex
	###
	### PegHash = a pointer to a hash of hashes such that $peg_hash->{$genome_index}->{$role_index} = a
	###           pointer to a list of PEGs
	###
	### ColorHash is a hash: key=PEG value=color
	###
	### AliasHash is a hash: key=PEG value=aliases
	###
        ### ReactionHash is a hash: key=Role value=[reaction-ids]

    if (ref($fig) eq "FIG")
    {

	
	my $subsystem = new Subsystem($ssa,$fig,0);
	my $curator = $subsystem->get_curator;
	my $notes = $subsystem->get_notes;
	$notes =~ s/
/\n/g;
	my @roles = $subsystem->get_roles;
	my $reactions = $subsystem->get_reactions;
	my @genomes = $subsystem->get_genomes;
        my @col_subsets = $subsystem->get_subset_namesC;

	my $role_info = [];
	my $roleH     = {};

	my($i,$j,$subset,$peg);
	for ($i=0; ($i < @roles); $i++)
	{
	    my $role = $roles[$i];
	    my $abbrev = $subsystem->get_role_abbr( $subsystem->get_role_index( $role ) );
	    my $react = $reactions ? join(",", map { &HTML::reaction_link($_) } @{$reactions->{$role}}) : [];
	    push(@$role_info,[$role,$abbrev,$react]);
	    $roleH->{$role} = $i;
	}

	my $subset_info = [];
	foreach $subset (@col_subsets)
	{
	    if ($subset ne 'All')
	    {
		push(@$subset_info,[$subset,[map { $roleH->{$_} } $subsystem->get_subsetC_roles($subset)]]);
	    }
	}

	my $genomes_info = [];
	my $genomeH      = {};
	for ($i=0; ($i < @genomes); $i++)
	{
	    my $genome  = $genomes[$i];
	    my $variant = $subsystem->get_variant_code( $subsystem->get_genome_index( $genome ) );
	    push(@$genomes_info,[$genome,$variant]);
	    $genomeH->{$genome} = $i;
	}

	my $pegH = {};
	for ($i=0; ($i < @genomes); $i++)
	{
	    my $genome = $genomes[$i];
	    for ($j=0; ($j < @roles); $j++)
	    {
		my $role = $roles[$j];
		my @pegs = $subsystem->get_pegs_from_cell($genome,$role);
		$pegH->{$i}->{$j} = [@pegs];
	    }
	}
	
	my $colorsH  = $colors  ? &set_colors($fig,$pegH)  : {};
	my $aliasesH = $aliases ? &set_aliases($fig,$pegH) : {};
        my $reactions = $subsystem->get_reactions;	    
	my $self = { Roles => $role_info,
		     RoleIndex => $roleH,
		     RoleSubsets => $subset_info,
		     Genomes => $genomes_info,
		     GenomesIndex => $genomeH,
		     PegHash => $pegH,
		     Colors => $colorsH,
		     Aliases => $aliasesH,
	             Curator => $curator,
		     Notes => $notes,
		     Reactions => $reactions
		   };
	bless($self, $class);
	return $self;
    }
    else
    {
	return undef;
    }
}

sub subsystem_curator {
    my($self) = @_;

    my $curator = $self->{Curator};
    $curator =~ s/master://;
    return $curator;
}

sub get_roles {
    my($self) = @_;

    return map { $_->[0] } @{$self->{Roles}};
}

sub get_role_index {
    my($self,$role) = @_;

    return $self->{RoleIndex}->{$role};
}

sub get_role_abbr {
    my($self,$roleI) = @_;

    if ($roleI !~ /^\d+$/)
    {
	$roleI = $self->{RoleIndex}->{$roleI};
    }
    my $roles = $self->{Roles};
    return $roles->[$roleI]->[1];
}

sub get_reactions {
    my($self) = @_;

    return $self->{Reactions};
}

sub get_subset_namesC {
    my($self) = @_;

    return map { $_->[0] } @{$self->{RoleSubsets}};
}

sub get_subsetC_roles {
    my($self,$subset) = @_;
    my($i,$j);

    my $subset_info = $self->{RoleSubsets};
    for ($i=0; ($i < @$subset_info) && ($subset_info->[$i]->[0] ne $subset); $i++) {}
    if ($i < @$subset_info)
    {
	my @roles = ();
	foreach $j (@{$subset_info->[$i]->[1]})
	{
	    push(@roles,$self->{Roles}->[$j]->[0]);
	}
	return @roles;
    }
    return undef;
}

1;



MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3