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

View of /FigKernelScripts/figfam.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (download) (as text) (annotate)
Thu Nov 11 17:43:21 2010 UTC (9 years ago) by disz
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.22: +6 -6 lines
FigFam 6 digit problem

########################################################################
# -*- perl -*-
#
# Copyright (c) 2003-2006 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 Carp;
use Data::Dumper;
use gjoseqlib;

use DB_File;

use FIG;
my $fig = new FIG;

use FigFam;

# usage: figfam [FAMdir]

my $default_dir;
if (@ARGV > 0)
{
    $default_dir = $ARGV[0];
}
else
{
    $default_dir = &FIG::get_figfams_data();
}


use FigFams;
my $figfams = new FigFams($fig,$default_dir);

my $figfam;
my($fam_id,$dir);
while ($req = &get_req)
{
    if ($req =~ /^\s*set\s+(FIG\d+)(\s+\S.*\S)?\s*$/)
    {
	$fam_id = $1;
	$dir = $2 ? $2 : $default_dir;

	$figfam = new FigFam($fig,$fam_id,$dir);

	$figfam
	    || warn "could not handle $fam_id in $dir\n";
    }
    elsif ($req =~ /^\s*display(\s+(FIG\d+))?\s*$/)
    {
	if ($2)
	{
	    $fam_id = $2;
	    $figfam = new FigFam($fig,$fam_id,$default_dir);
	}
	print $figfam->display;
    }
    elsif ($req =~ /^\s*alignment(\s+(FIG\d+))?\s*$/)
    {
	if ($2)
	{
	    $fam_id = $2;
	    $figfam = new FigFam($fig,$fam_id,$default_dir);
	}
	my $ali;
	if ($figfam && ($ali = $figfam->alignment))
	{
	    print "---------\n";
	    foreach $_ (@$ali)
	    {
		print join("\t",($_->[0],$_->[2])),"\n";
	    }
	    print "---------\n";
	}
	else
	{
	    print "alignment is undefined\n";
	}
    }
    elsif ($req =~ /^\s*reset_function(\s+(\S.*\S))?\s*$/)
    {
	$debug = 0;
	if ($2)
	{
	    my $args = $2;
	    if ($args =~ /(FIG\d+)/) { $fam_id = $1 }
	    if ($args =~ /debug/i)     { $debug = 1 }
	    $figfam = new FigFam($fig,$fam_id,$default_dir);
	}
	print "reset to ",$figfam->reset_function($debug),"\n";
    }
    elsif ($req =~ /^\s*family_function(\s+(\S+))?\s*/)
    {
	if ($2)
	{
	    my $fam_id = $2;
	    $figfam = new FigFam($fig,$fam_id,$default_dir);
	}

	if (defined($figfam)) 
	{
	    print $figfam->family_function,"\n";
	}
	else
	{
	    print STDERR "you need to set the family first or give a family id\n";
	}
    }
    elsif ($req =~ /^\s*should_be_member\s+(\S+)(\s+(\S+))?\s*/)
    {
	$seq = $1;
	if ($3)
	{
	    my $fam_id = $3;
	    $figfam = new FigFam($fig,$fam_id,$default_dir);
	}

	if (defined($figfam)) 
	{
	    print &Dumper($figfam->should_be_member($seq));
	}
	else
	{
	    print STDERR "you need to set the family first or give a family id\n";
	}
    }
    elsif ($req =~ /^\s*load\s+(\S+)(\s+\S.*\S)?/)
    {
	my $file = $1;

	my $dir = $2;
	my @args;
	if ($dir)
	{
	    $dir =~ s/^\s+//;
	    @args = ("$dir/FIGFAMS","$dir/families.2c");
	}
	else
	{
	    @args = ($default_dir,"$default_dir/families.2c");
	}

	foreach $line (`cat $file`)
	{
	    if ($line =~ /^\s*(FIG\d+)/)
	    {
		$fam_id = $1;
		$figfam = new FigFam($fig,$fam_id,@args);
		
		$figfam
		    || warn "could not handle $dir\n";
		print STDERR "loaded $fam_id\n";
	    }
	}
    }
    elsif ($req =~ /^\s*families_in_genome\s+(\d+\.\d+)\s*$/)
    {
	my $genome = $1;
	my @fams = $figfams->families_in_genome($genome);
	foreach $_ (@fams)
	{
	    print "$_\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*place_in_family\s+(\S+)\s*$/)
    {
	($famO,undef) = $figfams->place_in_family($1);
	if ($famO)
	{
	    print join("\t",$famO->family_id,$famO->family_function),"\n";
	}
	else
	{
	    print "could not place it\n";
	}
    }
    elsif ($req =~ /^\s*families_with_function\s+(\S.*\S)\s*$/)
    {
	my $function = $1;
	my @fams = $figfams->families_with_function($function);
	foreach $_ (@fams)
	{
	    print "$_\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*families_with_functional_role\s+(\S.*\S)\s*$/)
    {
	my $functional_role = $1;
	my @fams = $figfams->families_with_functional_role($functional_role);
	foreach $_ (@fams)
	{
	    print "$_\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*rebuild_dbs\s*$/)
    {
	$figfams->rebuild_dbs;
    }
    elsif ($req =~ /^\s*check_fams\s*$/)
    {
	$figfams->check_fams;
    }
    elsif ($req =~ /^\s*rebuild_repdb\s*$/)
    {
	$figfams->rebuild_repdb;
	print "rebuilt repdb\n";
    }
    elsif ($req =~ /^\s*rebuild_family_funcs\s*$/)
    {
	$figfams->rebuild_family_funcs;;
	print "rebuilt family.functions\n";
    }
    elsif ($req =~ /^\s*families_containing_peg\s+(\S+)\s*$/)
    {
	$peg = $1;
	my @families = $figfams->families_containing_peg($peg);
	foreach $fam_id (@families)
	{
	    $famO = new FigFam($fig,$fam_id);
	    $fam_func = $famO->family_function;
	    print "$fam_id\t$fam_func\n";
	}
	print "\n";
    }
    elsif ($req =~ /^\s*families_implementing_role\s+(\S.*\S)\s*$/)
    {
	my $role = $1;
	my @fams = $figfams->families_implementing_role($role);
	print join(",",@fams),"\n";
    }
    elsif ($req =~ /^\s*next_id\s*$/)
    {
	print $figfams->next_id,"\n\n";
    }
    elsif ($req =~ /^\s*reset_functions\s*$/)
    {
	$figfams->reset_functions;
    }
    elsif ($req =~ /^\s*clean_and_split\s+(FIG\d+)\s*$/)
    {
	$first_new = $figfams->next_id;
	$figfams->clean_and_split($1);
	$next      = $figfams->next_id;
	while ($first_new lt $next)
	{
	    $figfam = new FigFam($fig,$first_new,$default_dir);
	    my $func = $figfam->family_function;
	    print "ADDED\t$first_new\t$func\n";
	    $first_new++;
	}
    }
    elsif ($req =~ /^\s*h\s*$/ || $req =~ /^\s*help\s*$/)
    {
     &help;
    }
    else
    {
	print "invalid command\n";
    }
    print "\n";
}

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;
    
    h                               
    alignment                        FamID
    check_fams
    clean_and_split                  FamID
    display                          [FamID]
    families_containing_peg          PEG
    families_implementing_role       Role
    families_in_genome               GENOME
    families_with_function           Function
    families_with_functional_role    FunctionalRole
    family_function                  [FamID]
    load                             FamIDfile [Dir]
    next_id
    rebuild_dbs
    rebuild_family_funcs
    rebuild_repdb
    reset_function                   [famID] [debug]
    reset_functions
    set                              FamID [Dir]
    should_be_member Seq             [FamID]

END
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3