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

View of /FigKernelScripts/load_features.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 strict;
use FIG;
my $fig = new FIG;

use DBrtns;


my $temp_dir = "$FIG_Config::temp";
my($organisms_dir) = "$FIG_Config::organisms";

my($genome,@types,$type,$id,$loc,@aliases,$aliases,$contig);

# usage: load_features [G1 G2 G3 ... ]

open(REL,">$temp_dir/tmpfeat$$") || die "could not open $temp_dir/tmpfeat$$";

my $dbf = $fig->{_dbf};



my @genomes;
if (@ARGV == 0)
{
    $dbf->drop_table( tbl => "features" );
    if ($FIG_Config::dbms eq "Pg")
    {
	$dbf->create_table( tbl  => "features",
			    flds => "id varchar(32) UNIQUE NOT NULL, type varchar(16),genome varchar(16),"  .
			            "location varchar(5000),"  .
			            "contig varchar(96), minloc INTEGER, maxloc INTEGER,"  .
			            "aliases TEXT, PRIMARY KEY ( id )"
			    );
    }
    elsif ($FIG_Config::dbms eq "mysql")
    {
	$dbf->create_table( tbl  => "features",
			    flds => "id varchar(32) UNIQUE NOT NULL, type varchar(16),genome varchar(16),"  .
			            "location TEXT,"  .
			            "contig varchar(96), minloc INTEGER, maxloc INTEGER,"  .
			            "aliases TEXT, PRIMARY KEY ( id )"
			    );
    }

    $dbf->create_index( idx  => "features_org_ix",
			tbl  => "features",
			type => "btree",
			flds => "genome" );
    $dbf->create_index( idx  => "features_type_ix",
			type => "btree",
			tbl  => "features",
			flds => "type" );
    $dbf->create_index( idx  => "features_beg_ix",
			type => "btree",
			tbl  => "features",
			flds => "genome,contig,minloc" );

    @genomes = $fig->genomes;
}
else
{
    @genomes = @ARGV;
}

foreach $genome (@genomes)
{
    opendir(FEAT,"$organisms_dir/$genome/Features") 
	|| die "could not open $genome/Features";
    @types = grep { $_ =~ /^[a-zA-Z]+$/ } readdir(FEAT);
    closedir(FEAT);

    foreach $type (@types)
    {
	if ((-s "$organisms_dir/$genome/Features/$type/tbl") &&
	    open(TBL,"<$organisms_dir/$genome/Features/$type/tbl"))
	{
#	    print STDERR "loading $genome/Features/$type/tbl\n";
	    while (defined($_ = <TBL>))
	    {
		chop;
		($id,$loc,@aliases) = split(/\t/,$_);
		if ($id)
		{
		    my($minloc,$maxloc);
		    if ($loc)
		    {
			$loc =~ s/\s+$//;
			($contig,$minloc,$maxloc) = &FIG::boundaries_of($loc);
			if ($minloc && $maxloc)
			{
			    ($minloc < $maxloc) || (($minloc,$maxloc) = ($maxloc,$minloc));
			}
		    }

		    if (! $contig)
		    { 
			$loc = $contig = $minloc = $maxloc = ""; 
		    }

		    if (@aliases > 0)
		    {
			$aliases = join(",",grep(/\S/,@aliases));
		    }
		    else
		    {
			$aliases = "";
		    }
		    $minloc = (! $minloc) ? 0 : $minloc;
		    $maxloc = (! $maxloc) ? 0 : $maxloc;
		    print REL "$id\t$type\t$genome\t$loc\t$contig\t$minloc\t$maxloc\t$aliases\n";
		}
	    }
	    close(TBL);
	}
    }
}
close(REL);

$dbf->load_table( tbl => "features",
                  file => "$temp_dir/tmpfeat$$" );

if (@ARGV == 0) {  $dbf->vacuum_it("features") }
unlink("$temp_dir/tmpfeat$$");

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3