[Bio] / FigKernelScripts / annotate-ss-with-pattyfams.pl Repository:
ViewVC logotype

View of /FigKernelScripts/annotate-ss-with-pattyfams.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Wed Nov 18 18:20:02 2015 UTC (3 years, 11 months ago) by olson
Branch: MAIN
CVS Tags: HEAD
New scripts.

use FIG;
use strict;
use Data::Dumper;
use WebColors;

#my $ss_name = "Possible_regulatory_cluster_of_globally_occuring_genes";
my $ss_name = "CBSS-1313.3.peg.391";

my $kmer_dir = "/disks/ssd/kmers/core.2015-0818/Data.2";
my $url = "http://spruce:6100";

my $fig = FIG->new;
my $ss = $fig->get_subsystem($ss_name);

my $fa_file = "$ss_name.fa";
open(T, ">", $fa_file) or die "cannot write $fa_file: $!";

for my $row ($ss->get_sorted_rows('by_phylo'))
{
    my($genome, $name, $variant, $cells) = @$row;
    next if $variant eq -1;

    for my $cell (@$cells)
    {
	for my $ent (@$cell)
	{
	    my $peg = "fig|$genome.peg.$ent";
	    my $trans = $fig->get_translation($peg);

	    print T ">$peg\n$trans\n";
	}
    }
}
close(T);

my $palette = WebColors::get_palette('many');

my $next_col = 0;

my(%fam, %fun, %color );
open(P, "-|", "perl", "FigKernelScripts/place_proteins_into_localfam.pl", $kmer_dir, $url, $fa_file);
while (<P>)
{
    chomp;
    my($fid, $fam, $fun) = split(/\t/);
    $fam =~ s/PGF_//;
    $fam{$fid} = $fam;
    $fun{$fid} = $fun;

    if (!exists $color{$fam})
    {
	$color{$fam} = to_color($palette->[$next_col]);
	
	$next_col = ($next_col + 1) % @$palette;
    }
}
close(P);
# print STDERR Dumper(\%color);

sub to_color
{
    my($triple) = @_;
    return "#" . join("", map { sprintf("%02x", $_) } @$triple);
}

print "<table border='1'>\n";

my $hdr = "<tr><th>gid</th><th>genome</th><th>var</th>";
for my $abbr ($ss->get_abbrs())
{
    $hdr .=  "<th>$abbr</th>";
}
$hdr .= "</tr>\n";

my $n = 0;

for my $row ($ss->get_sorted_rows('by_phylo'))
{
    my($genome, $name, $variant, $cells) = @$row;
    next if $variant eq -1;

    if ($n % 20 == 0)
    {
	print $hdr;
    }
    $n++;

    print "<tr><td>$genome</td><td>$name</td><td>$variant</td>\n";
    
    for my $cell (@$cells)
    {
	
	my $cpeg;
	my $cfam;
	my $color;
	my $no_color;
	my @pegs;
	my @guts = map {
	    my $peg = "fig|$genome.peg.$_";
	    push(@pegs, $peg);
	    my $fam = $fam{$peg};
	    my $ret = '';
	    if ($fam)
	    {
		my $this_color = $color{$fam};
		if (defined($color) && $this_color ne $color)
		{
		    $no_color = 1;
		    # print STDERR "Setting no_color due to clash for $cpeg $cfam $color $peg $this_color $color{$fam{$peg}} $fam{$peg}\n";
		}
		else
		{
		    $cpeg = $peg;
		    $cfam = $fam{$cpeg};
		    $color = $this_color;
		    # print STDERR  "set color to $this_color for $peg $fam{$peg}\n";
		}
		$ret = "<a href='http://core.theseed.org/FIG/seedviewer.cgi?page=Annotation&feature=$peg'>$fam{$peg}</a>";
	    }
	    else
	    {
		$no_color = 1;
		$ret = "<a href='http://core.theseed.org/FIG/seedviewer.cgi?page=Annotation&feature=$peg'>nofam</a>";
	    }
	    $ret;
	} grep { $_ ne '' } @$cell;
	if (@pegs > 1)
	{
	    my $s = join("&", map { "feature=$_" } @pegs);
	    my $n = @pegs;
	    push(@guts, "<a href='http://pseed.theseed.org/seedviewer.cgi?page=Regions&$s'>$n pegs</a>");
	}
	my $guts = join("<br>", @guts);
	print "<td";
	if ($guts && $color && !$no_color)
	{
	    print " bgcolor='$color'";
	}
	print ">$guts</td>\n";
    }

    print "<tr>\n";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3