-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobo-ids-to-obolibrary-uris.pl
executable file
·74 lines (57 loc) · 1.37 KB
/
obo-ids-to-obolibrary-uris.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
#!/usr/bin/perl -w
use strict;
my %colh = ();
while ($ARGV[0] =~ /^\-.+/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
if ($opt eq '-k' || $opt eq '--key') {
foreach (split /,/,shift @ARGV) {
if (/(\d+)\-(\d+)/) {
foreach ($1..$2) {
$colh{$_}=1;
}
}
else {
$colh{$_}=1;
}
}
}
}
my @cols = keys %colh;
if (@cols) {
while (<>) {
chomp;
my @vals = split(/\t/,$_);
foreach my $c (@cols) {
$vals[$c-1] =~ s@([\w\-]+):(\S+)@http://purl.obolibrary.org/obo/$1_$2@g;
}
print join("\t",@vals),"\n";
}
}
else {
while (<>) {
s@([\w\-]+):(\S+)@http://purl.obolibrary.org/obo/$1_$2@g;
print;
}
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [-k COLNUMS] FILE [FILES]
translates OBO IDs to OBO Foundry style URIs.
E.g. CL:0000540 ==> http://purl.obolibrary.org/obo/CL_0000540
If -k is not specified, the translation operates on the whole file - any file structure can be used.
If -k is specified, a tab delimited file is assumed
E.g.
$sn -k 2,4,7-10 foo.tab > foo_owl.tab
converts all OBO IDs in cols 2,4,7,8,9 and 10
EOM
}