-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdb_archive_filter.pl
executable file
·269 lines (225 loc) · 7.26 KB
/
pdb_archive_filter.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/perl
# DESCRIPTION:
# This program reads and processes PDB archive files
# in a way that retrieves the number of ATOMS in each
# file associated with publication year and resolution
# in Angstroms.
#
#------------------------------------------------------
# INPUT FORMAT:
# This program can only process PDB or CIF file formats.
# This means that inputs have to be PDB or CIF files.
# Also it is possible to provide a directory name that
# has PDB or CIF files stored in it for analysis. In
# this case the program will analyze every file in that
# directory.
#
#------------------------------------------------------
# OUTPUT FORMAT:
# Output format is a tab seperated text file. That
# has FILENAME, NUMBER_OF_ATOMS, PUBLICATION_DATE and
# RESOLUTION_VALUE fields. The fields are self
# explanatory. Each row represents a different file.
#
#------------------------------------------------------
# USAGE:
# Providing a directory with PDB files:
# ./pdb_archive_filter -d -pdb directory_path
#
# Providing an array of CIF files:
# ./pdb_archive_filter -cif file_1.cif \
# file_2.cif file_3.cif.gz
#
# Providing a single PDB file:
# ./pdb_archive_filter -pdb file_1.pdb
#
#------------------------------------------------------
use strict;
use warnings;
my ($svn_id) = ('$Id: pdb_file_statistics.pl 22 2023-01-09 14:09:29Z karolis $' =~ /^\$Id: (.*) \$$/);
print $svn_id, "\n\n";
#------------------------------------------------------
# Checking if required commands are installed in this
# linux device.
my $check = `bash scripts/command_check.sh`;
if( $check == 1 ) {
die "Missing linux command cod-tools. You",
" can download this command here: ",
"https://github.com/cod-developers/cod-tools.";
}
#------------------------------------------------------
# Processing options and errors if there are any.
if( scalar @ARGV == 0 ) {
die "No input file. In order for the ",
"program to work an input file or - for ",
"the standart input has to be specified ",
"in program: ( $0 ).",
"\n";
}
my $dash_option = 0;
my $directory_option = 0;
my $cif_option = 0;
my $pdb_option = 0;
my @arguments = @ARGV;
for my $element ( @arguments ) {
if( $element =~ /^-$/ ) {
$dash_option = 1;
@ARGV = grep {$_ ne "-"} @ARGV;
}
elsif( $element =~ /^-pdb$/ ) {
$pdb_option = 1;
@ARGV = grep {$_ ne '-pdb'} @ARGV;
}
elsif( $element =~ /^-cif$/ ) {
$cif_option = 1;
@ARGV = grep {$_ ne '-cif'} @ARGV;
}
elsif( $element =~ /^-d$/ ) {
$directory_option = 1;
@ARGV = grep {$_ ne '-d'} @ARGV;
}
elsif( $element =~ /^-.+$/ ) {
die "Unknown option specified. Option $element ",
"is unknown, please correct it or refer to the ",
"OPTIONS section in the README.txt file.",
"\n";
}
}
my $sum = $directory_option + $dash_option + $pdb_option +
$cif_option;
if( $sum == 0 ) {
die "No options were specified. Because the program has ",
"no default settings it is necessary to specify ",
"options. Please refer to the OPTIONS section in the ",
"README.txt file.",
"\n";
}
elsif( $directory_option == $sum ) {
die "Option -d has to be used with one another option. ",
"Either -pdb or -cif according to the files that are ",
"going to be analyzed. Please refer to the OPTIONS ",
"section in the README.txt file.",
"\n";
}
elsif( $directory_option == 1 && $dash_option == 1 ) {
die "Option -d cannot be used with - option together. - ",
"has to be used alone. -d option has to be used with ",
"either -pdb or -cif options according to the files ",
"you are analyzing. Please refer to the OPTIONS section ",
"in the README.txt file.",
"\n";
}
elsif( $pdb_option == 1 && $cif_option == 1 ) {
die "Options -pdb and -cif cannot be used together. Use one ",
"that refers to the type of files you are analyzing. ",
"Please refer to the OPTIONS section in the README.txt ",
"file.",
"\n";
}
elsif( $dash_option == 1 && scalar @ARGV != 1 ) {
die "When using - option it can only be the single possible ",
"argument. No other file names can be specified. ",
"Please refer to the OPTIONS section in the READMNE.txt ",
"file.",
"\n";
}
#------------------------------------------------------
# File processing part.
# Extracting the current year from localtime()
# function and saving the file names into an
# array.
my $current_time = localtime();
my @time_array = split( ' ', $current_time );
my $current_year = $time_array[4];
my $year_part = substr( $current_year, -2 );
my @file_array = @ARGV;
print "ID\tYEAR\tMETHOD\tRESOLUTION\tATOMCOUNT\n";
# This block is used to process files that are passed
# as arguments (not a directory) for either PDB or
# CIF formats.
if( $directory_option == 0 ) {
if( $pdb_option == 1) {
my $file = $ARGV[0];
my $output = `bash scripts/one_file_processing.sh $file PDB`;
my @output_arr = split('\|', $output);
my $year = 0;
for my $i (0 .. $#output_arr) {
if( $output_arr[$i] eq "" ) {
$output_arr[$i] = "N\/A";
}
}
if ( $output_arr[1] =~ /^\d{2}$/ ) {
if( $output_arr[1] ne "N\/A" and int($output_arr[1]) > int($year_part) ) {
$year = "19" . $output_arr[1];
}
else {
$year = "20" . $output_arr[1];
}
}
print "$output_arr[0]\t$year\t$output_arr[2]",
"\t$output_arr[3]\t$output_arr[4]\n";
}
elsif( $cif_option == 1) {
my $file = $ARGV[0];
my $output = `bash scripts/one_file_processing.sh $file CIF`;
my @output_arr = split('\|', $output);
for my $i (0 .. $#output_arr) {
if( $output_arr[$i] eq "." or $output_arr[$i] eq "?" ) {
$output_arr[$i] = "N\/A";
}
}
print "$output_arr[0]\t$output_arr[1]\t$output_arr[2]",
"\t$output_arr[3]\t$output_arr[4]\n";
}
}
# This block is used for processing a passed
# directory for either PDB or CIF files.
else {
if( $pdb_option == 1 ){
for my $element ( @ARGV ) {
# Getting file name information from a
# shell script.
my @files = `bash scripts/directory_processing.sh $element PDB`;
for my $filename ( @files ) {
chomp( $filename );
my $output = `bash scripts/one_file_processing.sh $element/$filename PDB`;
my @output_arr = split('\|', $output);
for my $i (0 .. $#output_arr) {
if( $output_arr[$i] eq "" ) {
$output_arr[$i] = "N\/A";
}
}
my $year = 0;
if ( $output_arr[1] =~ /^\d{2}$/ ) {
if( $output_arr[1] ne "N\/A" and int($output_arr[1]) > int($year_part) ) {
$year = "19" . $output_arr[1];
}
else {
$year = "20" . $output_arr[1];
}
}
print "$output_arr[0]\t$year\t$output_arr[2]",
"\t$output_arr[3]\t$output_arr[4]\n";
}
}
}
elsif( $cif_option == 1 ){
for my $element ( @ARGV ) {
# Getting file name information from a
# shell script.
my @files = `bash scripts/directory_processing.sh $element CIF`;
for my $filename ( @files ) {
chomp( $filename );
my $output = `bash scripts/one_file_processing.sh $element/$filename CIF`;
my @output_arr = split('\|', $output);
for my $i (0 .. $#output_arr) {
if( $output_arr[$i] eq "." or $output_arr[$i] eq "?" ) {
$output_arr[$i] = "N\/A";
}
}
print "$output_arr[0]\t$output_arr[1]\t$output_arr[2]",
"\t$output_arr[3]\t$output_arr[4]\n";
}
}
}
}