annotate galaxy-tools/tools/rdock/lib/run_rbfuncs.pl @ 0:4eb3f9cb2a51 draft

Uploaded
author dzesikah
date Fri, 26 Aug 2016 09:53:37 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
1 #!/usr/bin/perl
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
2 # Perl functions for the run_rb* collection of automated docking scripts
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
3
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
4 use strict;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
5
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
6 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
7 # sub get_prm_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
8 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
9 # Purpose: return a hash table of
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
10 # key=parameter file name, value = file title
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
11 # for all .prm files in a directory
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
12 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
13 # Usage: %prm_table = get_prm_table($dir)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
14 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
15 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
16 # $prmDir - directory to search for .prm files
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
17 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
18 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
19 # %prm_table - hash table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
20 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
21 sub get_prm_table {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
22 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
23 my $prm_dir = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
24
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
25 #Local variables
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
26 my @prm_list;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
27 my %prm_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
28 my $TITLEREC = "TITLE ";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
29 my $file;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
30 my $title;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
31 my @titleLines;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
32
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
33 #Get the list of files ending in .prm
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
34 @prm_list = glob "$prm_dir/*.prm";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
35
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
36 #Read each file and extract the title record
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
37 foreach $file (@prm_list) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
38 open PRMHANDLE,$file;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
39 @titleLines = grep /^$TITLEREC/,<PRMHANDLE>;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
40 close PRMHANDLE;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
41 #Extract just the file name from the full path
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
42 my $prmName = substr($file, rindex($file,"/")+1);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
43 #Check if a title record was found
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
44 if (scalar @titleLines) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
45 $title = substr $titleLines[0],length($TITLEREC);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
46 chomp $title;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
47 $prm_table{$prmName} = $title;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
48 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
49 else {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
50 $prm_table{$prmName} = "No title";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
51 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
52 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
53 return %prm_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
54 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
55 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
56 # sub get_dock_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
57 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
58 # Purpose: Modified version of get_prm_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
59 # specific for the RBT_LIGDB docking database
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
60 # Return a hash table of
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
61 # key=docking library, value = expression for all sd files in that library
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
62 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
63 # Assumes that all subdirs within $db_dir are separate vendor libraries,
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
64 # and that each subdir contains a set of compressed .sd.gz files
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
65 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
66 # Usage: %dock_table = get_dock_table($dir)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
67 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
68 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
69 # $db_dir - directory to search for docking libraries
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
70 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
71 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
72 # %dock_table - hash table#
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
73 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
74 sub get_dock_table {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
75 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
76 my $db_dir = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
77
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
78 #Local variables
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
79 my ($lib,$sdfiles);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
80 my (@lib_list,@sd_list);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
81 my %dock_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
82
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
83 opendir DBDIR,$db_dir;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
84 @lib_list = readdir DBDIR;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
85 closedir DBDIR;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
86
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
87 foreach $lib (sort @lib_list) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
88 if (-d "$db_dir/$lib") {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
89 $sdfiles = "$db_dir/$lib/*.sd*";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
90 @sd_list = glob $sdfiles;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
91 my $n = scalar(@sd_list);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
92 if ($n > 0) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
93 $dock_table{"$lib ($n files)"} = $sdfiles;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
94 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
95 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
96 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
97
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
98 return %dock_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
99 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
100 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
101 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
102 # sub get_selection
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
103 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
104 # Purpose: allow a user to select from
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
105 # a list of parameter files.
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
106 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
107 # Usage: $receptor = get_selection(\%prm_table,"receptor")
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
108 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
109 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
110 # $prm_table_ref - reference to hash table returned by get_prm_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
111 # $name - descriptive name for items (e.g. "receptor" or "script"
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
112 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
113 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
114 # $item - selected items (key into %prm_table)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
115 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
116 sub get_selection {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
117 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
118 my $prm_table_ref = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
119 my $name = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
120
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
121 #Local variables
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
122 my @items = sort keys %$prm_table_ref;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
123 my $nItems = scalar @items;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
124 my ($i,$itemNum,$item);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
125 my $inRange;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
126
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
127 print "\n\n$name selection:\n\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
128 $i=1;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
129 foreach $item (@items) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
130 print "$i\t$item\t$$prm_table_ref{$item}\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
131 $i++;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
132 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
133 do {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
134 print "\nEnter the $name number: ";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
135 $itemNum = <STDIN>;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
136 chomp $itemNum;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
137 print "\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
138 $inRange = (($itemNum >= 1) && ($itemNum <= $nItems));
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
139 print "$itemNum is out of range\n" if (!$inRange);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
140 } until ($inRange);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
141
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
142 print "\nYou have selected the following $name\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
143 $item = $items[$itemNum-1];
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
144 print "$itemNum\t$item\t$$prm_table_ref{$item}\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
145 return $item;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
146 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
147
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
148 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
149 # sub get_multiple_selection
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
150 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
151 # Purpose: allow a user to multiply select from the docking library list
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
152 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
153 # Usage: $receptor = get_selection(\%prm_table,"receptor")
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
154 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
155 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
156 # $prm_table_ref - reference to hash table returned by get_prm_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
157 # $name - descriptive name for items (e.g. "receptor" or "script"
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
158 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
159 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
160 # $item - selected items (key into %prm_table)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
161 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
162 sub get_multiple_selection {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
163 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
164 my $prm_table_ref = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
165 my $name = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
166
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
167 #Local variables
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
168 my @items = sort keys %$prm_table_ref;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
169 my $nItems = scalar @items;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
170 my ($i,$idstring,$itemNum,$item);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
171 my @itemNums;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
172 my @selectedItems;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
173 my $inRange;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
174 my $allInRange;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
175
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
176 print "\n\n$name selection:\n\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
177 $i=1;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
178 foreach $item (@items) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
179 print "$i\t$item\t$$prm_table_ref{$item}\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
180 $i++;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
181 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
182 do {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
183 print "\nEnter the $name number(s): ";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
184 my $idstring = <STDIN>;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
185 chomp $idstring;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
186 @itemNums = get_ids($idstring);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
187 print "\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
188 $allInRange = 1;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
189 foreach $itemNum (@itemNums) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
190 $inRange = (($itemNum >= 1) && ($itemNum <= $nItems));
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
191 print "$itemNum is out of range\n" if (!$inRange);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
192 $allInRange = $allInRange && $inRange;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
193 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
194 } until ($allInRange);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
195
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
196 print "\nYou have selected the following $name(s)\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
197 foreach $itemNum (@itemNums) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
198 $item = $items[$itemNum-1];
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
199 push @selectedItems,$item;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
200 print "$itemNum\t$item\t$$prm_table_ref{$item}\n";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
201 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
202 return @selectedItems;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
203 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
204
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
205 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
206 # sub get_input
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
207 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
208 # Purpose: get user input, or returns default if no response given
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
209 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
210 # Usage: $nRuns = get_input("Enter no. of runs per ligand",10)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
211 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
212 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
213 # $question - text of question to ask
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
214 # $defResponse - default answer
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
215 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
216 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
217 # $response - user response, or default
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
218
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
219 sub get_input {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
220 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
221 my $question = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
222 my $defResponse = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
223 print "$question [$defResponse]: ";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
224 my $response = <STDIN>;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
225 chomp $response;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
226 $response = $defResponse if ($response eq "");
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
227 return $response;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
228 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
229
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
230 # Based on //depot/intranet/1.0/lib/rbt_func.pl#1
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
231 # this function converts a list of ids in one string
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
232 # in the format 1,2,4-6,8,15-20
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
233 # and returns an @array with the unique ids
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
234 sub get_ids {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
235 my $idstring = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
236 my %ids;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
237
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
238 foreach my $id (split (',',$idstring)){
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
239 if ( grep (/-/,$id)){
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
240 (my $low, my $up) = split ('-',$id);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
241 for ( my $co = $low; $co <= $up; $co++ ){
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
242 $ids{$co}=$co;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
243 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
244 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
245 else {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
246 $ids{$id}=$id;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
247 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
248 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
249
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
250 return (sort {$a<=>$b} keys %ids);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
251 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
252 ################################################################################
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
253 # sub get_filter_table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
254 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
255 # Purpose: return a hash table of
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
256 # key=filter file name, value = file title
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
257 # for all .filter files in a directory
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
258 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
259 # Usage: %filter_table = get_filter_table($dir)
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
260 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
261 # Arguments:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
262 # $filterDir - directory to search for .filter files
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
263 # $tmp - temperature for first filter
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
264 # Note:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
265 # The first two filters are not in a file, but are created here
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
266 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
267 # Return parameters:
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
268 # %filter_table - hash table
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
269 #
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
270 sub get_filter_table {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
271 #Arguments
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
272 my $filter_dir = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
273 my $tmp = shift;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
274
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
275 #Local variables
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
276 my $pwd = $ENV{"PWD"};
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
277 my @filter_list;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
278 my %filter_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
279 my $file;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
280
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
281 #Get the list of files ending in .filter
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
282 @filter_list = ((glob "$pwd/*.filter"), (glob "$filter_dir/*.filter"));
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
283 $filter_table{"1no_other_filters"} = "";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
284 # $filter_table{"1threshold"} = "\tSCORE.INTER < $tmp";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
285 # $filter_table{"2cavity"} = "\t\tSCORE.RESTR.CAVITY < 1 ";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
286
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
287 #Read each file and extract the title record
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
288 foreach $file (@filter_list) {
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
289 #Extract just the file name from the full path
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
290 my $filterName = substr($file, rindex($file,"/")+1);
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
291 #Check if a title record was found
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
292 $filter_table{$filterName} = "No title";
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
293 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
294 return %filter_table;
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
295 }
4eb3f9cb2a51 Uploaded
dzesikah
parents:
diff changeset
296 1;