HackaMol/Roles/FileFetchRole.pm

filter: Statementstmt 45.8% 22 / 48 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 41.6% 30 / 72 SCAR 27.0
CC
6
Cov
37%
getstore_pdbid
30.0
get_pdbid
6.0
_fix_pdbid
2.0
CRAP 14.9
« HackaMol/Roles/ReadPdbqtRole.pm ↑ Summary HackaMol/Roles/ReadXyzRole.pm »
1 package HackaMol::Roles::FileFetchRole;
2 11 $HackaMol::Roles::FileFetchRole::VERSION = '0.051';
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 sub _fix_pdbid{
15 0 ▶ my $pdbid = shift;
Subroutine _fix_pdbid: not called CC=1 SCAR=6.9
16 0 $pdbid =~ s/\.pdb//; #just in case
17 0 $pdbid .= '.pdb';
18 0 return $pdbid;
19 }
20  
21 sub get_pdbid{
22 #return pdb contents downloaded from pdb.org
23 0 ▶ my $self = shift;
Subroutine get_pdbid: not called CC=2 SCAR=17.9
Pod documented
24 0 my $pdbid = _fix_pdbid(shift);
25 0 my ($ok, $why) = HTTP::Tiny->can_ssl;
26 0 ▶ if ($ok){
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 0 0 0
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 sub getstore_pdbid{
37 #return array of lines from pdb downloaded from pdb.org
38 0 ▶ my $self = shift;
Subroutine getstore_pdbid: not called CC=5 SCAR=34.0
Pod documented
39 0 my $pdbid = _fix_pdbid(shift);
40 0 my $fpdbid = shift ;
41 0 ▶ $fpdbid = $pdbid unless defined($fpdbid);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fpdbid 0 0 0
42 0 $fpdbid = path($fpdbid);
43  
44 0 ▶ if ($fpdbid->exists and not $self->overwrite){
Branch: 1 branch
BranchTrueFalseTotal
if ($fpdbid->exists and not $self->overwrite) 0 0 0
Condition0%0/3
$fpdbid->exists and not $self->overwrite
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($pdb) { } 0 0 0
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__
64  
65 =pod
66  
67 =head1 NAME
68  
69 HackaMol::Roles::FileFetchRole - Role for using LWP::Simple to fetch files from www
70  
71 =head1 VERSION
72  
73 version 0.051
74  
75 =head1 SYNOPSIS
76  
77 use HackaMol;
78  
79 my $pdb = $HackaMol->new->get_pdbid("2cba");
80 print $pdb;
81  
82 =head1 DESCRIPTION
83  
84 FileFetchRole provides attributes and methods for pulling files from the internet.
85 Currently, the Role has one method and one attribute for interacting with the Protein Database.
86  
87 =head1 METHODS
88  
89 =head2 get_pdbid
90  
91 fetches a pdb from pdb.org and returns the file in a string.
92  
93 =head2 getstore_pdbid
94  
95 arguments: pdbid and filename for writing (optional).
96 Fetches a pdb from pdb.org and stores it in your working directory unless {it exists and overwrite(0)}. If a filename is not
97 passed to the method, it will write to $pdbid.pdb. use get_pdbid to return contents
98  
99 =head1 ATTRIBUTES
100  
101 =head2 overwrite
102  
103 isa lazy ro Bool that defaults to 0 (false). If overwrite(1), then fetched files will be able to overwrite
104 those of same name in working directory.
105  
106 =head2 pdbserver
107  
108 isa lazy rw Str that defaults to http://pdb.org/pdb/files/
109  
110 =head1 SEE ALSO
111  
112 =over 4
113  
114 =item *
115  
116 L<http://www.pdb.org>
117  
118 =item *
119  
120 L<LWP::Simple>
121  
122 =back
123  
124 =head1 AUTHOR
125  
126 Demian Riccardi <demianriccardi@gmail.com>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 This software is copyright (c) 2017 by Demian Riccardi.
131  
132 This is free software; you can redistribute it and/or modify it under
133 the same terms as the Perl 5 programming language system itself.
134  
135 =cut
« HackaMol/Roles/ReadPdbqtRole.pm ↑ Summary HackaMol/Roles/ReadXyzRole.pm »