This repository has been archived by the owner on Jul 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathClan.pm
executable file
·138 lines (116 loc) · 2.83 KB
/
Clan.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright SRA International
#
# Distributed under the OSI-approved BSD 3-Clause License.
# See http://ncip.github.com/pathway-interaction-database/LICENSE.txt for details.
package Clan;
require Exporter;
@ISA = qw(Exporter);
#@EXPORT = qw(
#);
use strict;
######################################################################
sub new {
my ($self, $atomset, $molinstset, $macropset) = @_;
my $x = {};
if (defined $atomset && $atomset ne "") {
for my $a (@{ $atomset }) {
$x->{atom}{$a} = 1;
}
}
if (defined $molinstset && $molinstset ne "") {
for my $m (@{ $molinstset }) {
$x->{molinst}{$m} = 1;
}
}
if (defined $macropset && $macropset ne "") {
for my $p (@{ $macropset }) {
$x->{macroprocess}{$p} = 1;
}
}
return bless $x;
}
######################################################################
sub HasAtom {
my ($self, $atom) = @_;
if (defined $self->{atom}{$atom}) {
return 1;
} else {
return 0;
}
}
######################################################################
sub ClanAtoms {
my ($self) = @_;
return [ keys %{ $self->{atom} } ];
}
######################################################################
sub ClanSize {
my ($self) = @_;
return scalar(keys %{ $self->{atom} });
}
######################################################################
sub ClansTouch {
my ($self, $x) = @_;
for my $m (keys %{ $x->{molinst} }) {
if (defined $self->{molinst}{$m}) {
return 1;
}
}
for my $p (keys %{ $x->{macroprocess} }) {
if (defined $self->{macroprocess}{$p}) {
return 1;
}
}
return 0;
}
######################################################################
sub JoinClans {
my ($self, $x) = @_;
for my $a (keys %{ $x->{atom} }) {
$self->{atom}{$a} = 1;
}
for my $m (keys %{ $x->{molinst} }) {
$self->{molinst}{$m} = 1;
}
for my $p (keys %{ $x->{macroprocess} }) {
$self->{macroprocess}{$p} = 1;
}
}
######################################################################
sub PartitionClans {
my ($clanlist) = @_;
my @clans = @{ $clanlist };
my $n = @clans;
my %killed;
my $more;
while (1) {
$more = 0;
for (my $i = 0; $i < $n - 1; $i++) {
if ($killed{$i}) {
next;
}
for (my $j = $i+1; $j < $n; $j++) {
if ($killed{$j}) {
next;
}
if ($clans[$i]->ClansTouch($clans[$j])) {
$clans[$i]->JoinClans($clans[$j]);
$more = 1;
$killed{$j} = 1;
}
}
}
if (! $more) {
last;
}
}
my @newclanlist;
for (my $i = 0; $i < $n; $i++) {
if (! $killed{$i}) {
push @newclanlist, $clans[$i];
#print STDERR "[" . join(",", keys %{ $clans[$i]->{atom} }) . "], ";
#print STDERR "[" . join(",", keys %{ $clans[$i]->{molinst} }) . "]\n";
}
}
return \@newclanlist;
}