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

View of /FigKernelScripts/compare_annotation_sets.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Apr 11 10:21:24 2014 UTC (5 years, 7 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Annotation comparison tool.

use strict;
use File::Basename;
use FIG;
use FIG_Config;

=head1 NAME

compare_annotation_sets

=head1 SYNOPSIS

  compare_annotation_sets S1 S2 ... > out.html

=head1 DESCRIPTION

Given sets S1, S2, ... of files of the form

    id <tab> annotation

generate a HTML file that has a table

    ID Reference-annotation Annotation-1 Annotation-2 ...

Lines are generated for each identifier where any of the annotations do not
match the reference.

=cut

my $fig = new FIG;

my @sets = @ARGV;

@sets > 0 or die "Usage: $0 S1 ...\n";

my %assignments;
my @names;
my $genome;

for my $set (@sets)
{
    my $name = basename($set);
    push(@names, $name);
    open(F, "<", $set) or die "Cannot open $set: $!";

    while (<F>)
    {
	chomp;
	my($id, $func) = split(/\t/);
	$assignments{$name}->{$id} = $func;
	$genome = FIG::genome_of($id) unless defined ($genome);
    }
    close(F);
}

my $features = $fig->all_features_detailed_fast($genome);

my $link_base = "$FIG_Config::cgi_url/linkin.cgi?fid=";
print <<END;
<style>
tr:hover {
      background-color: lightgray;
  }

</style>
END
    
print "<table>\n";
my $hdr =  "<tr><th>ID</th>";
for my $n ("SEED", @names)
{
    $hdr .= "<th>$n</th>";
}
$hdr .= "</tr>\n";

my $n = 0;

my @colors = ("lightblue", "lightgreen", "yellow");

for my $f (sort { FIG::by_fig_id($a->[0], $b->[0]) } grep { $_->[3] eq 'peg' } @$features)
{
    my($fid, $loc, $aliases, $type, $left, $right, $func) = @$f;
    my @tuple = ($func);
    # next if $func eq 'unknown protein';
    my %set;
    $set{$func} = 1;
    for my $n (@names)
    {
	my $f = $assignments{$n}->{$fid};
	push(@tuple, $f);
	$set{$f} = 1;
    }

    my $link = $link_base . $fid;

    my @funcs = keys %set;

    if (@funcs > 1)
    {
	my %c;
	my @ofuncs = grep { $_ ne $func } @funcs;
	$c{$func} = $colors[0];
	for my $i (0 .. $#ofuncs)
	{
	    $c{$ofuncs[$i]} = $colors[$i+1];
	}

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

	print "<tr><td><a target='_BLANK' href='$link'>$fid</a></td>";
	for my $ent (@tuple)
	{
	    my $c = $c{$ent};
	    if ($ent)
	    {
		print "<td bgcolor='$c'>$ent</td>";
	    }
	    else
	    {
		print "<td></td>";
	    }
	}
	print "<tr>\n";
    }

}
print "</table>\n";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3