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

View of /FigKernelScripts/fig_net.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Mon Dec 1 20:46:40 2003 UTC (16 years ago) by efrank
Branch: MAIN
CVS Tags: V00-00-01, delong-01, delong-02, V00-00-00

Makefile:
	get it to work with the release tools

All the rest:
	had to rename foo to foo.pl so that makefiles could recognize
	perl source from, say, Makefiles and READMEs

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

use FIGnet;
use FIG;

my($user);

# usage: fig $url [-echo] [-time] [command]

defined($url = shift @ARGV)
    || die "usage: fig $url [-echo] [-time] [command]";

$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);
if (@ARGV > 0)  { $req = join( " ", @ARGV ); }
while ( (defined($req) && $req) || ($req = &get_req) )
{
    if ($time_cmds)
    {
	$t1 = gettimeofday;
    }

    if ($req =~ /^\s*genomes(\s+(\S.*\S))?\s*$/)
    {
	$pat = $2;
	foreach $genome ($figN->genomes)
	{
	    my $genus_species = $fig->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 &Dumper($figN->seqs_with_roles_in_genomes($genomes,$roles,$who));
	print "\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;
    Those not implemented yet are marked with an *:

*   add_annotation                  FID User [ prompted for annotation; terminate with "." at start of line ]
*   add_chromosomal_clusters        File
*   add_pch_pins                    File
    all_maps                      
    all_protein_families
*   assign_function                 PEG User [conf=X] Function
*   assign_functionF                User File
*   auto_assign                     PEG [Seq]
*   blast                           PEG  [against nr]
*   cas                             cid
*   cas_to_cid                      cas
    catalyzed_by                    rid
    catalyzes                       role
    comp2react                      cid
*   contig_ln                       Genome Contig
*   coupling_and_evidence           Fid Bound SimCutoff CouplingCutoff
*   dna_seq                         Genome Loc
*   dsims                           FastaFile [MaxN MaxPsc Select]   *** select defaults to raw
*   ec_to_maps                      EC
*   family_function                 Family
*   feature_annotations             FID
*   feature_location                Fid	
    all_compounds               
*   all_features                    Genome Type
    all_reactions
*   function_of                     ID [all]
*   genes_in_region                 Org Contig Beg End 
*   genome_of                       Prot
    genomes                         [Pat]
*   genome_version                  Genome
*   genus_species                   Org
*   get_translation                 ID
    h                               [command]  *** h h for help on how to use help ***
*   ids_in_family                   Family
*   in_cluster_with                 Peg
*   in_family                       Fid
    map_to_ecs                      map
*   map_name                        map
*   mapped_prot_ids                 ID
    names_of_compound               cid
    names_of_compounds
*   neighborhood_of_role            Role
*   org_of                          ID
    reaction2comp                   rid
*   restricted
    reversible                      rid
    seqs_with_roles_in_genomes      GenomesFile RolesFile Who
*   sims                            ID [MaxN MaxPsc Select]   *** select defaults to raw
*   sz_family                       Family
*   taxonomy_of                     Org
*   translation_length              ID
    
END
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3