line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
$HackaMol::Roles::FileFetchRole::VERSION = '0.053'; |
2
|
|
|
|
|
|
|
#ABSTRACT: Role for using LWP::Simple to fetch files from www |
3
|
|
|
|
|
|
|
use Moose::Role; |
4
|
11
|
|
|
11
|
|
6362
|
use Carp; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
78
|
|
5
|
11
|
|
|
11
|
|
50156
|
use Path::Tiny; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
668
|
|
6
|
11
|
|
|
11
|
|
70
|
use HTTP::Tiny; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
524
|
|
7
|
11
|
|
|
11
|
|
7963
|
#use LWP::Simple; |
|
11
|
|
|
|
|
339859
|
|
|
11
|
|
|
|
|
434
|
|
8
|
|
|
|
|
|
|
use Data::Dumper; |
9
|
11
|
|
|
11
|
|
6504
|
|
|
11
|
|
|
|
|
58097
|
|
|
11
|
|
|
|
|
3263
|
|
10
|
|
|
|
|
|
|
has 'pdbserver', is => 'rw', isa => 'Str', lazy => 1, default => 'https://files.rcsb.org/download/'; |
11
|
|
|
|
|
|
|
has 'overwrite', is => 'rw', isa => 'Bool', lazy => 1, default => 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $pdbid = shift; |
14
|
|
|
|
|
|
|
$pdbid =~ s/\.pdb//; #just in case |
15
|
0
|
|
|
0
|
|
|
$pdbid .= '.pdb'; |
16
|
0
|
|
|
|
|
|
return $pdbid; |
17
|
0
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#return pdb contents downloaded from pdb.org |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
my $pdbid = _fix_pdbid(shift); |
22
|
|
|
|
|
|
|
my ($ok, $why) = HTTP::Tiny->can_ssl; |
23
|
0
|
|
|
0
|
1
|
|
if ($ok){ |
24
|
0
|
|
|
|
|
|
my $pdb = HTTP::Tiny->new->get($self->pdbserver.$pdbid); |
25
|
0
|
|
|
|
|
|
return ( $pdb->{content} ); |
26
|
0
|
0
|
|
|
|
|
} |
27
|
0
|
|
|
|
|
|
else { |
28
|
0
|
|
|
|
|
|
warn "$why"; |
29
|
|
|
|
|
|
|
return 0; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#return array of lines from pdb downloaded from pdb.org |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $pdbid = _fix_pdbid(shift); |
36
|
|
|
|
|
|
|
my $fpdbid = shift ; |
37
|
|
|
|
|
|
|
$fpdbid = $pdbid unless defined($fpdbid); |
38
|
0
|
|
|
0
|
1
|
|
$fpdbid = path($fpdbid); |
39
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
if ($fpdbid->exists and not $self->overwrite){ |
41
|
0
|
0
|
|
|
|
|
carp "$fpdbid exists, set self->overwrite(1) to overwrite"; |
42
|
0
|
|
|
|
|
|
return $fpdbid->stringify; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
0
|
0
|
|
|
|
my $pdb = $self->get_pdbid( $pdbid ); |
45
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
if ($pdb){ |
47
|
|
|
|
|
|
|
$fpdbid->spew($pdb); |
48
|
0
|
|
|
|
|
|
return ( $fpdbid->stringify ); |
49
|
|
|
|
|
|
|
} |
50
|
0
|
0
|
|
|
|
|
else{ |
51
|
0
|
|
|
|
|
|
warn "could not connect, $fpdbid not written\n"; |
52
|
0
|
|
|
|
|
|
return 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
no Moose::Role; |
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
11
|
|
|
11
|
|
95
|
=pod |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
138
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
HackaMol::Roles::FileFetchRole - Role for using LWP::Simple to fetch files from www |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.053 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use HackaMol; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $pdb = $HackaMol->new->get_pdbid("2cba"); |
75
|
|
|
|
|
|
|
print $pdb; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
FileFetchRole provides attributes and methods for pulling files from the internet. |
80
|
|
|
|
|
|
|
Currently, the Role has one method and one attribute for interacting with the Protein Database. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 get_pdbid |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
fetches a pdb from pdb.org and returns the file in a string. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 getstore_pdbid |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
arguments: pdbid and filename for writing (optional). |
91
|
|
|
|
|
|
|
Fetches a pdb from pdb.org and stores it in your working directory unless {it exists and overwrite(0)}. If a filename is not |
92
|
|
|
|
|
|
|
passed to the method, it will write to $pdbid.pdb. use get_pdbid to return contents |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 overwrite |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
isa lazy ro Bool that defaults to 0 (false). If overwrite(1), then fetched files will be able to overwrite |
99
|
|
|
|
|
|
|
those of same name in working directory. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 pdbserver |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
isa lazy rw Str that defaults to http://pdb.org/pdb/files/ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over 4 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<http://www.pdb.org> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L<LWP::Simple> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 AUTHOR |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Demian Riccardi <demianriccardi@gmail.com> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Demian Riccardi. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
128
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |