forked from cmungall/obo-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbl2obolinks.pl
executable file
·88 lines (83 loc) · 1.86 KB
/
tbl2obolinks.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
#!/usr/bin/perl
my $rel;
my $swap;
my $src;
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-r' || $opt eq '--rel') {
$rel = shift;
}
elsif ($opt eq '--is_a') {
$rel = 'is_a';
}
elsif ($opt eq '--synonym') {
$rel = 'synonym';
}
elsif ($opt eq '--swap') {
$swap = 1;
}
elsif ($opt eq '--source') {
$src = shift @ARGV;
}
}
my %linkh = ();
while (<>) {
chomp;
s/\!.*//;
s/^\s+//;
s/\s+$//;
next unless $_;
my @cols = split(/\t/);
if (@cols == 4) {
@cols = ("$cols[0] ! $cols[1]","$cols[2] ! $cols[3]");
}
foreach (@cols) {
if (/^(\S+:\d+)\-(.*)/) {
$_ = "$1 ! $2";
}
if ($src) {
s/ \! / {source="$src"} \! /;
}
}
if (!$rel) {
$rel = shift @cols;
}
if ($swap) {
push(@{$linkh{$cols[1]}->{$rel}},$cols[0]);
}
else {
push(@{$linkh{$cols[0]}->{$rel}},$cols[1]);
}
}
foreach my $id (keys %linkh) {
print "[Term]\nid: $id\n";
my $relh = $linkh{$id};
foreach my $rel (keys %$relh) {
if ($rel eq 'xref') {
print "xref: $_\n" foreach @{$relh->{$rel}};
}
elsif ($rel eq 'synonym') {
print "$rel: \"$_\" EXACT []\n" foreach @{$relh->{$rel}};
}
elsif ($rel eq 'is_a') {
print "is_a: $_\n" foreach @{$relh->{$rel}};
}
elsif ($rel eq 'equivalent_to') {
print "equivalent_to: $_\n" foreach @{$relh->{$rel}};
}
elsif ($rel eq 'def_xref') {
printf("def: \".\" [%s]\n",
join(', ', @{$relh->{$rel}}));
}
else {
print "relationship: $rel $_\n" foreach @{$relh->{$rel}};
}
}
print "\n";
}
exit 0;
sub print_term {
my $id = shift;
my $n = shift;
print "[Term]\nid: $id\nname: $n\n\n"
}