ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/Genquire/load_tigr.cfg
Revision: 1.6
Committed: Wed Aug 25 20:32:42 2004 UTC (12 years, 1 month ago) by skchan
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +3 -1 lines
Log Message:
added some comments to make it obvious to change the use lib to point to the correct location of HelperMethods.pm.  It should be in /home/skchan/gq/BIO_SUPPORT/Genquire/Admin

Line File contents
1 # This config file was coded up by Simon Chan.
2 # It's a modifed version of the gb_flat.cfg.
3
4 ###############################################################
5 # The original comments:
6 # any cfg file must return a valid Context object
7 # based on whatever data source is being configured.
8 # see the AdaptorLayer documentation for details on
9 # how to construct your own Context object and adaptor layer
10 # for your own datasource.
11
12 # ALL METHODS OF Context.pm and ContextI must be available!
13
14 # The variables $Username, $Password, $IPAddress, and/or $Filename
15 # may be set here, and the values will appear in the appropriate
16 # box on the opening genquire GUI. This is FYI only!! Modifying
17 # their values from the GUI makes **no difference** to the final connection parameters,
18 # since the final Context object is created here!
19 ###############################################################
20
21
22 use Bio::SeqIO;
23 use Tk;
24 use Tk::widgets qw(FileSelect);
25 use DBI;
26
27 use lib '/home/skchan/gq/BIO_SUPPORT/Genquire/Admin'; # This points to the location of the HelperMethods.pm
28 # It should be in your Admin directory. Modify this to point
29 # to the correct location on your machine.
30 use HelperMethods;
31
32 my $tigr_xml_main_window = MainWindow->new;
33 my $FileMW = $tigr_xml_main_window->FileSelect(
34 -width => 30);
35 $tigr_xml_main_window->withdraw;
36 my $Filename = $FileMW->Show;
37
38 unless ($Filename){ return undef };
39 $FileMW->destroy;
40 $tigr_xml_main_window->destroy;
41
42
43 $Username = "root";
44 $Password = "";
45 $IPAddress = "localhost";
46 ### $Filename = "";
47
48
49 $Default_DB = "genquire";
50
51 # note that DbObj is not an absolute requirement for all Context objects
52 # we use it in the Genquire_local adaptor layer because it is useful...
53 # you will probably want to have something like DbObj (call it what you wish)
54 # as the test of database or flat-file availability/successful connection.
55
56 %orgs = ();
57
58 $dbobj = GQ::Server::DB::DbObj->new($Username, $Password, $Default_DB, $IPAddress);
59
60 if ($dbobj) { #successful connection
61
62 $Filename =~ /(.*)\/.*$/;
63 print "Connecting to $1\n";
64
65 $log_file = "$1/GenquireErrorLogFile.txt";
66
67 # Make_Tiling_Path.pl determines the tiling path from the XML tags.
68 my $result1 = system("perl", "./Admin/Make_Tiling_Path.pl", "$1", $log_file); # This script should take almost no time at all.
69 die "Error executing Make_Tiling_Path.pl" if $result1 != 0;
70
71 # Data_Tiling_Path.pl, which acts as a wrapper for Data_Dumper.pl, dumps all the clones into the database in the correct
72 # tiling path order.
73 my $result2 = system("perl", "./Admin/Data_Tiling_Path.pl", "$1", $log_file); # It's this one that might take some time,
74 # depending on the number of clones.
75 die "Error executing Data_Tiling_Path.pl" if $result2 != 0;
76
77 $context=GQ::Server::DB::Context->new($dbobj); # not all Context objects will require $dbobj for initialization!
78
79 main();
80
81 } else {
82 die "failed to connect to local Genquire database to extract organism list";
83 }
84
85 # ===================================================================================
86 sub main {
87
88 # This is the main subroutine.
89 # It displays the window that shows the user which organism/version IDs are currently sitting in the database
90 # and lets them specify on which organism/version ID to run create_tilingpath.pl on.
91
92 @orgs = $context->all_orgs_by_id;
93
94 $instructions = "In Database:\n" if scalar @orgs > 0;
95
96 foreach (@orgs){
97
98 # print $_->latin,"\t",$_->common,"\t",$_->id,"\t",$_->version,"\n";
99 $latin = $_->latin;
100 $common = $_->common;
101 $id = $_->id;
102 $version = $_->version;
103 $instructions .= "Latin Name: $latin\nCommon Name: $common\nOrganism ID: $id\nVersion ID: $version\n\n";
104
105 # Assign values to the %orgs hash.
106 $orgs{$_->id}{$_->version} = $_;
107 }
108
109 # This should NEVER, EVER occur because we've just run Data_Tiling_Path.pl script.
110 # However, just in case....
111 $instructions = "No organism/version in the database!" if !defined $instructions;
112
113
114 $organism_version_window = MainWindow->new(-title => 'Choose Organism and Version Ids to create tiling path for:',
115 -height => 80,
116 -width => 80
117 );
118
119
120
121 $instructions_text = $organism_version_window->Text(
122 -width => 80,
123 -height => 40,
124 )->pack(-side => 'top', -anchor => 'w');
125 $instructions_text->insert('end',$instructions);
126
127
128 # Organism Label:
129 $org_label = $organism_version_window->Label(-text => 'Organism ID:', -width => 10, -height => 1, -relief => 'raised'
130 )->pack(-side => 'left', -anchor => 'w');
131 # Organism Text Box:
132 $org_text = $organism_version_window->Text(-width => 5, -height => 1)->pack(-side => 'left', -anchor => 'w');
133
134
135 # Version Label:
136 $ver_label = $organism_version_window->Label(-text => 'Version ID:', -width => 10, -height => 1, -relief => 'raised'
137 )->pack(-side => 'left', -anchor => 'w');
138 # Version Text Box:
139 $ver_text = $organism_version_window->Text(-width => 5, -height => 1)->pack(-side => 'left', -anchor => 'w');
140
141
142 # Clear Button:
143 $clear_button = $organism_version_window->Button( -text => ' Clear ',
144 -command => \&_clear_text_boxes,
145 )->pack(-side => 'right', -anchor => 's');
146
147
148 # OK Button: (submit)
149 $ok_button = $organism_version_window->Button( -text => ' OK ',
150 -command => \&_run_create_tiling_path,
151 )->pack(-side => 'right', -anchor => 's');
152
153
154 } # closes main();
155 # ===================================================================================
156 sub _run_create_tiling_path {
157
158 # Get the organism/version ids that the user entered.
159 $entered_org = $org_text->get('1.0','end');
160 $entered_version = $ver_text->get('1.0', 'end');
161
162 chomp ($entered_org);
163 chomp ($entered_version);
164 # print "entered_org: $entered_org, entered_version: $entered_version\n";
165
166 # The user has clicked the 'OK' button. Now get rid of the window:
167 $organism_version_window->destroy;
168
169 # Did the user enter a valid organism/version id?
170 # If not, run the main subroutine again. Do so until they enter valid ids.
171 # Note that the %orgs hash is assigned values within the main subroutine.
172 if(!exists $orgs{$entered_org}{$entered_version}){
173 # pop-up window that tells them to enter valid organism/version ids.
174 &pop_up_window("You did not enter a valid organism and/or version id.");
175 main();
176 } else {
177
178 # These are the arguments that are to be passed to create_tilingpath.pl
179 # Originally, the user runs create_tilingpath.pl from the command line and enters the values below via STDIN.
180 # Now, it's all done dynamically and behind the scenes.
181 $from_genquire = 1;
182 $from_genquire_user = $Username;
183 $from_genquire_pass = $Password;
184 $from_genquire_IP = $IPAddress;
185 $from_genquire_DB = $Default_DB;
186
187 # The Context package contains a method called get_chrs_by_id that obtains the chromosome id (4, 2, 32, whatever) with the
188 # query that I have below.
189 # However, the object doesn't seem to have the organism and version ids stored, so the query cannot be executed.
190 # So, I have the code below that works fine:
191 my $chr_query = $dbobj->dbh->prepare("SELECT DISTINCT chr_id
192 FROM Assembly
193 WHERE version=? and organism=? order by chr_id asc"
194 );
195 $chr_query->execute($entered_version,$entered_org); # execute the above the query with the ids entered by the user.
196
197
198 # Fetch the results of the query. For each organism ID and version ID, there *should* be one chromsome....
199 my @chr = ();
200 while (my ($chr_id)=$chr_query->fetchrow_array) {
201 push @chr,$chr_id;
202 }
203 die "Error. Could not determine which chromosome this clone maps to!" if scalar @chr == 0;
204 die "Error. These clones belong to more than one chromosome??!" if scalar @chr != 1;
205
206 # Run create_tilingpath.pl with the specified arguments:
207 $result3 = system("perl", "./Admin/create_tilingpath.pl", "$from_genquire", "$from_genquire_user", "$from_genquire_pass",
208 "$from_genquire_IP", "$from_genquire_DB", "$chr[0]", "$entered_org", "$entered_version"
209 );
210 die "Error executing create_tilingpath.pl" if $result3 != 0;
211
212 # pop-up window that tells them to click on 'Begin with these settings'
213 &pop_up_window("Click on the 'Begin with these settings' button on the Genquire window to begin!");
214 }
215
216
217 }
218 # ===================================================================================
219 sub _clear_text_boxes {
220
221 # Subroutine that clears the Organism and Version Text Boxes:
222 $org_text->delete('1.0','end');
223 $ver_text->delete('1.0','end');
224
225 }
226 # ===================================================================================
227 #sub _pop_up_window {
228 #
229 # # Subroutine creates a window to alert users of $message.
230 # my ($message) = @_;
231 # $pop_up_main = MainWindow->new(-title => 'Message:', -width => 110, -height => 20);
232 #
233 # # The message:
234 # $message_label = $pop_up_main->Label(-text => $message, -width => 100, -height => 10, -relief => 'raised'
235 # )->pack(-side => 'top', -anchor => 'center');
236 #
237 # # Close Button
238 # $close_button = $pop_up_main->Button( -text => ' Close ',
239 # -command => sub { $pop_up_main->destroy; },
240 # )->pack(-side => 'top', -anchor => 'center');
241 #
242 #
243 #
244 #}
245 # ===================================================================================