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

View of /FigKernelScripts/FFB3_construct_assigned_functions.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Tue Jul 9 16:49:46 2013 UTC (6 years, 4 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Changes since 1.1: +1 -1 lines
FFB3_build_updated_FF: Add --temp to force use of given temp directory
Change hardcoded database host to seed-db-read for the annotator seed.

#
# Construct the table of assigned functions to use for the
# figfam generation.
#
# It is initialized first using the family functions from
# the raw subsystem families data generated by FFB3_make_subsys_based_families,
# then filled in with annotator seed functions then with pubseed functions.
#
# We write a sorted list of the function assignments, and then
# create a btree from them.
#

use FIG;
use strict;
use DB_File;
use YAML::Any 'LoadFile';
use DBI;

@ARGV == 3 or die "Usage: FFB3_construct_assigned_functions raw-families function-table function-btree";

my $raw_data = shift;
my $fn_file = shift;
my $fn_btree = shift;

my %funcs;

my $fig = FIG->new;

my $anno_dbh = DBI->connect('dbi:mysql:host=seed-db-read.mcs.anl.gov;database=fig_anno_v5', 'seed');
$anno_dbh or die;

open(my $fn_fh, ">", $fn_file) or die "Cannot write $fn_file: $!";

my %btree;
tie %btree, 'DB_File', $fn_btree, O_RDWR | O_CREAT, 0666, $DB_BTREE or die "tie $fn_fh failed: $!";

my $pubseed_dbh = $fig->db_handle->{_dbh};

if ($ENV{FFB3_TEST_MODE})
{
    $anno_dbh = DBI->connect('dbi:mysql:host=seed-db-read.mcs.anl.gov;database=fig_test1', 'seed');
    $pubseed_dbh = DBI->connect('dbi:mysql:host=seed-db-read.mcs.anl.gov;database=fig_test2', 'seed');
}

load_ss_data(\%funcs, $raw_data);
load_db_data(\%funcs, $anno_dbh);
load_db_data(\%funcs, $pubseed_dbh);

for my $peg (sort keys %funcs)
{
    print $fn_fh "$peg\t$funcs{$peg}\n";
    $btree{$peg} = $funcs{$peg};
}
close($fn_fh);
untie %btree;

sub load_db_data
{
    my($funcs, $dbh) = @_;

    my $sth = $dbh->prepare(qq(SELECT af.prot, af.assigned_function
			       FROM assigned_functions af LEFT OUTER JOIN deleted_fids df ON af.prot = df.fid
			       WHERE df.fid IS NULL AND af.prot LIKE 'fig|%'),
			{ mysql_use_result => 1 });
    $sth->execute();
    while (my $row = $sth->fetchrow_arrayref())
    {
	my($peg, $func) = @$row;
	if (!exists($funcs->{$peg}))
	{
	    $funcs->{$peg} = $func;
	}
    }
    $sth->finish();
}

sub load_ss_data
{
    my($funcs, $raw_data) = @_;
    
    my $data = LoadFile($raw_data);

    while (my($func, $phash) = each %$data)
    {
	$funcs->{$_} = $func foreach keys %$phash;
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3