-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobo-add-relationships-from-xps.pl
executable file
·133 lines (107 loc) · 2.93 KB
/
obo-add-relationships-from-xps.pl
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
#!/usr/bin/perl -w
use strict;
my %tag_h=();
my $verbose = 0;
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
if ($opt eq -'v' || $opt eq '--verbose') {
$verbose = 1;
}
}
if (!@ARGV) {
print usage();
exit 0;
}
my $id;
my @lines = @_;
my %relh = ();
while (<>) {
s/\s+$//;
if (/^id:\s+(\S+)/) {
$id = $1;
}
elsif (/^relationship:\s+(\S+)\s+(\S+)/) {
$relh{$id}->{$1}->{$2} = 1;
}
push(@lines,$_);
}
my $n = 0;
my %fixedh = ();
my @adds = ();
foreach (@lines) {
my $orig = $_;
s/\s*\!.*//;
if (/^id:\s+(\S+)/) {
$id = $1;
}
if (/^intersection_of:\s+(\S+)\s+(\S+)/) {
if (!$relh{$id}->{$1}->{$2}) {
$_ = $orig;
s/intersection_of/relationship/;
push(@adds, $_);
}
else {
if ($verbose) {
print STDERR "Already have corresponding relationship for: $_\n";
}
}
}
else {
# relationship tags should be added immediately after intersection_of tags
while (my $add = shift @adds) {
print "$add\n";
$n++;
$fixedh{$id}++;
if ($verbose) {
printf STDERR "Inserted[%d]: $add\n", scalar($fixedh{$id});
}
}
}
print "$orig\n";
}
printf STDERR "Added $n new relationships in %d terms based on xp defs\n", scalar(keys %fixedh);
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [-v] OBO-FILE
Add (redundant) relationship tags for intersection_of
differentiae. This is useful in cases where we might want to remove
all intersection_of tags before presentation to basic tools.
If the script encounters the following:
[Term]
id: GO:0035085
name: cilium axoneme
namespace: cellular_component
def: "The bundle of microtubules and associated proteins that forms the core of cilia in eukaryotic cells and is responsible for their movements." [GOC:bf, ISBN:0198547684]
is_a: GO:0005930 ! axoneme
is_a: GO:0044441 ! cilium part
intersection_of: GO:0005930 ! axoneme
intersection_of: part_of GO:0005929 ! cilium
It will add a line
relationship: part_of GO:0005929 ! cilium
This is technically completely redundant, but useful to materialize in the file.
If the script encounters the following:
[Term]
id: GO:0034350
name: regulation of glial cell apoptosis
namespace: biological_process
def: "Any process that modulates the frequency, rate, or extent of glial cell apoptosis." [GOC:mah]
is_a: GO:0042981 ! regulation of apoptosis
intersection_of: GO:0065007 ! biological regulation
intersection_of: regulates GO:0034349 ! glial cell apoptosis
relationship: regulates GO:0034349 ! glial cell apoptosis
It will do nothing, as the redundant relationship is already there.
See also:
https://sourceforge.net/tracker/?func=detail&aid=2305635&group_id=36855&atid=418260
https://sourceforge.net/tracker/index.php?func=detail&aid=2305594&group_id=36855&atid=418257
EOM
}