Phylo/PhyloWS/Service/UbioClassificationBank.pm untested

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