exhibits(A, B), is_a(A,C) => exhibits(C, B)
We have documented this on the wiki [1]. In addition, we also use
'character_slim' subsets of qualities to generate character-quality
pairs such as
(count, absence), (count, presence), (shape, flat) and such. These are
specific to the Phenoscape project. So we could do our own thing and
also leverage changes to the OBD reasoner without getting everything
mixed up.
[1] https://www.nescent.org/phenoscape/OBD_Reasoner
Regards,
Cartik
Chris Mungall wrote:
>
> any reason why you need your own reasoner script?
>
> On Aug 7, 2009, at 8:51 AM, cart...@users.sourceforge.net wrote:
>
>> Revision: 2790
>> http://obo.svn.sourceforge.net/obo/?rev=2790&view=rev
>> Author: cartik73
>> Date: 2009-08-07 15:51:18 +0000 (Fri, 07 Aug 2009)
>>
>> Log Message:
>> -----------
>> Moved OBD generic aspects out of this reasoner. Only those facets which
>> are useful for Phenoscape remain
>>
>> Modified Paths:
>> --------------
>> OBDAPI/trunk/scripts/phenoscape-obd-reasoner.pl
>>
>> Modified: OBDAPI/trunk/scripts/phenoscape-obd-reasoner.pl
>> ===================================================================
>> --- OBDAPI/trunk/scripts/phenoscape-obd-reasoner.pl 2009-08-07
>> 15:49:56 UTC (rev 2789)
>> +++ OBDAPI/trunk/scripts/phenoscape-obd-reasoner.pl 2009-08-07
>> 15:51:18 UTC (rev 2790)
>> @@ -3,13 +3,6 @@
>> use DBI;
>> use FileHandle;
>>
>> -#THIS IS A TEMPORARY COPY OF THE MAIN REASONER WHICH SHOULD BE PARED
>> DOWN TO THE DIFFERENCES
>> -
>> -# TODO: replace inferred links when ontology changes (just get rid
>> of inferences with any dependencies on updated ontology?)
>> -# TODO: keep other properties in inference; eg reiflink??
>> -
>> -# TODO: more robust w.r.t cycles; eg MP-XP-towards, FMA-has_part
>> -
>> my $d;
>> my $dbhost = '';
>> my $uid;
>> @@ -56,6 +49,10 @@
>> elsif ($opt eq '-h' || $opt eq '--host') {
>> $dbhost = shift @ARGV;
>> }
>> + elsif ($opt eq '-?' || $opt eq '--help') {
>> + print usage();
>> + exit 0;
>> + }
>> elsif ($opt eq '--split') {
>> $split = shift @ARGV;
>> }
>> @@ -84,15 +81,24 @@
>> if (!$d) {
>> $d = shift @ARGV;
>> }
>> +if (!$d) {
>> + die "No database specified\n";
>> + exit(1);
>> +}
>>
>> my $time_started = time;
>>
>> -
>> -
>> my $dbh;
>> if ($d =~ /^dbi:/) {
>> $dbh = DBI->connect($d);
>> }
>> +elsif ($d =~ /^jdbc:postgresql:\/\/(.*):(\d+)/) {
>> + $dbh = DBI->connect("dbi:Pg:dbname=$d;host=$1;port=$2");
>> +}
>> +elsif ($d =~ /\@/) {
>> + require 'DBIx::DBStag';
>> + $dbh = DBIx::DBStag->connect($d);
>> +}
>> else {
>> $dbh = DBI->connect("dbi:Pg:dbname=$d;host=$dbhost",$uid,$pwd);
>> }
>> @@ -101,172 +107,8 @@
>> delete_inferred_links();
>> }
>>
>> -my @is_a_nodes =
>> - $dbh->selectrow_array("SELECT node_id FROM node WHERE
>> uid='OBO_REL:is_a'");
>> -if (@is_a_nodes != 1) {
>> - die "@is_a_nodes";
>> -}
>> -my $is_a = shift @is_a_nodes;
>> +my @views;
>>
>> -my @instance_of_nodes =
>> - $dbh->selectrow_array("SELECT node_id FROM node WHERE
>> uid='OBO_REL:instance_of'");
>> -if (@instance_of_nodes != 1) {
>> - if ($infer_instance_of) {
>> - die "expected 1 instance_of node. Got: @instance_of_nodes";
>> - }
>> -}
>> -my $instance_of = shift @instance_of_nodes;
>> -
>> -
>> -
>> -# TODO: use this below
>> -my @transitive_relation_node_ids =
>> - $dbh->selectrow_array("SELECT node_id FROM node WHERE
>> is_transitive='t'");
>> -
>> -
>> -my $lj=qq[
>> - LEFT JOIN link AS existing_link
>> - ON (x.node_id=existing_link.node_id AND
>> - x.predicate_id=existing_link.predicate_id AND
>> - y.object_id=existing_link.object_id)
>> -];
>> -my $lj_cond = "AND existing_link.link_id IS NULL";
>> -
>> -# TODO: transitive_over and relation compositions
>> -my @views =
>> - (
>> - {id=>'transitivity',
>> - rule=>"transitive(R), A R B, B R C, => A R C",
>> - sql=>qq[
>> - SELECT DISTINCT
>> - x.node_id AS node_id,
>> - x.predicate_id AS predicate_id,
>> - y.object_id AS object_id
>> - FROM inheritable_link AS x
>> - INNER JOIN inheritable_link AS y
>> - ON (x.object_id=y.node_id AND x.predicate_id=y.predicate_id)
>> - INNER JOIN relation_node AS r
>> - ON (x.predicate_id=r.node_id)
>> - $lj
>> - WHERE r.is_transitive='t'
>> - $lj_cond
>> -],
>> - },
>> - {id=>'isa1',
>> - rule=>"A is_a B, B R C => A R C",
>> - sql=>qq[
>> - SELECT DISTINCT
>> - x.node_id AS node_id,
>> - y.predicate_id AS predicate_id,
>> - y.object_id AS object_id
>> - FROM inheritable_link AS x
>> - INNER JOIN inheritable_link AS y ON (x.object_id=y.node_id)
>> - LEFT JOIN link AS existing_link
>> - ON (x.node_id=existing_link.node_id AND
>> - y.predicate_id=existing_link.predicate_id AND
>> - y.object_id=existing_link.object_id)
>> - WHERE x.predicate_id = $is_a
>> - $lj_cond
>> -],
>> - },
>> - {id=>'isa2',
>> - rule=>"A R B, B is_a C => A R C",
>> - sql=>qq[
>> - SELECT DISTINCT
>> - x.node_id AS node_id,
>> - x.predicate_id AS predicate_id,
>> - y.object_id AS object_id
>> - FROM inheritable_link AS x
>> - INNER JOIN inheritable_link AS y ON (x.object_id=y.node_id)
>> - $lj
>> - WHERE y.predicate_id = $is_a
>> - $lj_cond
>> -],
>> - },
>> - {id=>'isa*',
>> - rule=>"A is_a A: reflexivity", # we do not implement other
>> reflexive relations for now
>> - sql=>qq[
>> - SELECT DISTINCT
>> - node.node_id AS node_id,
>> - $is_a AS predicate_id,
>> - node.node_id AS object_id
>> - FROM node
>> - LEFT JOIN inheritable_link AS existing_link
>> - ON (node.node_id=existing_link.node_id AND
>> - $is_a=existing_link.predicate_id AND
>> - node.node_id=existing_link.object_id)
>> - WHERE
>> - (node.metatype='C' OR node.metatype = 'I') AND
>> - node.source_id IS NOT NULL
>> - $lj_cond
>> -],
>> - },
>> - {id=>'subrelations',
>> - rule=>"A R B, R is_a R2 => A R2 B: reflexivity",
>> - sql=>qq[
>> - SELECT DISTINCT
>> - x.node_id AS node_id,
>> - subrel.object_id AS predicate_id,
>> - x.object_id AS object_id
>> - FROM subrelation_link AS subrel
>> - INNER JOIN inheritable_link AS x
>> - ON (subrel.node_id=x.predicate_id)
>> - LEFT JOIN link AS existing_link
>> - ON (x.node_id=existing_link.node_id AND
>> - subrel.object_id=existing_link.predicate_id AND
>> - x.object_id=existing_link.object_id)
>> - WHERE true
>> - $lj_cond
>> -],
>> - }
>> -
>> - );
>> -
>> -if (%ruleconf) {
>> - @views = grep {$ruleconf{$_->{id}}} @views;
>> -}
>> -
>> -unless ($skip{chain}) {
>> - # TODO: make this generic - use role chains
>> - my @relation_chains =
>> - (
>> -
>> ['OBO_REL:inheres_in_part_of','OBO_REL:inheres_in','OBO_REL:part_of'],
>> - ['OBO_REL:inheres_in_part_of','OBO_REL:inheres_in','part_of'],
>> - );
>> -
>> - foreach my $rule (@relation_chains) {
>> - my $rel = shift @$rule;
>> - my @chain = @$rule;
>> - if (@chain != 2) {
>> - die "$rel must have 2 in chain: got: @chain";
>> - }
>> - my $r1id = get_or_put_relation(shift @chain);
>> - my $r2id = get_or_put_relation(shift @chain);
>> - my $rid = get_or_put_relation($rel);
>> - my $sql =
>> - qq[
>> - SELECT DISTINCT
>> - x.node_id AS node_id,
>> - $rid AS predicate_id,
>> - y.object_id AS object_id
>> - FROM inheritable_link AS x
>> - INNER JOIN inheritable_link AS y ON (x.object_id=y.node_id)
>> - $lj
>> - WHERE x.predicate_id = $r1id
>> - AND y.predicate_id = $r2id
>> - $lj_cond
>> -];
>> - push(@views,
>> - {id=>$rel,
>> - rule=>"$rel = ".join(' * ',@chain),
>> - sql=>$sql});
>> - }
>> -}
>> -
>> -if ($skip{rules}) {
>> - @views = ();
>> -}
>> -
>> {
>> my @quality_ontology_nodes = $dbh->selectrow_array("SELECT node_id
>> FROM node WHERE uid = 'quality'");
>> my @character_slim_ontology_nodes = $dbh->selectrow_array("SELECT
>> node_id FROM node WHERE uid = 'character_slims'");
>> @@ -343,74 +185,13 @@
>> });
>> }
>>
>> -foreach my $view (@inference_views) {
>> -
>> - my $sql =
>> - qq[
>> - SELECT DISTINCT
>> - x.node_id ,
>> - x.predicate_id,
>> - x.object_id
>> - FROM $view AS x
>> - LEFT JOIN link AS existing_link
>> - ON (x.node_id=existing_link.node_id AND
>> - x.predicate_id=existing_link.predicate_id AND
>> - x.object_id=existing_link.object_id)
>> - WHERE
>> - existing_link.link_id IS NULL
>> -
>> -];
>> - push(@views,
>> - {id=>$view,
>> - rule=>"$view",
>> - sql=>$sql});
>> -}
>> -
>> my $sth_link = $dbh->prepare_cached("SELECT link_id FROM LINK WHERE
>> node_id=? AND predicate_id=? AND object_id=?");
>> my $sth_store = $dbh->prepare_cached("INSERT INTO link
>> (node_id,predicate_id,object_id,is_inferred) VALUES (?,?,?,'t')");
>>
>> -my $i_by_node_id = get_intersections();
>> -foreach my $node_id (keys %$i_by_node_id) {
>> - if ($test_intersection && $node_id != $test_intersection) {
>> - next;
>> - }
>> - my $intersection_h = $i_by_node_id->{$node_id};
>> - my $sql = intersection_to_query($node_id,$intersection_h);
>> - # print STDERR "$sql\n";
>> - # we do this at the start - unless new intersections can be added
>> - unshift(@views,
>> - {id=>"intersection_for_$node_id",
>> - sql=>$sql});
>> - if ($infer_instance_of) {
>> - my $sql = intersection_to_query($node_id,$intersection_h,1);
>> - # print STDERR "$sql\n";
>> - # we do this at the start - unless new intersections can be
>> added
>> - unshift(@views,
>> - {id=>"instance_intersection_for_$node_id",
>> - sql=>$sql});
>> - }
>> -
>> -
>> +foreach my $view (@views) {
>> + my $links_added = cache_view($view);
>> }
>>
>> -my $done = 0;
>> -my $sweep = 0;
>> -unless ($skip{sweep}) {
>> - while (!$done) {
>> - logmsg( "Sweep: $sweep" );
>> - my $links_added_this_sweep = 0;
>> - foreach my $view (@views) {
>> - my $links_added = cache_view($view);
>> - $links_added_this_sweep += $links_added;
>> - }
>> - logmsg( "Sweep: $sweep total_added: $links_added_this_sweep" );
>> - $done = 1 unless $links_added_this_sweep;
>> - }
>> -}
>> -unless ($skip{equivalence}) {
>> - &assert_sameas();
>> -}
>> -
>> my $time_finished = time;
>>
>> printf STDERR "Started: %d Finished: %d Duration: %d\n",
>> $time_started, $time_finished, $time_finished - $time_started;
>> @@ -449,12 +230,10 @@
>> $link->{predicate_id},
>> $link->{object_id});
>>
>> - if (($triple[0] == $triple[2]) && ($view_id ne 'isa*')
>> && ($view_id ne 'value_for')) {
>> + if (($triple[0] == $triple[2]) && ($view_id ne
>> 'value_for')) {
>> # TODO: proper reflexivity rules. hardcode OK for
>> is_a for now
>> # also: will report cycles for intersections to self,
>> which is normal?
>> #
>> - # this gives us lots of spurious messages for GALEN,
>> since the obo translation
>> - # uses anonymous IDs and class expression syntax
>> # Changed this to add reflexive links with
>> 'value_for' predicate between characters: Cartik 05/08/09
>> logmsg(" Cycle detected for node: $triple[0] pred:
>> $triple[1]");
>> next;
>> @@ -480,115 +259,6 @@
>> return $view_links_added;
>> }
>>
>> -sub assert_sameas {
>> - logmsg("fetching reciprocal subclass links");
>> - my $eqs =
>> - $dbh->selectall_arrayref("SELECT DISTINCT x.node_id,
>> x.object_id FROM link AS x INNER JOIN link AS y ON
>> (y.object_id=x.node_id AND x.object_id=y.node_id) WHERE
>> x.predicate_id=$is_a AND y.predicate_id=$is_a AND x.node_id !=
>> x.object_id", {Slice=>{}});
>> - logmsg("got reciprocal subclass links: ".scalar(@$eqs));
>> - foreach (@$eqs) {
>> - $dbh->do("INSERT INTO sameas (node_id,object_id,is_inferred)
>> VALUES ($_->{node_id},$_->{object_id},'t')");
>> - $dbh->do("INSERT INTO sameas (object_id,node_id,is_inferred)
>> VALUES ($_->{node_id},$_->{object_id},'t')");
>> - }
>> - logmsg("done sameas");
>> -}
>> -
>> -# TODO: unions
>> -sub get_intersections {
>> - my $i_by_node_id = {};
>> - unless ($skip{intersections}) {
>> - my $ilinks = $dbh->selectall_arrayref("SELECT DISTINCT
>> node_id,predicate_id,object_id,combinator FROM link WHERE
>> combinator='I'",{Slice=>{}});
>> - foreach (@$ilinks) {
>> - push(@{$i_by_node_id->{$_->{node_id}}}, $_);
>> - }
>> - }
>> - return $i_by_node_id;
>> -}
>> -
>> -sub intersection_to_query {
>> - my $defined_node_id = shift;
>> - my $i_h = shift;
>> - my $is_inst = shift;
>> - my @conds = @$i_h;
>> - my $linknum=0;
>> - my @links = ();
>> -
>> - # TODO: remember, is_a is reflexive..
>> - # TODO: sub-relations
>> - my $where =
>> - join(" AND ",
>> - map {
>> - $linknum++;
>> - my $link = "link_".$linknum;
>> - push(@links,"link AS $link");
>> - my $q;
>> - my $pred_id = $_->{predicate_id};
>> - if ($is_inst) {
>> - if ($pred_id == $is_a) {
>> - $pred_id = $instance_of;
>> - $q = "$link.node_id=subsumed_node.node_id AND
>> $link.predicate_id = $instance_of AND $link.object_id =
>> $_->{object_id} AND $link.combinator!='U'";
>> - }
>> - else {
>> - $q = "$link.node_id=subsumed_node.node_id AND
>> $link.predicate_id = $pred_id AND $link.object_id IN (SELECT node_id
>> FROM instantiation_link WHERE object_id= $_->{object_id}) AND
>> $link.combinator!='U'";
>> - }
>> - }
>> - else {
>> - $q = "$link.node_id=subsumed_node.node_id AND
>> $link.predicate_id = $pred_id AND $link.object_id = $_->{object_id}
>> AND $link.combinator!='U'";
>> - }
>> - # TODO: omit negation links
>> - $q;
>> - } @conds);
>> - my $from = join(', ',@links);
>> -
>> - my $inf_pred_id = $is_inst ? $instance_of : $is_a;
>> -
>> - my $sql =
>> - qq[
>> - SELECT DISTINCT
>> - subsumed_node.node_id AS node_id,
>> - $inf_pred_id AS predicate_id,
>> - $defined_node_id AS object_id
>> - FROM node AS subsumed_node, $from
>> - WHERE
>> - $where
>> - ];
>> - return $sql;
>> -}
>> -
>> -sub delete_inferred_links {
>> - my $link_ids = $dbh->selectcol_arrayref("SELECT link_id FROM
>> link WHERE is_inferred='t'");
>> - $dbh->{AutoCommit}=0;
>> - my $n=0;
>> - foreach my $link_id (@$link_ids) {
>> - print STDERR "Deleting $link_id\n";
>> - $dbh->do("DELETE FROM link WHERE link_id=$link_id");
>> - $n++;
>> - if ($n % 1000 == 0) {
>> - print STDERR "COMMITTING\n";
>> - $dbh->commit;
>> - }
>> - }
>> - $dbh->commit;
>> - print STDERR "Deleted all inferred links\n";
>> -}
>> -
>> -sub get_or_put_relation {
>> - my $rel = shift;
>> - my @nids =
>> - $dbh->selectrow_array("SELECT node_id FROM node WHERE
>> uid='$rel'");
>> - if (@nids == 1) {
>> - return $nids[0];
>> - }
>> - elsif (@nids > 1) {
>> - die "@nids";
>> - }
>> - else {
>> - $dbh->do("INSERT INTO node (uid,metatype) VALUES
>> ('$rel','R')");
>> - return get_or_put_relation($rel);
>> - }
>> -
>> -}
>> -
>> -
>> sub logmsg {
>> return unless $verbose;
>> my $msg = shift;
>>
>>
>> This was sent by the SourceForge.net collaborative development
>> platform, the world's largest Open Source development site.
>>
>> ------------------------------------------------------------------------------
>>
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and
>> focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Obo-svn-commit mailing list
>> Obo-svn...@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/obo-svn-commit
>>
>