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

View of /FigKernelScripts/generate_prolog_facts.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Tue Oct 30 00:27:29 2012 UTC (7 years ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Changes since 1.5: +0 -1 lines
no fields with tabs

# The process of generating a usable halo goes like this:
# 
# 	1. Get a file with genome IDs in the first "column"
# 
# 	2. Run 
# 		extract_halo_genomes -d Halo -f < genome.IDs
# 
# 	   This builds a directory representing the halo.  There is
# 	   a separate subdirectory for each entity-type or relationship type.
# 
# 	3.  Then run 
# 
# 		generate_prolog_facts Halo
# 
# 	    This builds a file for each entity or relationship type.
# 	    The file will be "facts.pl" placed in the appropriate
# 	    subdirectory.
# 
# 	4.  Then run 
# 
# 		make_supporting_predicates Halo > halo_support.pl
# 
#             This generates extraction/access predicates for the prolog
# 	    facts.
# 
# Then, move it all to the "prolog machine".  There, you run
# 
# 	perl compile_into_prolog.pl Halo saved_state
# 	sicstus
# 	| ?- restore(saved_state),compile(halo_support), compile(cs_predicates).
# 
# Then, you should have access to the entire framework.
# 

use strict;

my $usage = "usage: perl generate_prolog_facts.pl DataDirectory";
my($dir,$save);
(
 ($dir  = shift @ARGV)
)
    || die $usage;

opendir(DIR,"$dir") || die "could not open $dir";
my @ers = grep { $_ !~ /^\./ } readdir(DIR);
closedir(DIR);

foreach my $er (@ers)
{
    my $file = (-e "$dir/$er/entity") ? "$dir/$er/entity" : "$dir/$er/relationship";

    open(IN,"<$file") || die "could not open $file";
    open(TYPES,"<$dir/$er/types") || die "could not open $dir/$er/types";
    $_ = <TYPES>;
    chop;
    my @types = split(/\t/,$_);
    close(TYPES);
    open(OUT,">$dir/$er/facts.pl") || die "could not open $dir/$er/facts.pl";
    print STDERR "building $er/facts.pl\n";    
    while (defined($_ = <IN>))
    {
	chop;
	my @fields = split(/\t/,$_);
	my $i;
	for ($i=0; ($i < @types); $i++)
	{
	    $fields[$i] = &type_conv($fields[$i],$types[$i]);
	}
	my $fact = "'$er'(" .  join(",",@fields) . ").\n";
	print OUT $fact;
    }
    close(IN);
    close(OUT);
    print STDERR "\tbuilt\n";
}

sub type_conv {
    my($x,$type) = @_;

    if (! defined($x)) { $x = '' }
    $type =~ s/^[^,]*,//;
    if (($type eq "string") || ($type eq "text"))
    {
#	$x =~ s///g;
#	$x =~ s/—//g;
        $x =~ s/[^a-zA-Z0-9!#@$%&*\(\)+-\{\[}\]:\/;\.,? \n\|]/*/sg;
 	return "'$x'";
    }
    return $x;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3