| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # $Id: CrossProduct.pm,v 1.2 2004/11/24 02:28:01 cmungall Exp $ | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | # This GO module is maintained by Chris Mungall | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # see also - http://www.geneontology.org | 
| 6 |  |  |  |  |  |  | #          - http://www.godatabase.org/dev | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | # You may distribute this module under the same terms as perl itself | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | package GO::Model::CrossProduct; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =head1 NAME | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | GO::Model::CrossProduct; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | for cross products - an intersection between another class/term and a | 
| 21 |  |  |  |  |  |  | list of anonymous subclass over some restrictions | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =cut | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 14 |  |  | 14 |  | 81 | use Carp qw(cluck confess); | 
|  | 14 |  |  |  |  | 239 |  | 
|  | 14 |  |  |  |  | 862 |  | 
| 27 | 14 |  |  | 14 |  | 77 | use Exporter; | 
|  | 14 |  |  |  |  | 72 |  | 
|  | 14 |  |  |  |  | 552 |  | 
| 28 | 14 |  |  | 14 |  | 74 | use GO::Utils qw(rearrange); | 
|  | 14 |  |  |  |  | 35 |  | 
|  | 14 |  |  |  |  | 733 |  | 
| 29 | 14 |  |  | 14 |  | 92 | use GO::Model::Root; | 
|  | 14 |  |  |  |  | 33 |  | 
|  | 14 |  |  |  |  | 329 |  | 
| 30 | 14 |  |  | 14 |  | 72 | use strict; | 
|  | 14 |  |  |  |  | 29 |  | 
|  | 14 |  |  |  |  | 569 |  | 
| 31 | 14 |  |  | 14 |  | 68 | use vars qw(@ISA); | 
|  | 14 |  |  |  |  | 26 |  | 
|  | 14 |  |  |  |  | 12295 |  | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | @ISA = qw(GO::Model::Root Exporter); | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub _valid_params { | 
| 37 | 0 |  |  | 0 |  |  | return qw(xp_acc parent_acc restriction_list); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub get_restriction_values_for_property { | 
| 41 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 42 | 0 |  |  |  |  |  | my $prop = shift; | 
| 43 | 0 |  |  |  |  |  | my @vals = | 
| 44 | 0 | 0 |  |  |  |  | map {$_->value} grep {$_->property_name eq $prop} @{$self->restriction_list||[]}; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | return \@vals; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub add_restriction { | 
| 49 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 50 | 0 |  |  |  |  |  | my $r = shift; | 
| 51 | 0 | 0 |  |  |  |  | if (!ref($r)) { | 
| 52 | 0 |  |  |  |  |  | $r = $self->apph->create_restriction_obj({property_name=>$r, | 
| 53 |  |  |  |  |  |  | value=>shift}); | 
| 54 |  |  |  |  |  |  | } | 
| 55 | 0 |  | 0 |  |  |  | my $rl = $self->restriction_list || []; | 
| 56 | 0 |  |  |  |  |  | $self->restriction_list([@$rl, $r]); | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 |  |  |  |  |  | $r; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | sub all_parent_accs { | 
| 62 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 63 | 0 |  |  |  |  |  | my $restrs = $self->restriction_list; | 
| 64 |  |  |  |  |  |  | return [ | 
| 65 | 0 |  |  |  |  |  | $self->parent_acc, | 
| 66 | 0 |  |  |  |  |  | map { $_->value } @$restrs | 
| 67 |  |  |  |  |  |  | ]; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub all_parent_relationships { | 
| 71 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 72 | 0 |  |  |  |  |  | my $restrs = $self->restriction_list; | 
| 73 | 0 |  |  |  |  |  | my $xp_acc = $self->xp_acc; | 
| 74 | 0 |  |  |  |  |  | my @hashes = | 
| 75 |  |  |  |  |  |  | ( | 
| 76 |  |  |  |  |  |  | {acc1=>$self->parent_acc, | 
| 77 |  |  |  |  |  |  | acc2=>$xp_acc, | 
| 78 |  |  |  |  |  |  | type=>'is_a' | 
| 79 |  |  |  |  |  |  | }, | 
| 80 |  |  |  |  |  |  | map { | 
| 81 | 0 |  |  |  |  |  | ({ | 
| 82 |  |  |  |  |  |  | acc1=>$_->value, | 
| 83 |  |  |  |  |  |  | acc2=>$xp_acc, | 
| 84 |  |  |  |  |  |  | type=>$_->property_name | 
| 85 |  |  |  |  |  |  | }) | 
| 86 |  |  |  |  |  |  | } @$restrs | 
| 87 |  |  |  |  |  |  | ); | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | return [ | 
| 90 | 0 |  |  |  |  |  | map { | 
| 91 | 0 |  |  |  |  |  | $self->apph->create_relationship_obj($_) | 
| 92 |  |  |  |  |  |  | } @hashes | 
| 93 |  |  |  |  |  |  | ]; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub to_obo { | 
| 97 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 98 | 0 |  |  |  |  |  | my $restrs = $self->restriction_list; | 
| 99 |  |  |  |  |  |  | return | 
| 100 | 0 |  |  |  |  |  | sprintf("cross_product: %s %s\n", | 
| 101 |  |  |  |  |  |  | $self->parent_acc, | 
| 102 |  |  |  |  |  |  | join(' ', | 
| 103 | 0 |  |  |  |  |  | map {sprintf("(%s %s)", | 
| 104 |  |  |  |  |  |  | $_->property_name, $_->value)} @$restrs)); | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub equals { | 
| 110 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 111 | 0 |  |  |  |  |  | my $xp = shift; | 
| 112 |  |  |  |  |  |  | #    printf "TESTING FOR EQUALITY (%s):\n", $xp->xp_acc; | 
| 113 |  |  |  |  |  |  | #    print $self->to_obo; | 
| 114 |  |  |  |  |  |  | #    print $xp->to_obo; | 
| 115 | 0 | 0 |  |  |  |  | return 0 unless $self->parent_acc eq $xp->parent_acc; | 
| 116 | 0 | 0 |  |  |  |  | my @r1 = @{$self->restriction_list || []}; | 
|  | 0 |  |  |  |  |  |  | 
| 117 | 0 | 0 |  |  |  |  | my @r2 = @{$xp->restriction_list || []}; | 
|  | 0 |  |  |  |  |  |  | 
| 118 | 0 | 0 |  |  |  |  | return 0 unless scalar(@r1) == scalar(@r2); | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | my @propnames = | 
| 121 | 0 | 0 |  |  |  |  | map {$_->property_name} | 
| 122 | 0 | 0 |  |  |  |  | @{$self->restriction_list||[]}, | 
| 123 | 0 |  |  |  |  |  | @{$xp->restriction_list||[]}; | 
| 124 | 0 |  |  |  |  |  | my %uniqpropnames = map{$_=>1} @propnames; | 
|  | 0 |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 0 |  |  |  |  |  | my $ok = 1; | 
| 127 | 0 |  |  |  |  |  | foreach my $pn (keys %uniqpropnames) { | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 0 |  |  |  |  |  | my @vals1 = | 
| 130 |  |  |  |  |  |  | sort | 
| 131 | 0 |  |  |  |  |  | @{$self->get_restriction_values_for_property($pn)}; | 
| 132 | 0 |  |  |  |  |  | my @vals2 = | 
| 133 |  |  |  |  |  |  | sort | 
| 134 | 0 |  |  |  |  |  | @{$xp->get_restriction_values_for_property($pn)}; | 
| 135 | 0 |  |  |  |  |  | while (@vals1) { | 
| 136 | 0 | 0 |  |  |  |  | if (shift @vals1 ne shift @vals2) { | 
| 137 | 0 |  |  |  |  |  | $ok = 0; | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  | } | 
| 140 | 0 | 0 |  |  |  |  | if (@vals2) { | 
| 141 | 0 |  |  |  |  |  | $ok = 0; | 
| 142 |  |  |  |  |  |  | } | 
| 143 | 0 | 0 |  |  |  |  | last unless $ok; | 
| 144 |  |  |  |  |  |  | } | 
| 145 | 0 |  |  |  |  |  | return $ok; | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | 1; |