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

View of /FigKernelScripts/load_attributes.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Sun Feb 27 01:39:55 2005 UTC (15 years, 1 month ago) by overbeek
Branch: MAIN
Changes since 1.2: +60 -13 lines
major changes in notion of function and load_attributes

use FIG;
my $fig = new FIG;

my $dbf = $fig->{_dbf};
$dbf->drop_table( tbl => "attribute" );
$dbf->create_table( tbl => 'attribute',
		    flds => "fid varchar(64), tag varchar(64), val text, url text"
		    );

my(%kv,$genome);
foreach $genome ($fig->genomes)
{
    undef %kv;
    my $dir = "$FIG_Config::organisms/$genome/Features/peg/Attributes";
    if (opendir(ATTR,$dir))
    {
	my @files = grep { $_ !~ /^\./ } readdir(ATTR);
	closedir(ATTR);

	my $i;
	for ($i=0; ($files[$i] ne "assigned_attributes"); $i++) {}
	if ($i < @files)
	{
	    splice(@files,$i,1);
	    push(@files,"assigned_attributes");
	}

	my $file;
	foreach $file (@files)
	{
	    if ((-s "$dir/$file") && open(TMPATTR,"<$dir/$file"))
	    {
		while (defined($_ = <TMPATTR>))
		{
		    if ($_ =~ /^(\S+)\t(\S+)\t(.*)$/)
		    {
			if ($3)
			{
			    $kv{"$1\t$2"} = $3;
			}
			else
			{
			    delete $kv{"$1\t%2"};
			}
		    }
		}
		close(TMPATTR);
	    }
	}
	if (open(TMPATTR,">$FIG_Config::temp/tmp$$"))
	{
	    my($pegK,$k,$v);
	    foreach $pegK (sort keys(%kv))
	    {
		($peg,$k) = split(/\t/,$pegK);
		$v = $kv{$pegK};
		print TMPATTR "$peg\t$k\t$v\n";
	    }
	    close(TMPATTR);
	    $dbf->load_table( tbl => "attribute",
			      file => "$FIG_Config::temp/tmp$$" );
	    unlink("$FIG_Config::temp/tmp$$");
	}
	else
	{
	    die "$FIG_Config::temp/tmp$$";
	}

    }
}
$dbf->create_index( idx  => "attribute_fid_ix",
		    tbl  => "attribute",
		    type => "btree",
		    flds => "fid" 
		  );

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3