Phylo/PhyloWS/Service/UbioClassificationBank.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 70 CC 3 SCAR 14.6
CC
3
Cov
0%
get_record
12.0
get_supported_formats
2.0
get_authority
2.0
CRAP 4.3
1 package Bio::Phylo::PhyloWS::Service::UbioClassificationBank;
2 use strict;
3 use warnings;
4 use base 'Bio::Phylo::PhyloWS::Service';
5 use constant RDFURL => 'http://www.ubio.org/authority/metadata.php?lsid=urn:lsid:ubio.org:classificationbank:';
6 use Bio::Phylo::IO 'parse';
7 use Bio::Phylo::Util::Logger;
8 use Bio::Phylo::Util::Exceptions 'throw';
9 use Bio::Phylo::Util::CONSTANT qw'/looks_like/ :objecttypes';
10  
11  
12 {
13 my $logger = Bio::Phylo::Util::Logger->new;
14  
15 =head1 NAME
16  
17 Bio::Phylo::PhyloWS::Service::UbioClassificationBank - PhyloWS service wrapper
18 for uBio ClassificationBank records
19  
20 =head1 SYNOPSIS
21  
22 # inside a CGI script:
23 use CGI;
24 use Bio::Phylo::PhyloWS::Service::UbioClassificationBank;
25  
26 # obtain a key code from http://www.ubio.org/index.php?pagename=form
27 # and define it as an environment variable:
28 $ENV{'UBIO_KEYCODE'} = '******';
29 my $cgi = CGI->new;
30 my $service = Bio::Phylo::PhyloWS::Service::UbioClassificationBank->new(
31 '-base_uri' => $url
32 );
33 $service->handle_request($cgi);
34  
35 =head1 DESCRIPTION
36  
37 This is an example implementation of a PhyloWS service. The service
38 wraps around some of the uBio XML services described at
39 L<http://www.ubio.org/index.php?pagename=xml_services>.
40  
41 Record lookups for this service return project objects
42 that capture the RDF metadata for a single ClassficationBank record as semantic
43 annotations to a taxon object. An example of the sort of metadata that
44 can be expected is shown here:
45 L<http://www.ubio.org/authority/metadata.php?lsid=urn:lsid:ubio.org:classificationbank:11168417>
46  
47 =head1 METHODS
48  
49 =head2 ACCESSORS
50  
51 =over
52  
53 =item get_record()
54  
55 Gets a uBio classification bank record by its id
56  
57 Type : Accessor
58 Title : get_record
59 Usage : my $record = $obj->get_record( -guid => $guid );
60 Function: Gets a uBio classification bank record by its id
61 Returns : Bio::Phylo::Project
62 Args : Required: -guid => $guid
63 Comments: For the $guid argument, this method only cares
64 whether the last part of the argument is a series
65 of integers, which are understood to be classification
66 bank identifiers
67  
68 =cut
69  
70  
71 sub get_record {
72 my $self = shift;
73 my $proj;
74 if ( my %args = looks_like_hash @_ ) {
75 if ( my $guid = $args{'-guid'} && $args{'-guid'} =~ m|(\d+)$| ) {
76
77 # fetch and parse the metadata record
78 my $namebank_id = $1;
79 $logger->info("Going to fetch metadata for record $namebank_id");
80 $proj = parse(
81 '-url' => RDFURL . $namebank_id,
82 '-format' => 'ubiocbmeta',
83 '-as_project' => 1,
84 );
85  
86 # attach links back for rss
87 my $prefix = $self->get_url_prefix;
88 my ($taxa) = @{ $proj->get_taxa };
89 $taxa->visit(sub{
90 my $taxon = shift;
91 $taxon->set_link( $prefix . $taxon->get_guid );
92 })
93 }
94 else {
95 throw 'BadArgs' => "No parseable GUID: '$args{-guid}'";
96 }
97 }
98 return $proj;
99 }
100
101 =item get_supported_formats()
102  
103 Gets an array ref of supported formats
104  
105 Type : Accessor
106 Title : get_supported_formats
107 Usage : my @formats = @{ $obj->get_supported_formats };
108 Function: Gets an array ref of supported formats
109 Returns : [ 'nexml', 'json', 'nexus', 'rss1' ]
110 Args : NONE
111  
112 =cut
113
114 sub get_supported_formats { [ 'nexml', 'json', 'nexus', 'rss1' ] }
115  
116 =item get_authority()
117  
118 Gets the authority prefix (e.g. TB2) for the implementing service
119  
120 Type : Authority
121 Title : get_authority
122 Usage : my $auth = $obj->get_authority;
123 Function: Gets authority prefix
124 Returns : 'uBioCB'
125 Args : None
126  
127 =cut
128  
129 sub get_authority { 'uBioCB' }
130  
131 =back
132  
133 =cut
134  
135 # podinherit_insert_token
136  
137 =head1 SEE ALSO
138  
139 There is a mailing list at L<https://groups.google.com/forum/#!forum/bio-phylo>
140 for any user or developer questions and discussions.
141  
142 Also see the manual: L<Bio::Phylo::Manual> and L<http://rutgervos.blogspot.com>
143  
144 =head1 CITATION
145  
146 If you use Bio::Phylo in published research, please cite it:
147  
148 B<Rutger A Vos>, B<Jason Caravas>, B<Klaas Hartmann>, B<Mark A Jensen>
149 and B<Chase Miller>, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
150 I<BMC Bioinformatics> B<12>:63.
151 L<http://dx.doi.org/10.1186/1471-2105-12-63>
152  
153  
154  
155 =cut
156  
157 }
158 1;