forked from cmungall/obo-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobo-extract-referenced-stanzas.pl
executable file
·82 lines (70 loc) · 1.29 KB
/
obo-extract-referenced-stanzas.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
#!/usr/bin/perl -w
use strict;
my %tag_h=();
my $negate = 0;
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
if ($opt eq '--neg') {
$negate = 1;
}
if ($opt eq '-t' || $opt eq '--tag') {
$tag_h{shift @ARGV} = 1;
}
}
if (!%tag_h) {
$tag_h{'xref'} = 1;
}
my $f = pop @ARGV; # file to extract from
my %ref=();
my %names=();
my $name;
while (<>) {
chomp;
if (/^name:\s+(.*)/) {
$name = $1;
}
elsif (/^id:\s+(\S+)\s*\!\s*(.+)/) {
$name = $2;
}
elsif (/^(relationship|intersection_of|union_of):\s+(\S+)\s+(\S+)/) {
count($1,$2);
}
elsif (/^(is_a|intersection_of):\s+(\S+)/) {
count($1);
}
else {
}
}
$/="\n\n";
open(F,$f);
while(<F>) {
chomp;
if (/id:\s*(\S+)/ && $ref{$1}) {
print STDERR "$1 refcount: $ref{$1}\n";
printf "! %s\n", join('//',@{$names{$1}});
print "$_\n\n";
}
}
close(F);
exit 0;
sub count {
foreach (@_) {
$ref{$_}++;
push(@{$names{$_}}, $name);
}
}
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn REFERENCING-FILE1 [REFERENCING-FILE2..] REFERENCED-FILE
extracts from REFERENCED-FILE all stanzas referenced in the other files
EOM
}