forked from cmungall/obo-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobo-promote-dbxref-to-intersection.pl
executable file
·99 lines (84 loc) · 2.39 KB
/
obo-promote-dbxref-to-intersection.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
#!/usr/bin/perl
my $idspace;
my $diff;
while ($ARGV[0] =~ /^(\-.*)/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
elsif ($opt eq '-i' || $opt eq '--idspace') {
$idspace = shift @ARGV;
}
elsif ($opt eq '-d' || $opt eq '--differentium') {
$diff = shift @ARGV;
unless ($diff =~ /\s/) {
$diff .= " ".shift @ARGV;
}
}
else {
die "Command line option \"$opt\" not known";
}
}
die "You must specify an idspace; for example:\n$0 --idspace CL" unless $idspace;
die "You must specify a differentium; for example:\n$0 -d \"part_of NCBITax:zebrafish\"" unless $diff;
my %done = ();
my $id;
while (<>) {
chomp;
$id = $1 if /^id: (\S+)/;
print "$_\n";
if (/^xref(\w*):\s*(.*)/) {
my $xref = $2;
if ($done{$id}) {
print STDERR "ignoring additional xref: $xref for $id\n";
}
else {
$done{$id}=1;
if ($xref =~ /(.*):/ && $1 eq $idspace) {
print "intersection_of: $xref\n";
print "intersection_of: $diff\n";
}
}
}
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [--idspace IDSPACE] [--differentium RELATION TERMID] FILE
Promotes xref to genus-differentia definitions.
This script is useful for keeping an ontology consistent with some
reference ontology, when these two ontologies reference the same or
highly similar kinds of entities.
For example, the ZFA contains links to CL, the OBO Foundry reference
ontology for cell types. If our input file contains:
[Term]
id: ZFA:0000134
name: neurons
namespace: zebrafish_anatomy
relationship: end ZFS:0000044 ! Adult
relationship: part_of ZFA:0000396 ! nervous system
relationship: start ZFS:0000026 ! Segmentation:14-19 somites
xref: CL:0000540
xref: ZFIN:ZDB-ANAT-010921-563
And we run:
obo-promote-dbxref-to-intersection.pl --idspace CL -d part_of NCBITax:7955 zfa.obo
We get:
[Term]
id: ZFA:0000134
name: neurons
namespace: zebrafish_anatomy
relationship: end ZFS:0000044 ! Adult
relationship: part_of ZFA:0000396 ! nervous system
relationship: start ZFS:0000026 ! Segmentation:14-19 somites
intersection_of: CL:0000540
intersection_of: part_of NCBITax:7955
xref: CL:0000540
xref: ZFIN:ZDB-ANAT-010921-563
EOM
}