-
Notifications
You must be signed in to change notification settings - Fork 7
/
update_PDB.pl
executable file
·92 lines (79 loc) · 2 KB
/
update_PDB.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
## Pombert Lab 2021
my $version = '0.3';
my $name = 'update_PDB.pl';
my $updated = '2022-02-23';
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
## Usage definition
my $USAGE = <<"OPTIONS";
NAME ${name}
VERSION ${version}
UPDATED ${updated}
SYNOPSIS Downloads/updates the RCSB PDB database with rsync
COMMAND ${name} \\
-o ./PDB \\
-d current \\
-n 15
OPTIONS:
-o (--outdir) PDB output directory [Default: PDB]
-n (--nice) Defines niceness (adjusts scheduling priority)
-v (--verbose) Adds verbosity
-d (--data) Data to download; current or obsolete [Default: current]
## current => /pub/pdb/data/structures/divided
## obsolete => /pub/pdb/data/structures/obsolete
## see https://www.rcsb.org/docs/programmatic-access/file-download-services
OPTIONS
die "\n$USAGE\n" unless @ARGV;
my $outdir = 'PDB';
my $data = 'current';
my $nice;
my $verbose;
GetOptions(
'o|outdir=s' => \$outdir,
'n|nice=i' => \$nice,
'd|data=s' => \$data,
'v|verbose' => \$verbose
);
## Checking output directory
unless (-d $outdir){
mkdir($outdir, 0755) or die "Cannot create $outdir: $!\n";
}
## Checking data type
$data = lc($data);
my $type = $data;
if ($data eq 'current'){ $data = 'divided'; }
elsif ($data eq 'obsolete'){ $data = 'obsolete'; }
else {
print "Unrecognized data type. Please use current or obsolete.\n";
print "Exiting...\n";
exit;
}
## Defining niceness / verbosity
my $prg = "";
if ($nice){ $prg = "nice -n $nice"; }
## Running task with adjusted niceness, if desired
print "Downloading $type RCSB PDB files with rsync:\n\n";
system ("$prg \\
rsync \\
-rlpt \\
--info=progress2 \\
-z \\
--delete \\
--port=33444 \\
rsync.rcsb.org::ftp_data/structures/$data/pdb/ \\
$outdir") == 0 or checksig();
### Subroutine(s)
sub checksig {
my $exit_value = $?;
my $modulo = $exit_value % 255;
if ($modulo == 2) {
print "\n\nSIGINT detected: Ctrl+C. Exiting...\n\n";
exit(1);
}
elsif ($modulo == 131) {
print "\n\nSIGTERM detected: Ctrl+\\. Exiting...\n\n";
exit(1);
}
}