-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobo-add-def-xrefs.pl
executable file
·79 lines (68 loc) · 1.23 KB
/
obo-add-def-xrefs.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
#!/usr/bin/perl -w
use strict;
my %tag_h=();
my $negate = 0;
my $replace = 0;
my $check = 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 '-r' || $opt eq '--replace') {
$replace = 1;
}
if ($opt eq '-c' || $opt eq '--check') {
$check = 1;
}
if ($opt eq '-t' || $opt eq '--tag') {
$tag_h{shift @ARGV} = 1;
}
}
if (!%tag_h) {
$tag_h{'xref'} = 1;
}
if (!@ARGV) {
print usage();
exit 0;
}
my $lastf = pop @ARGV;
my %defmap = ();
while (<>) {
chomp;
my ($k,$v) = split(/\t/,$_);
$defmap{$k} = $v;
}
my $id;
open(F,$lastf);
while(<F>) {
chomp;
if (/^id:\s+(\S+)/) {
$id = $1;
}
if ($defmap{$id}) {
if (/^(def:.*\[.*)\]\s*$/) {
print "$1, $defmap{$id}]\n";
next;
}
}
print "$_\n";
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [-t tag]* BASE-FILE FILE-TO-MERGE1 [FILE-TO-MERGE2...]
merges in tags to base file
Example:
$sn referenced_file1.obo [referenced_file2.obo ...] source_file.obo
EOM
}