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

View of /FigKernelScripts/make_supporting_predicates.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Mon Oct 29 17:32:07 2012 UTC (7 years ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Changes since 1.2: +1 -0 lines
handle minor issue with compound predicate

# 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;
use Data::Dumper;
use String::CamelCase qw(camelize decamelize wordsplit);

my $dir;
my $usage = "usage: perl make_supporting_predicates ExampleDir";
(
 ($dir = shift @ARGV) && (-d $dir)
)
    || die $usage;

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

my %by_pred;

foreach my $x (@er)
{
    my $entity = -e "$dir/$x/entity";
    open(TYPES,"<$dir/$x/types") || die "could not open $dir/$x/types";
    my $types = <TYPES>;
    chop $types;
    my @types = map { [split(/,/,$_)] } split(/\t/,$types);
    my @args = map { '_' . $_->[0] } @types;
    my $i;
    for ($i=0; ($i < @types); $i++)
    {
	my $tuple = $types[$i];
	my($field,$type) = @$tuple;
	$field = lc $field;
	if ($field eq "id")
	{
	    $args[$i] = "ID";
	}
	elsif  ($field eq "from_link")
	{
	    $args[$i] = 'ID1';
	}
	elsif  ($field eq "to_link")
	{
	    $args[$i] = 'ID2';
	}
	else
	{
	    $args[$i] = "_" . $field;
	}
    }

    my $extractor = "'$x'(" . join(",",@args) . ")";
    my $node = &decamelize($x);
    if ($node eq 'compound') { $node = 'cpd' }  # handle conflict with prolog primitive
    if ($entity)
    {
	print "$node(ID) :- $extractor.\n\n";
    }
    else
    {
	print "$node(ID1,ID2) :- $extractor.\n\n";
    }

    for ($i=0; ($i < @types); $i++)
    {
	my $tuple = $types[$i];
	my($field,$type) = @$tuple;
	$field = lc $field;
	if ($args[$i] !~ /^ID[12]?$/)
	{
	    my $save = $args[$i];
	    $args[$i] = 'X';
	    my $extractor = "'$x'(" . join(",",@args) . ")";
	    push(@{$by_pred{$field}},[$entity,$field,$x,$extractor]);
	    $args[$i] = $save;
	}
    }
}
	
foreach my $pred (sort keys(%by_pred))
{
    my $x = $by_pred{$pred};
    foreach my $tuple (@$x)
    {
	my($entity,$field,$er,$extractor) = @$tuple;
	my $node = &decamelize($er);
	my $long_field = $node . "_" . $field;

	if ($entity)
	{
	    print "$long_field(ID,";
	}
	else
	{
	    print "$long_field(ID1,ID2,";
	}
	print "X) :- $extractor.\n";
	print "\n";
    }
}

	

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3