| 1 | #----------------------------------------------------------------- | ||
| 2 | # MOSES::MOBY::Data::Xref | ||
| 3 | # Author: Edward Kawas <edward.kawas@gmail.com>, | ||
| 4 | # Martin Senger <martin.senger@gmail.com> | ||
| 5 | # For copyright and disclaimer see below. | ||
| 6 | # | ||
| 7 | # $Id: Xref.pm,v 1.4 2008/04/29 19:35:57 kawas Exp $ | ||
| 8 | #----------------------------------------------------------------- | ||
| 9 | |||
| 10 | package MOSES::MOBY::Data::Xref; | ||
| 11 | use base qw( MOSES::MOBY::Data::Object ); | ||
| 12 | use MOSES::MOBY::Tags; | ||
| 13 | use strict; | ||
| 14 | |||
| 15 | # add versioning to this module | ||
| 16 | use vars qw /$VERSION/; | ||
| 17 | $VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/; | ||
| 18 | |||
| 19 | =head1 NAME | ||
| 20 | |||
| 21 | MOSES::MOBY::Data::Xref - a Moby cross-reference | ||
| 22 | |||
| 23 | =head1 SYNOPSIS | ||
| 24 | |||
| 25 | use MOSES::MOBY::Data::Xref; | ||
| 26 | |||
| 27 | # create a simple cross-reference | ||
| 28 | my $simple_xref = new MOSES::MOBY::Data::Xref | ||
| 29 | ( id => 'At263644', | ||
| 30 | namespace => 'TIGR' | ||
| 31 | ); | ||
| 32 | |||
| 33 | # create an advanced cross-reference | ||
| 34 | my $advanced_xref = new MOSES::MOBY::Data::Xref | ||
| 35 | ( id => 'X112345', | ||
| 36 | namespace => 'EMBL', | ||
| 37 | service => 'getEMBLRecord', | ||
| 38 | authority => 'www.illuminae.com', | ||
| 39 | evidenceCode => 'IEA', | ||
| 40 | xrefType => 'transform' | ||
| 41 | ); | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | =head1 DESCRIPTION | ||
| 46 | |||
| 47 | An object representing a cross reference. A cross reference is an | ||
| 48 | optional component of any Moby object. It can be of a simple or of an | ||
| 49 | advanced version. | ||
| 50 | |||
| 51 | A simple cross reference is a base Moby object (named 'Object') that | ||
| 52 | can have only attributes 'namespace' and 'id' (no value, no article | ||
| 53 | name, no children). In XML, it look like this: | ||
| 54 | |||
| 55 | <Object namespace="TAIR" id="TG1989"/> | ||
| 56 | |||
| 57 | An advanced cross reference additionally includes a reference to a | ||
| 58 | Biomoby service that a creator of this cross reference (which is a | ||
| 59 | Biomoby service provider) suggests to execute in order to get more | ||
| 60 | about the cross-referenced data. Again, in XML it may look like this: | ||
| 61 | |||
| 62 | <moby:Xref moby:namespace="EMBL" moby:id="X112345" | ||
| 63 | authURI="www.illuminae.com" serviceName="getEMBLRecord" | ||
| 64 | evidenceCode="IEA" xrefType="transform"/> | ||
| 65 | |||
| 66 | =head1 AUTHORS | ||
| 67 | |||
| 68 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||
| 69 | Martin Senger (martin.senger [at] gmail [dot] com) | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | #----------------------------------------------------------------- | ||
| 74 | # A list of allowed attribute names. See MOSES::MOBY::Base for details. | ||
| 75 | #----------------------------------------------------------------- | ||
| 76 | |||
| 77 | =head1 ACCESSIBLE ATTRIBUTES | ||
| 78 | |||
| 79 | Details are in L<MOSES::MOBY::Base>. Here just a list of them. All of them | ||
| 80 | are of type string. | ||
| 81 | |||
| 82 | =over | ||
| 83 | |||
| 84 | =item B<authority> | ||
| 85 | |||
| 86 | =item B<service> | ||
| 87 | |||
| 88 | =item B<evidenceCode> | ||
| 89 | |||
| 90 | =item B<xrefType> | ||
| 91 | |||
| 92 | =item B<description> | ||
| 93 | |||
| 94 | =back | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | { | ||
| 99 | my %_allowed = | ||
| 100 | ( | ||
| 101 | authority => undef, | ||
| 102 | service => undef, | ||
| 103 | evidenceCode => undef, | ||
| 104 | xrefType => undef, | ||
| 105 | description => undef, | ||
| 106 | ); | ||
| 107 | |||
| 108 | sub _accessible { | ||
| 109 | my ($self, $attr) = @_; | ||
| 110 | exists $_allowed{$attr} or $self->SUPER::_accessible ($attr); | ||
| 111 | } | ||
| 112 | sub _attr_prop { | ||
| 113 | my ($self, $attr_name, $prop_name) = @_; | ||
| 114 | my $attr = $_allowed {$attr_name}; | ||
| 115 | return ref ($attr) ? $attr->{$prop_name} : $attr if $attr; | ||
| 116 | return $self->SUPER::_attr_prop ($attr_name, $prop_name); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | #----------------------------------------------------------------- | ||
| 121 | # toXML | ||
| 122 | #----------------------------------------------------------------- | ||
| 123 | sub toXML { | ||
| 124 | my $self = shift; | ||
| 125 | $self->increaseXMLCounter; | ||
| 126 | |||
| 127 | # for simple xrefs, this is enough | ||
| 128 | my $root = $self->SUPER::toXML; | ||
| 129 | $root->setNodeName (MOBY_XML_NS_PREFIX . ":" . MOBYOBJECT); | ||
| 130 | |||
| 131 | # now for advanced xrefs | ||
| 132 | if ($self->service and $self->authority) { | ||
| 133 | |||
| 134 | $root->setNodeName (MOBY_XML_NS_PREFIX . ":" . XREF); | ||
| 135 | $root->setAttributeNS (MOBY_XML_NS, AUTHURI, $self->authority); | ||
| 136 | $root->setAttributeNS (MOBY_XML_NS, SERVICENAME, $self->service); | ||
| 137 | $root->setAttributeNS (MOBY_XML_NS, EVIDENCECODE, $self->evidenceCode) | ||
| 138 | if $self->evidenceCode; | ||
| 139 | $root->setAttributeNS (MOBY_XML_NS, XREFTYPE, $self->xrefType) | ||
| 140 | if $self->xrefType; | ||
| 141 | $root->appendText ($self->description) | ||
| 142 | if $self->description; | ||
| 143 | } | ||
| 144 | |||
| 145 | # return it (TBD: cleaning namespaces happens several times...) | ||
| 146 | return $self->closeXML ($root); | ||
| 147 | } | ||
| 148 | |||
| 149 | 1; | ||
| 150 | __END__ |