[Bio] / FigWebServices / ss_directed_compare_regions.cgi Repository:
ViewVC logotype

View of /FigWebServices/ss_directed_compare_regions.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (annotate)
Tue Feb 10 19:59:29 2015 UTC (4 years, 9 months ago) by olson
Branch: MAIN
Changes since 1.2: +14 -30 lines
Bob fixes

# -*- perl -*-
#
# Copyright (c) 2003-2008 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
#
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


use strict;
use Data::Dumper;

use FIG;
use FIG_CGI;

use URI::Escape;  # uri_escape
use HTML;
my $fig = new FIG;
use CGI;
my $cgi = new CGI;

if (0)
{
    print $cgi->header;
    my @params = $cgi->param;
    print "<pre>\n";
    foreach $_ (@params)
    {
	print "$_\t:",join(",",$cgi->param($_)),":\n";
    }
    exit;
}

my $subsys = "$FIG_Config::data/Subsystems"; 
#my $subsys = "/vol/core-seed/FIGdisk/FIG/Data/Subsystems";

my $html = [];
unshift @$html, "<TITLE>Subsystem-based compare-regions</TITLE>\n";
my $ss = $cgi->param('ss');
my $abbr = $cgi->param('abbr');

if ((! $ss) || (! $abbr))
{   
    push(@$html,"<h1> ERROR: You need to use ss= and abbr= parameters</h1>");
    &HTML::show_page($cgi,$html);
    exit;
}
if (! -s "$subsys/$ss/spreadsheet")
{
    push(@$html,"<h1> ERROR: No such subsystemp in coreSEED ($subsys)</h1>");
    &HTML::show_page($cgi,$html);
    exit;
}
my @pegs = &pegs_in_spreadsheet("$subsys/$ss",$abbr,$fig);

if (@pegs == 0)
{
    push(@$html,"<h1> ERROR: No pegs in $abbr of $subsys</h1>");
    &HTML::show_page($cgi,$html);
    exit;
}

my $number_pegs = $cgi->param('n');
if (! $number_pegs) { $number_pegs = 10 }
while (@pegs > 0)
{
    my $sz = (@pegs > $number_pegs) ? $number_pegs : @pegs;
    my @batch = splice(@pegs,0,$sz);
    my @bpegs = map { $_->[0] } @batch;
    my $start_href = &link(\@bpegs);
    my $start_link = "<a target=_blank href=$start_href>$batch[0]->[0] $batch[0]->[2]</a><br>\n";
    push(@$html,"<br><br>",$start_link,"<br>\n");

    push(@$html, "<a target=_blank href='$FIG_Config::cgi_url/seedviewer.cgi?feature=$_->[0]'>$_->[0]</a><br>\n") foreach @batch;

}

&HTML::show_page($cgi,$html);

sub link {
    my($pegs) = @_;

    my $features = join('&feature=',@$pegs);
    return "$FIG_Config::cgi_url/seedviewer.cgi?page=Regions&feature=" . $features;
    #return "http://core.theseed.org/FIG/seedviewer.cgi?page=Regions&feature=" . $features;
}

sub pegs_in_spreadsheet {
    my($ssF,$abbr,$fig) = @_;

    my $spreadsheet = join("",`cat $ssF/spreadsheet`);
    my($hdrs,undef,$genomes) = split(/\n\/\/\n/,$spreadsheet);
    my @hdrs = map { ($_ =~ /^(\S+)/) ? $1 : () } split(/\n/,$hdrs);
    my $i;
    for ($i=0; ($i < @hdrs) && ($hdrs[$i] ne $abbr); $i++) {}
    my @pegs;
    foreach $_ (split(/\n/,$genomes))
    {
	my @rows = split(/\t/,$_);
	my $g = shift @rows;
	shift @rows;  # dump variant code
	push(@pegs,map { "fig|$g.peg.$_" } split(/,/,$rows[$i]));
    }
    @pegs = grep { $fig->is_real_feature($_) } @pegs;
    my @tuples = map { [$_,$fig->taxonomy_of(&SeedUtils::genome_of($_)),$fig->genus_species(&SeedUtils::genome_of($_))] } @pegs;
    @tuples = sort { $a->[1] cmp $b->[1] } @tuples;
    #print STDERR Dumper(\@tuples);
    #return map { $_->[0] } @tuples;
    return @tuples;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3