Debian Codegraph @

GO/Handlers/owl_to_obo_text.pm

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # $Id: owl_to_obo_text.pm,v 1.2 2004/07/08 04:08:42 cmungall Exp $
2 # BioPerl module for Bio::Parser::owl_to_obo
3 #
4 # cjm
5 #
6 # POD documentation - main docs before the code
7
8 =head1 NAME
9
10 Bio::Parser::owl_to_obo_text
11
12 =head1 SYNOPSIS
13
14 Do not use this module directly.
15
16 =head1 DESCRIPTION
17
18 =head1 FEEDBACK
19
20 =head1 AUTHORS - Chris Mungall
21
22 Email: [email protected]
23
24 =cut
25
26 # Let the code begin...
27
28 package GO::Handlers::owl_to_obo_text;
29 use vars qw(@ISA);
30 use strict;
31
32 # Object preamble - inherits from Bio::Root::Object
33
34 use base qw(GO::Handlers::base);
35
36 our $BASE;
37
38 sub e_rdf_RDF_xml_base {
39 my ($self, $base) = @_;
40 $BASE = $base->data;
41 return;
42 }
43
44 sub e_owl_ObjectProperty {
45 my ($self, $prop) = @_;
46 my $id = $prop->sget("owl:ObjectProperty-rdf:ID");
47 $self->printf("\n[Typedef]\nid:%s\nname:%s\n",
48 $id, $id);
49
50
51 $prop->free;
52 return;
53 }
54
55 sub e_owl_AnnotationProperty {
56 my ($self, $prop) = @_;
57
58 $prop->free;
59 return;
60 }
61
62 sub _xml {
63 my $str = shift;
64 my $xml = "<foo>$str</foo>";
65 my $struct;
66 eval {
67 $struct = Data::Stag->parsestr($xml);
68 };
69 if ($@) {
70 print STDERR $@;
71 print STDERR $str,"\n";
72 $struct = Data::Stag->new(foo=>[]);
73 }
74 $struct;
75 }
76
77 sub e_owl_Class {
78 my ($self, $owlclass) = @_;
79
80 print $owlclass->xml;
81 my $id = $owlclass->sget("owl:Class-rdf:ID");
82 my $name = $owlclass->sget("Preferred_Name") || $id;
83 my @defh =
84 map {
85 my $struct = _xml($_);
86 ($struct->sget("def-definition") =>
87 $struct->sget("def-source"));
88 } $owlclass->get("DEFINITION");
89 my %defh = @defh;
90 my @defrefs = values %defh;
91 my $defref = join(" ", map {"[$_]"} @defrefs) || "[]";
92 my $def = join(";;\\n", keys %defh);
93
94 my @subclasses =
95 map {
96 my @R = $_->get("owl:Restriction");
97 if (@R) {
98 @R;
99 }
100 else {
101 my $sid = $_->sget("rdfs:subClassOf-rdf:resource");
102 if (!$sid) {
103 die $owlclass->sxpr;
104 $sid = '';
105 }
106 _get_ID($sid);
107 }
108 } $owlclass->get("rdfs:subClassOf");
109 my @restrictions = grep {ref($_)} @subclasses;
110 @subclasses = grep {!ref($_)} @subclasses;
111
112 my @stypes = $owlclass->get("Semantic_Type");
113
114 # weird xml-inside-xml
115 my @syns = $owlclass->get("FULL_SYN");
116 @syns = map {
117 my $struct = _xml($_);
118 $struct->sget("term-name");
119 } @syns;
120 push(@syns, $owlclass->get("Synonym"));
121 my @lines =
122 (id => $id,
123 name => $name,
124 (map {(is_a => $_ )} @subclasses),
125 (map {(synonym => safeqt($_)." []")} @syns),
126 $def ? (definition => safeqt($def)." $defref") : (),
127 (map {
128 (relationship =>
129 sprintf("%s %s",
130 (_get_IDs($_->sfindval("owl:onProperty-rdf:resource")),
131 _get_IDs($_->sfindval("owl:someValuesFrom-rdf:resource")),
132 )))
133 } @restrictions),
134 );
135 $self->printf("\n[Term]\n");
136 while (my ($tag, $val) = splice(@lines, 0, 2)) {
137 $self->print("$tag: $val\n");
138 }
139 $owlclass->free;
140 return;
141 }
142
143 sub safeqt {
144 my $str = shift || '';
145 $str =~ s/\"/\\\"/g;
146 "\"$str\"";
147 }
148 sub _get_ID {
149 my @l = _get_IDs(@_);
150 return shift @l;
151 }
152
153 sub _get_IDs {
154 my @ids = @_;
155 map {
156 $_ = '' unless $_;
157 s/^\#//;
158 $_;
159 } @ids;
160 }
161
162 1;