annotate tools/rdock/bin/sdreport @ 2:0faa03a92843 draft default tip

Uploaded
author dzesikah
date Fri, 26 Aug 2016 10:19:49 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
1 #!/usr/bin/perl
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
2 # Produces text summaries of SD records *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
3 # *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
4 # Usage: sdreport [-l] [-t] [-s<DataField>] [sdFiles] *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
5 # *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
6 # -l output data fields for each record as processed *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
7 # -t tabulate Rbt.Score.* fields for each record as processed *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
8 # -s summarise data fields for all records *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
9 # -s<DataField> summarise data fields for each unique value *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
10 # of <DataField> *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
11 # *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
12 # Note: If -l or -t are combined with -s, the listing/table is output *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
13 # within each ligand summary *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
14 # If sdFiles not given, reads from standard input *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
15 # Output is to standard output *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
16 # Default is equivalent to sdfilter -l *
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
17 #*******************************************************************************
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
18 use lib "$ENV{'RBT_ROOT'}/lib";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
19
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
20 use SDRecord;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
21
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
22 # Default field names and headings for rDock v4.00 scores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
23 my @defaultFields = ('SCORE','SCORE.INTER','SCORE.INTRA','SCORE.RESTR','SCORE.INTER.VDW');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
24 my @defaultHeadings = ('TOTAL','INTER','INTRA','RESTR','VDW');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
25
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
26 # Default field names and headings for normalised scores (score / #ligand heavy atoms)
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
27 my @defaultNormFields = ('SCORE.norm','SCORE.INTER.norm','SCORE.INTRA.norm','SCORE.RESTR.norm','SCORE.heavy');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
28 my @defaultNormHeadings = ('TOTALn','INTERn','INTRAn','RESTRn','#heavy');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
29
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
30 # Default field names and headings for rDock v3.00 scores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
31 my @defaultOldFields = ('Rbt.Score.Corrected','Rbt.Score.Inter','Rbt.Score.Intra','Rbt.Score.IntraMin','Rbt.Score.Restraint');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
32 my @defaultOldHeadings = ('TOTAL','INTER','INTRA','INTRAMIN','RESTR');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
33
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
34 my $listFormat = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
35 my $summaryFormat = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
36 my $tableFormat = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
37 my $supplierFormat = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
38 my $csvFormat = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
39 my $summaryKey = "_TITLE1";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
40 my $oldFields = 0;#If true, use old default field names for component scores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
41 my $headings = 1;#DM 21 Nov 2000, If false, don't output headings
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
42 my @outputFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
43 my @outputHeadings;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
44
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
45 #Print help if no command line arguments
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
46 printHelpAndExit() if (scalar(@ARGV) == 0);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
47
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
48 #Parse command line arguments
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
49 my $nArgs = scalar(@ARGV);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
50
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
51 while (scalar(@ARGV)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
52 my $arg = shift @ARGV;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
53 printHelpAndExit() if ($arg eq '-h');
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
54 if (index($arg,'-l')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
55 $listFormat = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
56 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
57 elsif (index($arg,'-o')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
58 $oldFields = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
59 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
60 # 7 Feb 2005 (DM) Option to report normalised aggregate scores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
61 elsif (index($arg,'-norm')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
62 $oldFields = 2;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
63 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
64 elsif (index($arg,'-sup')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
65 $supplierFormat = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
66 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
67 elsif (index($arg,'-s')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
68 $summaryFormat = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
69 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
70 elsif (index($arg,'-id')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
71 $summaryKey = substr($arg,3);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
72 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
73 elsif (index($arg,'-nh')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
74 $headings = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
75 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
76 elsif (index($arg,'-t')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
77 $tableFormat = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
78 push @outputFields, split(',',substr($arg,2));
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
79 push @outputHeadings, @outputFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
80 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
81 elsif (index($arg,'-c')==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
82 $csvFormat = 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
83 push @outputFields, split(',',substr($arg,2));
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
84 push @outputHeadings, @outputFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
85 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
86 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
87 push @files,$arg;#must be a filename
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
88 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
89 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
90 push @ARGV,@files;#put the filenames back in the arg list
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
91
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
92 #use -l if neither table format is specified
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
93 $listFormat = (!$tableFormat && !$csvFormat && !$supplierFormat);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
94
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
95 #If no output fields defined for -t or -c use the defaults (old or new)
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
96 if (scalar(@outputFields)==0) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
97 if ($oldFields == 1) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
98 @outputFields = @defaultOldFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
99 @outputHeadings = @defaultOldHeadings;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
100 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
101 elsif ($oldFields == 2) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
102 @outputFields = @defaultNormFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
103 @outputHeadings = @defaultNormHeadings;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
104 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
105 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
106 @outputFields = @defaultFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
107 @outputHeadings = @defaultHeadings;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
108 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
109 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
110
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
111 my $sdRec = new SDRecord;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
112 my %summary;#hash of SDRecord lists, indexed by user-defined summary key
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
113 my %indexByName;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
114 my %indexByNum;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
115 my $idx = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
116 my $nRec = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
117
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
118 #Column headings for tab and csv format
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
119 #DM 21 Nov 2000 - if $headings is false, then don't output the column headings
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
120 if ($tableFormat && !$summaryFormat && $headings) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
121 tabHeadings($summaryKey,@outputHeadings);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
122 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
123 if ($csvFormat && !$summaryFormat && $headings) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
124 csvHeadings($summaryKey,@outputHeadings);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
125 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
126
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
127 #read records
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
128 while ($sdRec->readRec('LINES'=>1,'DATA'=>1)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
129 $sdRec->addData('_REC' => ++$nRec);#add record# as temp data field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
130 if ($listFormat && !$summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
131 print "\n\nRECORD #$nRec\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
132 $sdRec->writeData();
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
133 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
134 if ($tableFormat && !$summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
135 @recList = ($sdRec);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
136 tabScores(\@recList,$summaryKey,@outputFields);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
137 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
138 elsif ($csvFormat && !$summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
139 @recList = ($sdRec);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
140 csvScores(\@recList,$summaryKey,@outputFields);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
141 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
142 elsif ($supplierFormat && !$summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
143 @recList = ($sdRec);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
144 tabulateSuppliers(\@recList,$summaryKey);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
145 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
146 #add record to summary, indexed by user field value
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
147 #keep a separate index of unique values of user field values,
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
148 #indexed by number in the order the values first appear
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
149 #In this way we can maintain the sorted order of ligands
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
150 #when we come to print out the summary
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
151 if ($summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
152 my $summaryValue = $sdRec->{'DATA'}->{$summaryKey};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
153 #New data field value encountered
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
154 if (!defined $indexByName{$summaryValue}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
155 $idx++;#incr the number of unique values
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
156 #keep cross-referenced indexes (field value <-> number)
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
157 $indexByName{$summaryValue} = $idx;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
158 $indexByNum{$idx} = $summaryValue;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
159 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
160 push @{$summary{$summaryValue}},$sdRec->copy('DATA'=>1);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
161 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
162 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
163
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
164 #Print summary if required
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
165 if ($summaryFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
166 print "\n===============================================================\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
167 print "SUMMARY BY $summaryKey\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
168 foreach $idx (sort {$a<=>$b} keys %indexByNum) {#numberic sort of index numbers
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
169 my $key = $indexByNum{$idx};#look up corresponding data field value
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
170 print "\n===============================================================\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
171 print "$summaryKey = $key (#$idx)\n\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
172 writeSummary($summary{$key});
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
173 if ($listFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
174 print "\nIndividual records:\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
175 foreach $rec (@{$summary{$key}}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
176 print "\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
177 $rec->writeData();
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
178 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
179 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
180 if ($tableFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
181 print "\nScores:\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
182 tabHeadings($summaryKey,@outputHeadings);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
183 tabScores($summary{$key},$summaryKey,@outputFields);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
184 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
185 if ($csvFormat) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
186 print "\nScores:\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
187 csvHeadings($summaryKey,@outputHeadings);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
188 csvScores($summary{$key},$summaryKey,@outputFields);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
189 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
190 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
191 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
192
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
193 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
194 # writes a summary to STDOUT for a list of SDRecords
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
195 # Input is a reference to an array of SDRecords
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
196 sub writeSummary {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
197 my $recListRef = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
198
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
199 #Extract the list of data values for each fieldname into a hash array
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
200 #(key=fieldname, value=array ref)
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
201 my %fields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
202 foreach $rec (@{$recListRef}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
203 my ($key,$value);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
204 while ( ($key,$value) = each %{$rec->{'DATA'}}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
205 push @{$fields{$key}},$value;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
206 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
207 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
208
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
209 #Look for constant fields and store separately
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
210 my %constFields;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
211 foreach $key (keys %fields) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
212 my @values = sort @{$fields{$key}};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
213 my $nVal = scalar(@values);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
214 if ($values[0] eq $values[$nVal -1]) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
215 $constFields{$key} = $values[0];#store the field name and the constant value
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
216 delete $fields{$key};#remove from (non-const) array
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
217 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
218 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
219
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
220 #Print constant fields
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
221 print "\nConstant fields:\n\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
222 foreach $key (sort keys %constFields) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
223 printf "%-40s%s\n",$key,$constFields{$key};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
224 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
225 #Print min and max value for non-const fields
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
226 print "\nVariable fields:\n\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
227 foreach $key (sort keys %fields) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
228 my @values = @{$fields{$key}};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
229 #Look at first value to decide whether to do text or numeric sort
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
230 if (isNaN($values[0])) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
231 @values = sort @values;#text sort
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
232 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
233 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
234 @values = sort {$a <=> $b} @values;#numeric sort
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
235 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
236 my $nVal = scalar(@values);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
237 printf "%-40s",$key;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
238 print "Min = $values[0]\tMax = $values[$nVal-1]\t(N = $nVal)\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
239 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
240 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
241
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
242 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
243 # function isNaN equivalent to the C++, java, javascript isNaN
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
244 # From P Vaglio, ~intranet/lib/rbt_func.pl
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
245 sub isNaN {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
246 local($_) = @_;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
247 s/\s+//g; # strip white space
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
248 # match +or- beginning of line 0 or 1 time
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
249 # then any numeric 0 or more
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
250 # then a decimal point
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
251 # then any numeric 0 or more after decimal point
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
252 # then possibly an e or E then + or - then any numreci at least once
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
253 if (/^([+-]?)(\d*)(\.(\d*))?([Ee]([+-]?\d+))?$/ && (defined $2 || defined $4)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
254 return 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
255 } else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
256 return 1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
257 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
258 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
259
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
260 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
261 # output corresponding headings for use with tabScores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
262 sub tabHeadings {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
263 my $summaryKey = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
264 my @fieldNames = @_;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
265 printf("%-10s%-30s","REC",$summaryKey);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
266 foreach $field (@fieldNames) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
267 printf("%10s",$field);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
268 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
269 print "\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
270 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
271
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
272 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
273 # tab-delimited output of named data field values
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
274 sub tabScores {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
275 my $recListRef = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
276 my $summaryKey = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
277 my @fieldNames = @_;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
278 foreach $rec (@{$recListRef}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
279 printf("%03d\t%-30.30s",$rec->{'DATA'}->{'_REC'},$rec->{'DATA'}->{$summaryKey});
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
280 foreach $field (@fieldNames) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
281 my $val = $rec->{'DATA'}->{$field};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
282 if (isNaN($val)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
283 printf("%-10.12s",$val);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
284 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
285 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
286 printf("%10.3f",$val);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
287 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
288 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
289 print "\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
290 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
291 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
292
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
293 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
294 # output corresponding headings for use with csvScores
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
295 sub csvHeadings {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
296 my $summaryKey = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
297 my @fieldNames = @_;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
298 printf("%s,%s","REC",$summaryKey);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
299 foreach $field (@fieldNames) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
300 printf(",%s",$field);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
301 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
302 print "\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
303 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
304
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
305 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
306 # comma-delimited output of named data field values
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
307 sub csvScores {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
308 my $recListRef = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
309 my $summaryKey = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
310 my @fieldNames = @_;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
311 foreach $rec (@{$recListRef}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
312 printf("%d,%s",$rec->{'DATA'}->{'_REC'},$rec->{'DATA'}->{$summaryKey});
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
313 foreach $field (@fieldNames) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
314 my $val = $rec->{'DATA'}->{$field};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
315 if (isNaN($val)) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
316 printf(",%s",$val);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
317 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
318 else {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
319 printf(",%.3f",$val);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
320 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
321 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
322 print "\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
323 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
324 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
325
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
326
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
327 ##############################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
328 # standardised output of Catalyst supplier field
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
329 # Input is a reference to an array of SDRecords
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
330 # and a ligand identifier field to output in column 1 (def=Name)
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
331 sub tabulateSuppliers {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
332 my $recListRef = shift;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
333 my $summaryKey = shift || 'Name';
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
334 foreach $rec (@{$recListRef}) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
335 my $suppBase = $rec->{'DATAREF'}->{'Supplier'}+1;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
336 my $linesRef = $rec->{'LINES'};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
337 my $name = $rec->{'DATA'}->{$summaryKey};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
338
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
339 #Output some useful compound info
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
340 my $name = $rec->{'DATA'}->{$summaryKey};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
341 my $molFormula = $rec->{'DATA'}->{'MolFormula'};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
342 my $molWt = $rec->{'DATA'}->{'MolWt'};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
343 my $casNum = $rec->{'DATA'}->{'CAS_num'};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
344 my $mdlNum = $rec->{'DATA'}->{'MDLNUMBER'};
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
345 print "\n\n====================================================================================================\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
346 printf("%-10.10s%s\n","Name:",$name);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
347 printf("%-10.10s%s\n","Formula:",$molFormula);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
348 printf("%-10.10s%s\n","Mol.wt:",$molWt);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
349 printf("%-10.10s%s\n","CAS #:",$casNum);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
350 printf("%-10.10s%s\n","MDL #:",$mdlNum);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
351
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
352 #Get all the supplier record lines into a list
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
353 #Record is terminated by blank line
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
354 my @lines;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
355 my $nLines = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
356 for (; $$linesRef[$suppBase+$nLines] ne ""; $nLines++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
357 push @lines,$$linesRef[$suppBase+$nLines];
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
358 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
359
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
360 #Column headings
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
361 printf("\n%-20.20s%-40.40s%-40.40s\n",
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
362 "Supplier",
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
363 "Comment",
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
364 "Price"
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
365 );
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
366 print "----------------------------------------------------------------------------------------------------\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
367
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
368 #Loop over each supplier
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
369 my $iLine = 0;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
370 for (; $iLine < $nLines; $iLine++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
371 #collect supplier info lines
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
372 my @supplierInfo = ();
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
373 for (; $lines[$iLine] ne "." && $iLine < $nLines; $iLine++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
374 push @supplierInfo,$lines[$iLine];
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
375 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
376 #Check for incomplete record
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
377 if ($iLine == $nLines) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
378 print "** INCOMPLETE RECORD **\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
379 last;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
380 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
381 my $nSupplierInfo = scalar(@supplierInfo);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
382 my $supplier = $supplierInfo[0];
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
383 #loop over each grade
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
384 for ($iLine++; ($lines[$iLine] ne "........................") && ($iLine < $nLines); $iLine++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
385 #collect grade info lines
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
386 my @gradeInfo = ();
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
387 for (; index($lines[$iLine],"_") ne 0 && $iLine < $nLines; $iLine++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
388 push @gradeInfo,$lines[$iLine];
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
389 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
390 #Check for incomplete record
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
391 if ($iLine == $nLines) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
392 print "** INCOMPLETE RECORD **\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
393 last;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
394 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
395 my $grade = $gradeInfo[0];
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
396 #loop over each price info line
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
397 for (; index($lines[$iLine],".") ne 0 && $iLine < $nLines; $iLine++) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
398 my @priceInfo = split(" ",$lines[$iLine]);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
399 my $price = join(" ",@priceInfo);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
400 printf("%-20.20s%-40.39s%-40.40s\n",
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
401 $supplier,
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
402 $grade,
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
403 $price);
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
404 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
405 #Check for incomplete record
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
406 if ($iLine == $nLines) {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
407 print "** INCOMPLETE RECORD **\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
408 last;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
409 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
410 last if $lines[$iLine] eq "........................";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
411 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
412 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
413 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
414 }
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
415
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
416
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
417 #######################################################################
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
418 sub printHelpAndExit {
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
419 print "\nProduces text summaries of SD records\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
420 print "\nUsage:\tsdreport [-l] [-t[<FieldName,FieldName...>]] [-c<FieldName,FieldName...>] [-id<IDField>] [-nh] [-o] [-s] [-sup] [sdFiles]\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
421 print "\n\t-l (list format) output all data fields for each record as processed\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
422 print "\t-t (tab format) tabulate selected fields for each record as processed\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
423 print "\t-c (csv format) comma delimited output of selected fields for each record as processed\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
424 print "\t-s (summary format) output summary statistics for each unique value of ligand ID\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
425 print "\t-sup (supplier format) tabulate supplier details (from Catalyst)\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
426 print "\t-id<IDField> data field to use as ligand ID\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
427 print "\t-nh don't output column headings in -t and -c formats\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
428 print "\t-o use old (v3.00) score field names as default columns in -t and -c formats, else use v4.00 field names\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
429 print "\t-norm use normalised score field names as default columns in -t and -c formats (normalised = score / #ligand heavy atoms)\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
430 print "\nNote:\tIf -l, -t or -c are combined with -s, the listing/table is output within each ligand summary\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
431 print "\t-sup should not be combined with other options\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
432 print "\tDefault field names for -t and -c are rDock score field names\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
433 print "\tDefault ID field name is Name\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
434 print "\n\tIf sdFiles not given, reads from standard input\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
435 print "\tOutput is to standard output\n\n";
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
436 exit;
0faa03a92843 Uploaded
dzesikah
parents:
diff changeset
437 }