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

View of /FigKernelScripts/fig_net.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Mon Jun 21 22:08:14 2004 UTC (15 years, 5 months ago) by mkubal
Branch: MAIN
CVS Tags: merge-trunktag-bobdev_news-2, Root-bobdev_news, merge-bobdev_news-1, caBIG-dataload-0, merge-trunktag-bobdev_news-1, merge-bodev_news-3, efrank-preMakefileToStandardMk, caBIG-00-00-00, merge-bobdev_news-2, merge-trunktag-bodev_news-3
Branch point for: Branch-bobdev_news
Changes since 1.1: +1098 -55 lines
script to get ECs with no genes

# -*- perl -*-
use Carp;
use Data::Dumper;
use Time::HiRes qw(gettimeofday);

use FIGnet;
use FIG;
use Blast;

my($user);

my $usage = "usage: fig_net $url [-echo] [-time] [command]";

defined($url = shift @ARGV)
    || die $usage;

$figN = new FIGnet($url);
$fig  = new FIG;

$echo       = 0;
$time_cmds  = 0;
while ((@ARGV > 0) && ($ARGV[0] =~ /^-/))
{
    $arg = shift @ARGV;
    if ($arg =~ /^-time/i) { $time_cmds = 1 }
    if ($arg =~ /^-echo/i) { $echo      = 1 }
}

my($t1,$t2,$i);
if (@ARGV > 0)  { $req = join( " ", @ARGV ); }
while ( (defined($req) && $req) || ($req = &get_req) )
{
    if ($time_cmds)
    {
	$t1 = gettimeofday;
    }

    if ($req =~ /^\s*DB\s*$/)
    {
	if ($figN->{_fig})  # if a local SEED
	{
	    print "$FIG_Config::db\n\n";
	}
	else
	{
	    my $url = $figN->{_url} . "/kernel.cgi?request=DB";
	    my @out = &FIGnet::get_url($url);
	    for ($i=0; ($i < @out) && ($out[$i] !~ /^<pre>/i); $i++) {}
	    print $out[$i+1];
	}
    }
    elsif ($req =~ /^\s*abbrev\s+(\S.*\S)\s*$/)
    {
        $genome_name = $1;
	print &FIGnet::abbrev($genome_name),"\n";;
    }
    elsif ($req =~ /^\s*genomes(\s+(\S.*\S))?\s*$/)
    {
	$pat = $2;
	foreach $genome ($figN->genomes)
	{
	    my $genus_species = $figN->genus_species($genome);
	    if ((! $pat) || ($genus_species =~ /$pat/))
	    {
		print join("\t",(&padded($genome,15),$genus_species)),"\n";
	    }
	}
	print "\n";
    }
    elsif ($req =~ /^\s*map_to_ecs\s+(\S+)\s*$/)
    {
	print join("\n",$figN->map_to_ecs($1)),"\n\n";
    }
    elsif ($req =~ /^\s*all_maps\s*$/)
    {
	@maps = $figN->all_maps;
	foreach $map (@maps)
	{
	    print "$map: ",$fig->map_name($map),"\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*all_compounds\s*$/)
    {
	@compounds = $figN->all_compounds;
	foreach $compound (@compounds)
	{
	    my @tmp = $fig->names_of_compound($compound);
	    print "$compound: $tmp[0]\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*all_reactions\s*$/)
    {
	@reactions = $figN->all_reactions;
	foreach $reaction (@reactions)
	{
	    $tmp = $fig->displayable_reaction($reaction);
	    print "$tmp\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*reversible\s+(\S+)\s*$/)
    {
	$rid = $1;
	$rev = $figN->reversible($rid) ? "reversible" : "not reversible";;
	$displayable = $fig->displayable_reaction($rid);
	print "$rev\n$displayable\n\n";
    }
    elsif ($req =~ /^\s*catalyzed_by\s+(\S+)\s*$/)
    {
	$rid = $1;
	@ecs = $figN->catalyzed_by($rid);
	$displayable = $fig->displayable_reaction($rid);
	print "$displayable\n";
	foreach $ec (@ecs)
	{
	    $x = $fig->expand_ec($ec);
	    print "$x\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*catalyzes\s+(\S+)\s*$/)
    {
	$ec = $1;
	@rids = $figN->catalyzes($ec);
	print $fig->expand_ec($ec),"\n";
	foreach $rid (@rids)
	{
	    $displayable = $fig->displayable_reaction($rid);
	    print "$displayable\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*reaction2comp\s+(\S+)\s+(\d)\s*$/)
    {
	$rid = $1;
	$which = $2;
	@tmp = $figN->reaction2comp($rid,$which);
	print &Dumper(\@tmp);
	$displayable = $fig->displayable_reaction($rid);
	print "$displayable\n\n";
    }
    elsif ($req =~ /^\s*names_of_compound\s+(\S+)\s*$/)
    {
	$cid = $1;
	@names = $figN->names_of_compound($cid);
	foreach $name (@names)
	{
	    print "$name\n";
	}
    }
    elsif ($req =~ /^\s*comp2react\s+(\S+)\s*$/)
    {
	$cid = $1;
	@rids = $figN->comp2react($cid);
	foreach $rid (@rids)
	{
	    print $fig->displayable_reaction($rid),"\n";
	}
    }
    elsif ($req =~ /^\s*names_of_compounds\s*$/)
    {
	foreach $x ($figN->names_of_compounds)
	{
	    ($cid,$names) = @$x;
	    print "$cid\n";
	    foreach $name (@$names)
	    {
		print "\t$name\n";
	    }
	    print "\n";
	}
    }
    elsif ($req =~ /^\s*seqs_with_roles_in_genomes\s+(\S+)\s+(\S+)\s+(\S+)\s*$/)
    {
	$genomesF = $1;
	$rolesF   = $2;
	$who = $3;
	$genomes = [map { chop; $_ } `cat $genomesF`];
	$roles   = [map { chop; $_ } `cat $rolesF`];
	print "\n";
    }
    elsif ($req =~ /^\s*feature_annotations\s+(\S+)\s*$/)
    {
	$fid = $1;
	print "Annotations of $fid\n\n";
	@annotations = $figN->feature_annotations($fid);
	foreach $x (@annotations)
	{
	    (undef,$ts,$who,$annotation) = @$x;
	    print "$ts\t$who\n$annotation\n============\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*dna_seq\s+(\S+)\s+(\S+)\s*$/)
    {
	$seq = $figN->dna_seq($1,split(/,/,$2));
	print "$seq\n\n";
    }
    elsif ($req =~ /^\s*all_protein_families\s*$/)
    {
	print "Fam.\tSize\n\n";
	foreach $family ($figN->all_protein_families)
	{
	    print "$family\t",$figN->sz_family($family),"\n";
	}
	print "\n";
    }
    #elsif ($req =~ /^\s*all_features\s+(\d+\.\d+)\s+(\S+)\s*$/)
    #{
#	@ids =  sort { $figN->by_fig_id($a,$b) } $figN->all_features($1,$2);
#	while (@ids > 0)
#	{
#	    @tmp = splice(@ids,0,$figN->min(3,scalar @ids));
#	    print join("\t",@tmp),"\n";
#	}
#	print "\n";
#    }
    elsif ($req =~ /^\s*all_sets\s+(\S+)\s+(\S+)\s*$/)
    {
	$relation   = $1;
	$set_name   = $2;
	print "Set\tSize\n\n";
	foreach $set ($figN->all_sets($relation,$set_name))
	{
	    print "$set\t",$figN->sz_set($set,$relation,$set_name),"\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*catalyzed_by\s+(\S+)\s*$/)
    {
	$rid = $1;
	@ecs = $fig->catalyzed_by($rid);
	$displayable = $figN->displayable_reaction($rid);
	print "$displayable\n";
	foreach $ec (@ecs)
	{
	    $x = $fig->expand_ec($ec);
	    print "$x\n";
	}
	print "\n";
    }
    
    elsif ($req =~ /^\s*cgi_url\s*$/)
    {
	print $figN->cgi_url;
      
    }

    elsif ($req =~ /^\s*get_translation\s+(\S+)\s*$/)
    {
	$id     = $1;
	$seq = $figN->get_translation($id);
	print "$seq\n";
	print "\n";
    }
    
    elsif ($req =~ /^\s*function_of\s+(\S+)(\s+(\S+))?\s*$/)
    {
	if ($2)
	{
	    $extra = $2;
	    $all   = ($extra =~ /all/i);
	    $tran  = ($extra =~ /tran/i);
	}
	if ($all)
	{
	    foreach $x ($figN->function_of($1))
	    {
		($who,$func) = @$x;
		if ($tran) { $func = $figN->translate_function($func) }
		print &padded($who,30)," $func\n";
	    }
	}
	else
	{
	    $func = $figN->function_of($1);
	    if ($tran) { $func = $figN->translate_function($func) }
	    print "$func\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*org_of\s+(\S+)\s*$/)
    {
	print $figN->org_of($1),"\n\n";
    }
    
    elsif ($req =~ /^\s*blast\s+(\S+)\s*$/)
    {
	$id = $1;
	$func = $figN->function_of($id);

	if ($sims = &Blast::blastp([[$id,$figN->get_translation($id)]],"$FIG_Config::global/nr","-e 1.0e-5",0,0))
	{
	    $sims = $sims->{$id};

	    print &padded($id,20),"\t",$sims->[0]->ln1."\t$func\n\n";
	    foreach $sim (@$sims)
	    {
		$func = $figN->function_of($sim->id2);
		$org  = $figN->org_of($sim->id2);
		print join("\t",(&padded($sim->id2,20),
				 $sim->ln2,
				 $sim->psc,
				 $sim->b1,
				 $sim->e1,
				 $sim->b2,
				 $sim->e2,
				 $org,
				 $func)),"\n";
	    }
	}
	print "\n";
    }

    elsif ($req =~ /^\s*by_alias\s+(\S+)\s*$/)
    {
        $alias = $1;
	print $figN->by_alias($alias);
    }
    elsif ($req =~ /^\s*by_fig_id\s+(\S+)\s+(\S+)\s*$/)
    {
        $feature_id_a = $1;
        $feature_id_b = $2;
	print $figN->by_fig_id($feature_id_a,$feature_id_b),"\n";
    }
    elsif ($req =~ /^\s*cas\s+(\S+)\s*$/)
    {
	$cid = $1;
	$cas = $figN->cas($cid);
	@names = $figN->names_of_compound($cid);
	print "$cid\t$cas\t$names[0]\n\n";
    }
    elsif ($req =~ /^\s*cas_to_cid\s+(\S+)\s*$/)
    {
	$cas = $1;
	$cid = $figN->cas_to_cid($cas);
        print "$cid\n\n";
    }
    elsif ($req =~ /^\s*close_genes\s+(\S+)\s+(\S+)\s*$/)
    {
        $feature_id = $1;
        $dist = $2;
	print join(",",$figN->close_genes($feature_id,$dist)),"\n";
    }
    elsif ($req =~ /^\s*contig_ln\s+(\S+)\s+(\S+)\s*$/)
    {
	print $figN->contig_ln($1,$2),"\n\n";
    }
     elsif ($req =~ /^\s*coupling_and_evidence\s+(fig\|\d+\.\d+\.peg\.\d+)\s+(\d+)\s+(\S+)\s+(\S+)/)
    {
	$fid = $1;
	$bound = $2;
	$sim_cutoff = $3;
	$coup_cutoff = $4;
	@tmp = $figN->coupling_and_evidence($fid,$bound,$sim_cutoff,$coup_cutoff);
	print &Dumper(\@tmp),"\n\n";
    }

    elsif ($req =~ /^\s*crude_estimate_of_distance\s+(\S+)\s+(\S+)\s*$/)
    {
	print $figN->crude_estimate_of_distance($1,$2),"\n\n";
    }
    elsif ($req =~ /^\s*displayable_reaction\s+(\S+)\s*$/)
    {
        $rid = $1;
	print $figN->displayable_reaction($rid),"\n";
    }
    elsif ($req =~ /^\s*ec_to_maps\s+(\S+)\s*$/)
    {
	print join("\n",$figN->ec_to_maps($1)),"\n\n";
    }
    elsif ($req =~ /^\s*map_name\s+(\S+)\s*$/)
    {
	print $figN->map_name($1),"\n\n";
    }
    elsif ($req =~ /^\s*verify_dir\s+(\S+)\s*$/)
    {
	$dir = $1;
	$figN->verify_dir($dir);
	print "$dir is now a directory\n";
    }
    elsif ($req =~ /^\s*ec_name\s+(\S+)\s*$/)
    {
	$ec= $1;
        print $figN->ec_name($ec),"\n";
    }
    elsif ($req =~ /^\s*all_roles\s*$/)
    {
	my @tmp = $figN->all_roles;
	print &Dumper(\@tmp);
    }

    elsif ($req =~ /^\s*expand_ec\s+(\S+)\s*$/)
    {
	$ec = $1;
        print $figN->expand_ec($ec),"\n";
    }
    elsif ($req =~ /^\s*clean_tmp\s*$/)
    {
	$figN->clean_tmp;
	print "Cleaned $FIG_Config::temp\n";
    }
    elsif ($req =~ /^\s*ftype\s+(\S+)\s*$/)
    {
        $feature_id = $1;
	print $figN->ftype($feature_id),"\n";;
    }
    elsif ($req =~ /^\s*genome_of\s+(\S+)\s*$/)
    {
        $feature_id = $1;
	print $figN->genome_of($feature_id),"\n";
    }
        elsif ($req =~ /^\s*pegs_of\s+(\S+)\s*$/)
    {
        $genome = $1;
	print join(",",$figN->pegs_of($genome)),"\n";
    }
    elsif ($req =~ /^\s*rnas_of\s+(\S+)\s*$/)
    {
        $genome = $1;
	my @tmp = $figN->rnas_of($genome);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*feature_aliases\s+(\S+)\s*$/)
    {
        $feature_id = $1;
	print join(",",$figN->feature_aliases($feature_id)),"\n";
    }
    elsif ($req =~ /^\s*possibly_truncated\s+(\S+)\s*$/)
    {
        $feature_id = $1;
	print $figN->possibly_truncated($feature_id),"\n";
    }
    elsif ($req =~ /^\s*is_real_feature\s+(\S+)\s*$/)
    {
        $feature_id = $1;
	print $figN->is_real_feature($feature_id),"\n";
    }
    elsif ($req =~ /^\s*translatable\s+(\S+)\s*$/)
    {
        $prot_id = $1;
	print $figN->translatable($prot_id),"\n";
    }
    elsif ($req =~ /^\s*maps_to_id\s+(\S+)\s*$/)
    {
        $id = $1;
	print $figN->maps_to_id($id),"\n";
    }
    elsif ($req =~ /^\s*translated_function_of\s+(\S+)\s+(\S+)\s*$/)
    {
        $peg = $1;
        $user = $2;
	print $figN->translated_function_of($peg,$user),"\n";
    }
    elsif ($req =~ /^\s*translate_function\s+(\S.*\S)\s*$/)
    {
        $func = $1;
	print $figN->translate_function($func),"\n";
    }
    elsif ($req =~ /^\s*hypo\s+(\S.*\S)\s*$/)
    {
	print $figN->hypo($1),"\n";
    }
    elsif ($req =~ /^\s*blastit\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*$/)
    {
        $peg = $1;
        $seq = $2;
        $db = $3;
        $maxP = $4;
	@tmp = $figN->blastit($peg,$seq,$db,$maxP);
	print &Dumper(\@tmp);
    }    
    elsif ($req =~ /^\s*related_by_func_sim\s+(\S+)\s+(\S+)\s*$/)
    {
        $peg = $1;
        $user = $2;
        print join(",",$figN->related_by_func_sim($peg,$user)),"\n";
    }
    elsif ($req =~ /^\s*epoch_to_readable\s*$/)
    {
       	print $figN->epoch_to_readable(time);
    }
    elsif ($req =~ /^\s*search_index\s+(\S+)\s*$/)
    {
        $pattern = $1;
	my @tmp = $figN->search_index($pattern);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*sz_family\s+(\S+)\s*$/)
    {
        $family = $1;
	print $figN->sz_family($family),"\n";
    }
    elsif ($req =~ /^\names_of_compound\s+(\S+)\s*$/)
    {
	my @tmp = $figN->names_of_compound($1);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*reversible\s+(\S+)\s*$/)
    {
        $rid = $1;
	print $figN->reversible($rid),"\n";
    }
    elsif ($req =~ /^\s*neighborhood_of_role\s+(\S+)\s*$/)
    {
        $role = $1;
	my @tmp = $figN->neighborhood_of_role($role);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*roles_of_function\s+(\S+)\s*$/)
    {
        $func = $1;
	my @tmp = $figN->roles_of_function($func);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*assign_function\s+(\S+)\s+(\S+)(\s+conf=(\S))?\s+(\S.*\S)\s*$/)
    {
	$peg      = $1;
	$user     = $2;
	$conf     = $3 ? $4 : "";
	$func     = $5;
	print $figN->assign_function($peg,$user,$func,$conf),"\n\n";
    }
    elsif ($req =~ /^\s*assign_functionF\s+(\S+)\s+(\S+)\s*$/)
    {
	$user     = $1;
	$file     = $2;
	if (open(TMP,"<$file"))
	{
	    while (defined($_ = <TMP>))
	    {
		chop;
		($peg,$func,$conf) = split(/\t/,$_);
		if (! $conf) { $conf = "" }
		if ($user =~ /master:(.*)/)
		{
		    $userR = $1;
		    $funcO = $figN->function_of($peg);
		    if ($funcO ne $func)
		    {
			$figN->assign_function($peg,"master",$func,$conf);
			$figN->add_annotation($peg,$userR,"Set master function to\n$func\n");
		    }
		}
		else
		{
		    $funcO = $figN->function_of($peg,$user);
		    if ($funcO ne $func)
		    {
			$figN->assign_function($peg,$user,$func,$conf);
			$figN->add_annotation($peg,$user,"Set function to\n$func\n");
		    }
		}
	    }
	    close(TMP);
	}
    }

    elsif ($req =~ /^\s*largest_clusters\s+(\S+)\s+(\S+)\s*$/)
    {
        $file = $1;
        $user = $2;
	my @tmp = `cat $file`;
	chop @tmp;;
	my @tmp1 = $figN->largest_clusters(\@tmp,$user);
	print &Dumper(\@tmp1);
    }
    elsif ($req =~ /^\s*unique_functions\s+(\S+)\s+(\S+)\s*$/)
    {
        $pegs = $1;
        $user = $2;
	my @tmp = $figN->unique_functions([split(/,/,$pegs)],$user);
	print &Dumper(\@tmp);
    }
    elsif ($req =~ /^\s*extract_seq\s+(\S+)\s+(\S+)\s*$/)
    {
        $contigsF = $1;
        $loc = $2;
	$contigs  = &load_contigs($contigsF);
	print &Dumper(&FIG::extract_seq($contigs,$loc));
    }
    elsif ($req =~ /^\s*is_bacterial\s+(\S+)\s*$/)
    {
        $genome = $1;
        print $figN->is_bacterial($genome),"\n";;
    }
    elsif ($req =~ /^\s*is_archaeal\s+(\S+)\s*$/)
    {
        $genome = $1;
        print $figN->is_archaeal($genome),"\n";
    }
    elsif ($req =~ /^\s*is_prokaryotic\s+(\S+)\s*$/)
    {
        $genome = $1;
        print $figN->is_prokaryotic($genome),"\n";
    }
    elsif ($req =~ /^\s*is_eukaryotic\s+(\S+)\s*$/)
    {
        $genome = $1;
        print $figN->is_eukaryotic($genome),"\n";
    }
    elsif ($req =~ /^\s*sort_genomes_by_taxonomy\s+(\S+(\s+\S+)*)\s*$/)
    {
        @list_of_genomes = split(/\s+/,$1);
        print join(",",$figN->sort_genomes_by_taxonomy(@list_of_genomes)),"\n";
    }
    elsif ($req =~ /^\s*sort_fids_by_taxonomy\s+(\S+(\s+\S+)*)\s*$/)
    {
        @fids = split(/\s+/,$1);
        print join(",",$figN->sort_fids_by_taxonomy(@fids)),"\n";
    }
    elsif ($req =~ /^\s*build_tree_of_complete\s+(\S+)\s*$/)
    {
        $min_for_label = $1;
        print &Dumper($figN->build_tree_of_complete($min_for_label));
    }
    elsif ($req =~ /^\s*taxonomic_groups_of_complete\s+(\S+)\s*$/)
    {
        $min_for_labels = $1;
        print &Dumper($figN->taxonomic_groups_of_complete($min_for_labels));
    }
    elsif ($req =~ /^\s*max\s+(((\d+)\s+)*\d+)\s*$/)
    {
	print $figN->max(split(/\s+/,$1)),"\n\n";
    }
    elsif ($req =~ /^\s*add_genome\s+((.*\/)?(\d+\.\d+))\s*$/)
    {
	$genomeF = $1;
	$genome = $3;
	if ((! -d "$FIG_Config::organisms/$genome") && ($figN->add_genome($genomeF)))
	{
	    print "Added $genome\n";
	}
	else
	{
	    print "Failed to add $genome from $genomeF\n";
	}
    }
    elsif ($req =~ /^\s*delete_genomes\s+(\d.*\d)\s*$/)
    {
	$genomes = $1;
	@genomes = split(/\s+/,$genomes);
	if (@genomes > 0)
	{
	    @bad_genomes = grep { ! -d "$FIG_Config::organisms/$_" } @genomes;
	    if (@bad_genomes > 0)
	    {
		print "Bad Genomes: ",join(" ",@bad_genomes),"\n";
	    }
	    else
	    {
		$figN->delete_genomes(\@genomes);
		print "Completed deleting ",join(" ",@genomes),"\n";
	    }
	}
    }
    elsif ($req =~ /^\s*min\s+(((\d+)\s+)*\d+)\s*$/)
    {
	print $figN->min(split(/\s+/,$1)),"\n\n";
    }
    elsif ($req =~ /^\s*between\s+(\d+)\s+(\d+)\s+(\d+)\s*$/)
    {
	print $figN->between($1,$2,$3),"\n\n";
    }
    elsif ($req =~ /^\s*merge_related_annotations\s+(\S.*\S)\s*$/)
    {
	$pegs = [split(/\s+/,$1)];
	my @tmp = $figN->merged_related_annotations($pegs);
	print &Dumper(\@tmp);
	print "\n";
    }
    elsif ($req =~ /^\s*genus_species\s+(\d+\.\d+)\s*$/)
    {
	print $figN->genus_species($1),"\n\n";
    }
    elsif ($req =~ /^\s*genome_counts(\s+(complete))?/)
    {
	$counts = $figN->genome_counts($2);
	print "$counts\n";
    }
    elsif ($req =~ /^\s*file2N\s+(\S+)\s*$/)
    {
	print $figN->file2N($1),"\n\n";
    }
    elsif ($req =~ /^\s*genome_version\s+(\S+)\s*$/)
    {
	$_ = defined($_ = $figN->genome_version($1)) ? $_ : "undefined";
	print "$_\n\n";
    }
    
    elsif ($req =~ /^\s*taxonomy_of\s+(\d+\.\d+)\s*$/)
    {
	print $figN->taxonomy_of($1),"\n\n";
    }    
    
    elsif ($req =~ /^\s*fast_coupling\s+(fig\|\d+\.\d+\.peg\.\d+)\s+(\d+)\s+(\S+)/)
    {
	$fid = $1;
	$bound = $2;
	$coup_cutoff = $3;
	@tmp = $figN->fast_coupling($fid,$bound,$coup_cutoff);
	print &Dumper(\@tmp),"\n\n";
    } 

    elsif ($req =~ /^\s*auto_assign\s+(fig\|\d+\.\d+\.peg\.\d+)(\s+(\S+))?\s*$/)
    {
	$fid = $1;
	$seq = $3;
	print $figN->auto_assign($fid,$seq),"\n\n";
    }
    
    elsif ($req =~ /^\s*auto_assignG\s+(\S+)\s+(\S.*\S)\s*$/)
    {
	$user = $1;
	@genomes = split(/\s+/,$2);
	foreach $genome (@genomes)
	{
	    if (-s "$FIG_Config::organisms/$genome/Features/peg/tbl")
	    {
		print STDERR "making assignments for $genome\n";
		system "cut -f1 $FIG_Config::organisms/$genome/Features/peg/tbl > tmp$$ ; fig auto_assignF $user tmp$$";
		unlink("tmp$$");
	    }
	}
	print "\n";
    }
    
    elsif (($req =~ /^\s*auto_assignF\s+(\S+)\s+(\S+)\s*$/) && 
	   ($file = $2) && (-s $file) &&
	   ($user = $1))
    {
        $n = 0; 
        foreach $assignment (`cut -f1 $file | auto_assign | make_calls`)
        {
            if ($assignment =~ /^(\S+)\t(\S[^\t]+\S)(\t(\S))?\s*$/)
            {
		$prot = $1;
		$function = $2;
		$conf = $4 ? $4 : "";
		$n++;
		if ($user =~ /master:(.*)/)
		{
		    $userR = $1;
		    $figN->assign_function($prot,"master",$function,$conf);
		    if ($userR ne "none")
		    {
			$figN->add_annotation($prot,$userR,"Set master function to\n$function\n");
		    }
		}
		else
		{
		    $figN->assign_function($prot,$user,$function,$conf);
		    if ($user ne "none")
		    {
			$figN->add_annotation($prot,$user,"Set function to\n$function\n");
		    }
		}
	    }
	}
	close(TMP);
	print STDERR "$n assignments made (all attributed to $user)\n";
    }

    elsif ($req =~ /^\s*assignments_made\s+(\S+)\s+(\d{1,2}\/\d{1,2}\/\d{4})(\s+(\S.*\S))?\s*$/)
    {
	$who = $1;
	$date = $2;
	if ($3)
	{
	    $genomes = [split(/\s+/,$4)];
	}
	else
	{
	    $genomes = [$figN->genomes];
	}
	    
	foreach $assignment ($figN->assignments_made($genomes,$who,$date))
	{
	    print join("\t",@$assignment),"\n";
	}
    }
    
    elsif ($req =~ /^\s*genes_in_region\s+(\d+\.\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s*$/)
    {
	print &Dumper($figN->genes_in_region($1,$2,$3,$4)),"\n\n";
    }
    elsif ($req =~ /^\s*all_features\s+(\d+\.\d+)\s+(\S+)\s*$/)
    {
	@ids =  sort { $figN->by_fig_id($a,$b) } $figN->all_features($1,$2);
	while (@ids > 0)
	{
	    @tmp = splice(@ids,0,$figN->min(3,scalar @ids));
	    print join("\t",@tmp),"\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*function_of\s+(\S+)\s*(\S+)?\s*$/)
    {
	if ($2)
	{
	    $extra = $2;
	    $all   = ($extra =~ /all/i);
	    $tran  = ($extra =~ /tran/i);
	}
	if ($all)
	{
	    foreach $x ($figN->function_of($1))
	    {
		($who,$func) = @$x;
		if ($tran) { $func = $figN->translate_function($func) }
		print &padded($who,30)," $func\n";
	    }
	}
	else
	{
	    $func = $figN->function_of($1);
	    if ($tran) { $func = $figN->translate_function($func) }
	    print "$func\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*in_cluster_with\s+(\S+)\s*$/)
    {
	$peg = $1;
	@pegs = $figN->in_cluster_with($peg);
	$func = $figN->function_of($peg);
	print "$peg\t$func\n\n";
	foreach $peg (@pegs)
	{
	    $func = $figN->function_of($peg);
	    print "$peg\t$func\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*feature_location\s+(\S+)\s*$/)
    {
	$fid = $1;
	if ($loc = $figN->feature_location($fid))
	{
	    print "$loc\n";
	}
	else
	{
	    print "no location\n";
	}
    }
    elsif ($req =~ /^\s*translation_length\s+(\S+)\s*$/)
    {
	$fid = $1;
	if ($len = $figN->translation_length($fid))
	{
	    print "$len\n";
	}
	else
	{
	    print "no length for $fid\n";
	}
    }   
    elsif ($req =~ /^\s*mapped_prot_ids\s+(\S+)\s*$/)
    {
	foreach $x ($figN->mapped_prot_ids($1))
	{
	    ($id,$len) = @$x;
	    print &padded($id,20),"\t$len\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*boundaries_of\s+(\S+)\s*$/)
    {
	print join("_",$figN->boundaries_of($1)),"\n\n";
    }
    elsif ($req =~ /^\s*family_function\s+(\d+)\s*$/)
    {
	$family     = $1;
	$func       = $figN->family_function($family);
	print "family $family: $func\n\n";
    }
    elsif ($req =~ /^\s*in_family\s+(\S+)\s*$/)
    {
	$id         = $1;
	$n          = $figN->in_family($id);
	print "$id is in family $n\n\n";
    }
    elsif ($req =~ /^\s*ids_in_family\s+(\d+)\s*$/)
    {
	$family     = $1;
	$func       = $figN->family_function($family);
	print "family $family: $func\n\n";
	@ids = $figN->ids_in_family($family);
	while (@ids > 0)
	{
	    @tmp = splice(@ids,0,$figN->min(3,scalar @ids));
	    print join("\t",@tmp),"\n";
	}
	print "\n";

    }
    elsif ($req =~ /^\s*in_sets\s+(\S+)\s+(\S+)\s+(\S+)\s*$/)
    {
	$id         = $1;
	$relation   = $2;
	$set_name   = $3;
	print "$id is in set(s) ",join(",",$figN->in_sets($id,$relation,$set_name)),"\n\n";
    }
    elsif ($req =~ /^\s*in_pch_pin_with\s+(\S+)\s*$/)
    {
	$id         = $1;
	print "$id is in set(s) ",join(",",$figN->in_pch_pin_with($id)),"\n\n";
    }
    elsif ($req =~ /^\s*exportable_subsystem\s+(\S.*\S+)\s*$/)
    {
	my $ssa = $1;
	my($spreadsheet,$notes) = $figN->exportable_subsystem($ssa);
	print join("",@$spreadsheet),join("",@$notes),"\n";
    }
    elsif ($req =~ /^\s*is_exchangable_subsystem\s+(\S.*\S+)\s*$/)
    {
	my $ssa = $1;
	print $figN->is_exchangable_subsystem($ssa),"\n";
    }
    elsif ($req =~ /^\s*all_exchangable_subsystems\s*$/)
    {
	print join("\n",$figN->all_exchangable_subsystems),"\n";
    }
    elsif ($req =~ /^\s*export_set\s+(\S+)\s+(\S+)\s+(\S+)\s*$/)
    {
	$relation   = $1;
	$set_name   = $2;
	$file       = $3;
	print $figN->export_set($relation,$set_name,$file),"\n\n";
    }
    elsif ($req =~ /^\s*export_chromosomal_clusters\s*$/)
    {
	print $figN->export_set("chromosomal_clusters","cluster_id","$FIG_Config::global/chromosomal_clusters"),"\n\n";
    }
    elsif ($req =~ /^\s*export_pch_pins\s*$/)
    {
	print $figN->export_set("pch_pins","pin","$FIG_Config::global/pch_pins"),"\n\n";
    }
    elsif ($req =~ /^\s*add_chromosomal_clusters\s+(\S+)\s*$/)
    {
	$file = $1;
	print $figN->add_chromosomal_clusters($file),"\n\n";
    }
    elsif ($req =~ /^\s*add_pch_pins\s+(\S+)\s*$/)
    {
	$file = $1;
	print $figN->add_pch_pins($file),"\n\n";
    }
    elsif ($req =~ /^\s*all_sets\s+(\S+)\s+(\S+)\s*$/)
    {
	$relation   = $1;
	$set_name   = $2;
	print "Set\tSize\n\n";
	foreach $set ($figN->all_sets($relation,$set_name))
	{
	    print "$set\t",$figN->sz_set($set,$relation,$set_name),"\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*seqs_with_role\s+(\S+)\s+(\S+)\s+(\S.*\S)\s*$/)
    {
	$genome = $1;
	$role   = $3;
	$who    = $2;
	foreach $peg ($figN->seqs_with_role($role,$who,$genome))
	{
	    $func = $figN->function_of($peg,$who);
	    print "$peg\t$func\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*load_all\s*$/)
    {
	if ($figN->load_all)
	{
	    print "imported everything\n";
	}
    }
    elsif ($req =~ /^\s*dsims\s+(\S+)(\s+(\S+)\s+(\S+)\s+(\S+))?\s*$/)
    {
	$file    = $1;
	$maxN    = $3 ? $3 : 500;
	$maxP    = $4 ? $4 : 1,0e-5;
	$select  = $5 ? $5 : "raw";
	if (open(TMP,"<$file"))
	{
	    $_ = <TMP>;
	    while (defined($_) && ($_ =~ /^>(\S+)/))
	    {
		$id = $1;
		@seqs = ();
		while (defined($_ = <TMP>) && ($_ !~ /^>/))
		{
		    push(@seqs,$_);
		}
		$seq = join("",@seqs);
		$seq =~ s/\s//gs;
		if (@sims = $figN->dsims($id,$seq,$maxN,$maxP,$select,0))
		{
		    print "$id\t",length($seq),"\n\n";
		    foreach $sim (@sims)
		    {
			$func = $figN->function_of($sim->id2);
			print join("\t",($sim->id2(),
					 $sim->ln2,
					 $sim->psc,
					 $sim->b1,
					 $sim->e1,
					 $sim->b2,
					 $sim->e2,
					 $sim->iden,
					 $func)),"\n";
		    }
		    print "\n";
		}
	    }
	    close(TMP);
	}
	print "\n";
    }
    elsif ($req =~ /^\s*access_sims\s+(\S+)?\s*$/)
    {
	$opt = $1 ? $1 : "";
	foreach $peg ("fig|562.1.peg.14","fig|630.1.peg.589","fig|731.2.peg.1626","fig|75985.1.peg.2319","fig|294.1.peg.4630","fig|305.1.peg.2718","fig|292.1.peg.3262","fig|519.1.peg.4061","fig|633.1.peg.2431","fig|384.1.peg.2479")
	{
	    @sims = $figN->sims($peg,600,1.0e-3,"raw",0);
	    if ($opt =~ /expand/)
	    {
		foreach $sim (@sims)
		{
		    @map = $figN->mapped_prot_ids($sim->id2);
		    foreach $to (@map)
		    {
			if ($opt =~ /func/)
			{
			    @funcs = $figN->function_of($to->[0]);
			}
		    }
		}
	    }
	    elsif ($opt =~ /func/)
	    {
		foreach $sim (@sims)
		{
		    @funcs = $figN->function_of($sim->id2);
		}
	    }
	}
    }
    elsif ($req =~ /^\s*sims\s+(\S+)(\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d))?\s*$/)
    {
	$id      = $1;
	$maxN    = $3 ? $3 : 500;
	$maxP    = $4 ? $4 : 1,0e-5;
	$select  = $5 ? $5 : "raw";
	$tran = $6;

	$func = $figN->function_of($id);
	if (@sims = $figN->sims($id,$maxN,$maxP,$select))
	{
	    print &padded($id,20),"\t",$sims[0]->ln1."\t$func\n\n";
	    foreach $sim (@sims)
	    {
		$func = $figN->function_of($sim->id2);
		if ($tran) { $func = $figN->translate_function($func) }

		$org  = $figN->org_of($sim->id2);
		print join("\t",(&padded($sim->id2,20),
				 $sim->ln2,
				 $sim->psc,
				 $sim->b1,
				 $sim->e1,
				 $sim->b2,
				 $sim->e2,
				 $sim->iden,
				 $org,
				 $func)),"\n";
	    }
	}
	print "\n";
    }
    elsif ($req =~ /^\s*ids_in_set\s+(\d+)\s+(\S+)\s+(\S+)\s*$/)
    {
	$set        = $1;
	$relation   = $2;
	$set_name   = $3;
	print "$set_name $set\n\n";
	@ids = $figN->ids_in_set($set,$relation,$set_name);
	while (@ids > 0)
	{
	    @tmp = splice(@ids,0,$figN->min(3,scalar @ids));
	    print join("\t",@tmp),"\n";
	}
	print "\n";
    }
  
    elsif ($req =~ /^\s*get_translations\s+(\S+)(\s+tab)?\s*$/i)
    {
	$file = $1;
	$tab = $2 ? 1 : 0;
	if (open(TMP,"<$file"))
	{
	    while (defined($_ = <TMP>))
	    {
		foreach $id ($_ =~ /\S+/g)
		{
		    if ($seq = $figN->get_translation($id))
		    {
			if ($tab)
			{
			    print "$id\t$seq\n";			
                        }
			else
			{
			    $figN->display_id_and_seq($id,\$seq);
			}
		    }
		}
	    }
	    close(TMP);
	}
	else
	{
	    print STDERR "could not open $file\n";
	}
	print "\n";
    }
  
     elsif ($req =~ /^\s*add_annotation\s+(\S+)\s+(\S+)\s*$/)
    {
	$fid     = $1;
	$user    = $2;
	print "Type in annotation (end with \".\" at start of line)\n>> ";
	@ann = ();
	while (defined($_ = <STDIN>) && ($_ !~ /^\./))
	{
	    push(@ann,$_);
	    print ">> ";
	}
	print $figN->add_annotation($fid,$user,join("",@ann)),"\n\n";
    }
   
    elsif ($req =~ /^\s*h\s+(\S+)/)
    {
	if (-s "Help/$1")
	{
	    @tmp = `cat Help/$1`;
	    print "\n",join("",@tmp),"\n";
	}
	else
	{
	    print "sorry, no help for $1\n\n";
	}
    }
    else
    {
	print "invalid command\n";
    }
    print "\n";
    $req = "";

    if ($time_cmds)
    {
	$t2 = gettimeofday;
	print $t2-$t1," seconds to execute command\n\n";
    }
}
sub padded {
    my($x,$n) = @_;

    if (length($x) < $n)
    {
	return $x . (" " x ($n - length($x)));
    }
    return $x;
}

sub get_req {
    my($x);

    print "?? ";
    $x = <STDIN>;
    while (defined($x) && ($x =~ /^h$/i) )
    { 
	&help;
	print "?? ";
	$x = <STDIN>;
    }
    
    if ((! defined($x)) || ($x =~ /^\s*[qQxX]/))
    {
	return "";
    }
    else
    {
        if ($echo)
	{
	    print ">> $x\n";
	}
	return $x;
    }
}

sub help {
    print <<END;
    DB                              Current DB
    abbrev                          genome_name
    add_annotation                  FID User [ prompted for annotation; terminate with "." at start of line ]
    add_chromosomal_clusters        File
   *add_genome                      GenomeDir
    add_pch_pins                    File
    all_compounds               
    all_features                    GenomeID Type
    all_maps                 
    all_protein_families
    all_reactions
    all_roles
    all_sets                        Relation SetName
    assign_function                 PEG User [conf=X] Function
    assign_functionF                User File
    assignments_made                who date G1 G2 ...  [ none => all ]
    auto_assign                     PEG [Seq]
    auto_assignF                    User FileOfPEGs
    auto_assignG                    User GenomeID1 GenomeID2 ...
    between                         n1 n2 n3
    blast                           PEG  [against nr]
    blastit                         PEG seq db maxP
    boundaries_of                   Loc
    build_tree_of_complete          min_for_label   
    by_alias                        alias
    by_fig_id                       FID1 FID2
    cas                             CID
    cas_to_cid                      cas
    catalyzed_by                    RID
    catalyzes                       role
    cgi_url
    clean_tmp
    close_genes                     FID distance
    comp2react                      CID
    contig_ln                       GenomeID Contig
    coupling_and_evidence           FID Bound SimCutoff CouplingCutoff
    crude_estimate_of_distance      GenomeID1 GenomeID2
    delete_genomes                  G1 G2 G3 ...Gn
    displayable_reaction            RID
    dna_seq                         GenomeID Loc
    dsims                           FastaFile [MaxN MaxPsc Select]   *** select defaults to raw
    ec_to_maps                      EC
    ec_name                         EC
    expand_ec                       EC
    epoch_to_readable               [gives readable version of current time]
    export_chromosomal_clusters
    export_pch_pins
    export_set                      Relation SetName File
    exportable_subsystem            Subsystem
    extract_seq                     ContigsFile loc 
    all_exchangable_subsystems
    family_function                 Family
    fast_coupling                   FID Bound CouplingCutoff
    feature_aliases                 FID
    feature_annotations             FID
    feature_location                FID	
    file2N                          File
    ftype                           FID 
    function_of                     ID [all] [trans]
    genes_in_region                 GenomeID Contig Beg End 
    genome_of                       PEG
    genomes                         [complete|Pat]
    genome_counts                   [complete]
    genome_version                  GenomeID
    genus_species                   GenomeID
    get_translation                 ID
    get_translations                File [tab]
    h                               [command]  *** h h for help on how to use help ***
    hypo                            Function
    ids_in_family                   Family
    ids_in_set                      WhichSet Relation SetName
    in_cluster_with                 PEG
    in_family                       FID
    in_pch_pin_with                 FID
    in_sets                         Which Relation SetName
    is_archaeal                     GenomeID
    is_bacterial                    GenomeID
    is_eukaryotic                   GenomeID
    is_prokaryotic                  GenomeID
    is_exchangable_subsystem        Subsystem
    is_real_feature                 FID   
    largest_clusters                FileOfRoles user 
    load_all
    map_to_ecs                      map
    map_name                        map
    mapped_prot_ids                 ID
    maps_to_id                      ID 
    max                             n1 n2 n3 ...
    merged_related_annotations      PEG1 PEG2 ... PEGn
    min                             n1 n2 n3 ...
    names_of_compound
    neighborhood_of_role            role        
    org_of                          prot_id
    pegs_of                         GenomeID
    possibly_truncated              FID
    reaction2comp                   RID
    related_by_func_sim             PEG user
    reversible                      RID  
    rnas_of                         GenomeID
    roles_of_function               function
    search_index                    pattern
    seqs_with_role                  role who
    seqs_with_roles_in_genomes      genomes roles made_by
    sims                            PEG maxN maxP select
    sort_fids_by_taxonomy           FID1 FID2 FID3 ...
    sort_genomes_by_taxonomy        GenomeID1 GenomeID2 GenomeID3 ...
    sz_family                       family
    taxonomic_groups_of_complete    min_for_labels
    taxonomy_of                     GenomeID
    translatable                    prot_id
    translate_function              PEG user 
    translated_function_of          PEG user
    translation_length              ID
    unique_functions                PEGs user  [make the pegs comma separated]
    verify_dir                      dir
    
END
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3