line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BioX::CLPM::Base; |
2
|
2
|
|
|
2
|
|
1046
|
use Class::Std; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Class::Std::Utils; |
4
|
|
|
|
|
|
|
use DBIx::MySperqlOO; |
5
|
|
|
|
|
|
|
use File::Spec; |
6
|
|
|
|
|
|
|
use YAML qw(DumpFile LoadFile); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use warnings; |
9
|
|
|
|
|
|
|
use strict; |
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use version; our $VERSION = qv('0.0.1'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $config_filename = '.clpm/config'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
#my %attribute_of :ATTR( :get :set :default<''> :init_arg ); |
18
|
|
|
|
|
|
|
my %storage_of :ATTR( :get :set :default<'db'> :init_arg ); |
19
|
|
|
|
|
|
|
my %lookups_of :ATTR( :get :set :default<'local'> :init_arg ); |
20
|
|
|
|
|
|
|
my %data_dbh_of : ATTR(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
|
|
|
|
|
|
my ($self, $ident, $arg_ref) = @_; |
24
|
|
|
|
|
|
|
my $config = $self->_load_config(); |
25
|
|
|
|
|
|
|
$data_dbh_of{$ident} = DBIx::MySperqlOO->new( $config->{data} ); |
26
|
|
|
|
|
|
|
return; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_config_filename { return File::Spec->catfile( $ENV{HOME}, $config_filename ); } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub sqlexec { |
32
|
|
|
|
|
|
|
my ( $self, $sql, $return ) = @_; |
33
|
|
|
|
|
|
|
my $data = $data_dbh_of{ident $self}; |
34
|
|
|
|
|
|
|
$sql = $sql ? $sql : ''; |
35
|
|
|
|
|
|
|
$return = $return ? $return : ''; |
36
|
|
|
|
|
|
|
if ( $return eq '\@@' ) { |
37
|
|
|
|
|
|
|
my $rows_ref; |
38
|
|
|
|
|
|
|
if ( $sql ) { $rows_ref = $data->sqlexec( $sql, $return ); } |
39
|
|
|
|
|
|
|
return $rows_ref; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ( $return eq '@' ) { |
42
|
|
|
|
|
|
|
my @data; |
43
|
|
|
|
|
|
|
if ( $sql ) { @data = $data->sqlexec( $sql, $return ); } |
44
|
|
|
|
|
|
|
return @data; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# UTIL |
49
|
|
|
|
|
|
|
sub load_masses { |
50
|
|
|
|
|
|
|
my ( $self ) = @_; |
51
|
|
|
|
|
|
|
my $rows_ref = $self->sqlexec( 'select letter, mass from amino_acids', '\@@' ); |
52
|
|
|
|
|
|
|
my %aa_masses; |
53
|
|
|
|
|
|
|
foreach my $row_ref ( @$rows_ref ) { |
54
|
|
|
|
|
|
|
my ( $letter, $mass ) = @$row_ref; |
55
|
|
|
|
|
|
|
$aa_masses{$letter} = $mass; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return \%aa_masses; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _load_config { |
61
|
|
|
|
|
|
|
my ( $self ) = @_; |
62
|
|
|
|
|
|
|
return LoadFile( $self->get_config_filename() ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _sql_escape { |
66
|
|
|
|
|
|
|
my ( $self, $string ) = @_; |
67
|
|
|
|
|
|
|
if ($string) { $string =~ s/(['"\\])/\\$1/g; } |
68
|
|
|
|
|
|
|
return $string; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
74
|
|
|
|
|
|
|
__END__ |