comparison lib/CPT/Bio/Dbxref.pm @ 1:8691c1c61a8e draft default tip

planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author cpt
date Mon, 05 Jun 2023 02:48:47 +0000
parents
children
comparison
equal deleted inserted replaced
0:54c7a3ea81e2 1:8691c1c61a8e
1 package CPT::Bio::Dbxref;
2 use Moose;
3 use autodie;
4 use YAML;
5 use File::ShareDir;
6 use File::Spec qw/catfile/;
7
8 has 'regex_map' => ( is => 'rw', isa => 'HashRef');
9 has 'initialized' => ( is => 'rw', isa => 'Int', default => 0);
10
11 sub init {
12 my ($self) = @_;
13 # Locate file
14 my $data_dir = File::ShareDir::dist_dir('libCPT');
15 my $dbxref_data = File::Spec->catfile($data_dir, 'dbxref.yaml');
16 # Parse
17 $self->regex_map(YAML::LoadFile($dbxref_data));
18 $self->initialized(1);
19 }
20
21 sub get_prefix {
22 my ($self, $dbxref) = @_;
23 if(!$self->initialized()){
24 $self->init();
25 }
26
27 my @hits;
28 my %map = %{$self->regex_map()};
29 # Search through regex database
30 foreach my $db(keys(%map)){
31 if(defined($map{$db}{local_id_syntax})){
32 my $ref = $map{$db}{local_id_syntax};
33 if(ref($ref) eq 'ARRAY'){
34 foreach my $regi(@{$ref}){
35 if($dbxref =~ /$regi/){
36 push(@hits, $map{$db}{abbreviation});
37 }
38 }
39 }
40 if($dbxref =~ /$ref/){
41 push(@hits, $map{$db}{abbreviation});
42 }
43 }
44 }
45 return @hits;
46 }
47
48
49 no Moose;
50 1;
51
52 __END__
53
54 =pod
55
56 =encoding UTF-8
57
58 =head1 NAME
59
60 CPT::Bio::Dbxref
61
62 =head1 VERSION
63
64 version 1.99.4
65
66 =head1 AUTHOR
67
68 Eric Rasche <rasche.eric@yandex.ru>
69
70 =head1 COPYRIGHT AND LICENSE
71
72 This software is Copyright (c) 2014 by Eric Rasche.
73
74 This is free software, licensed under:
75
76 The GNU General Public License, Version 3, June 2007
77
78 =cut