annotate tools/rdock/lib/run_rbfuncs.pl @ 2:7e52b8fb2df4 draft

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