| 1 | package HackaMol::Roles::FileFetchRole; | ||||||||||||||||||||||||||||
| 2 | 11 | $HackaMol::Roles::FileFetchRole::VERSION = '0.053'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Role for using LWP::Simple to fetch files from www | ||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | #use LWP::Simple; | ||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | has 'pdbserver', is => 'rw', isa => 'Str', lazy => 1, default => 'https://files.rcsb.org/download/'; | |||||||||||||||||||||||||||
| 12 | 11 | has 'overwrite', is => 'rw', isa => 'Bool', lazy => 1, default => 0; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub _fix_pdbid{ | ||||||||||||||||||||||||||
|
Subroutine
_fix_pdbid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 15 | 0 | my $pdbid = shift; | |||||||||||||||||||||||||||
| 16 | 0 | $pdbid =~ s/\.pdb//; #just in case | |||||||||||||||||||||||||||
| 17 | 0 | $pdbid .= '.pdb'; | |||||||||||||||||||||||||||
| 18 | 0 | return $pdbid; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub get_pdbid{ | ||||||||||||||||||||||||||
|
Subroutine
get_pdbid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | #return pdb contents downloaded from pdb.org | ||||||||||||||||||||||||||||
| 23 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 0 | my $pdbid = _fix_pdbid(shift); | |||||||||||||||||||||||||||
| 25 | 0 | my ($ok, $why) = HTTP::Tiny->can_ssl; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ($ok){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | my $pdb = HTTP::Tiny->new->get($self->pdbserver.$pdbid); | |||||||||||||||||||||||||||
| 28 | 0 | return ( $pdb->{content} ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||
| 31 | 0 | warn "$why"; | |||||||||||||||||||||||||||
| 32 | 0 | return 0; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub getstore_pdbid{ | ||||||||||||||||||||||||||
|
Subroutine
getstore_pdbid: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | #return array of lines from pdb downloaded from pdb.org | ||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 0 | my $pdbid = _fix_pdbid(shift); | |||||||||||||||||||||||||||
| 40 | 0 | my $fpdbid = shift ; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | $fpdbid = $pdbid unless defined($fpdbid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $fpdbid = path($fpdbid); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($fpdbid->exists and not $self->overwrite){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fpdbid->exists and not $self->overwrite
MC/DC0%0/2
$fpdbid->exists and not $self->overwrite
$fpdbid->exists
not $self->overwrite
Truth table0%0/3
A and not(B)
A= $fpdbid->existsB= not $self->overwrite
| |||||||||||||||||||||||||||||
| 45 | 0 | carp "$fpdbid exists, set self->overwrite(1) to overwrite"; | |||||||||||||||||||||||||||
| 46 | 0 | return $fpdbid->stringify; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | my $pdb = $self->get_pdbid( $pdbid ); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($pdb){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $fpdbid->spew($pdb); | |||||||||||||||||||||||||||
| 52 | 0 | return ( $fpdbid->stringify ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | else{ | ||||||||||||||||||||||||||||
| 55 | 0 | warn "could not connect, $fpdbid not written\n"; | |||||||||||||||||||||||||||
| 56 | 0 | return 0; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 11 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 11 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||