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 (16 years, 5 months 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 User Rev File contents
1 skchan 1.3 # 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 skchan 1.1 # 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 skchan 1.3 ###############################################################
20    
21 skchan 1.1
22     use Bio::SeqIO;
23     use Tk;
24     use Tk::widgets qw(FileSelect);
25 skchan 1.2 use DBI;
26 skchan 1.3
27 skchan 1.6 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 skchan 1.5 use HelperMethods;
31 skchan 1.1
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 skchan 1.3
38 skchan 1.1 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 skchan 1.3
58 skchan 1.1 $dbobj = GQ::Server::DB::DbObj->new($Username, $Password, $Default_DB, $IPAddress);
59 skchan 1.2
60 skchan 1.1 if ($dbobj) { #successful connection
61    
62 skchan 1.2 $Filename =~ /(.*)\/.*$/;
63     print "Connecting to $1\n";
64 skchan 1.3
65 skchan 1.4 $log_file = "$1/GenquireErrorLogFile.txt";
66    
67 skchan 1.3 # Make_Tiling_Path.pl determines the tiling path from the XML tags.
68 skchan 1.4 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 skchan 1.3
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 skchan 1.4 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 skchan 1.2 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 skchan 1.1 sub main {
87    
88 skchan 1.3 # 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 skchan 1.1 @orgs = $context->all_orgs_by_id;
93    
94 skchan 1.3 $instructions = "In Database:\n" if scalar @orgs > 0;
95 skchan 1.1
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 skchan 1.2 $instructions .= "Latin Name: $latin\nCommon Name: $common\nOrganism ID: $id\nVersion ID: $version\n\n";
104 skchan 1.3
105     # Assign values to the %orgs hash.
106 skchan 1.1 $orgs{$_->id}{$_->version} = $_;
107 skchan 1.3 }
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 skchan 1.1
113    
114 skchan 1.2 $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 skchan 1.3
120 skchan 1.1
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 skchan 1.3 # Organism Label:
129 skchan 1.2 $org_label = $organism_version_window->Label(-text => 'Organism ID:', -width => 10, -height => 1, -relief => 'raised'
130 skchan 1.1 )->pack(-side => 'left', -anchor => 'w');
131 skchan 1.3 # Organism Text Box:
132 skchan 1.1 $org_text = $organism_version_window->Text(-width => 5, -height => 1)->pack(-side => 'left', -anchor => 'w');
133 skchan 1.3
134    
135     # Version Label:
136 skchan 1.2 $ver_label = $organism_version_window->Label(-text => 'Version ID:', -width => 10, -height => 1, -relief => 'raised'
137 skchan 1.1 )->pack(-side => 'left', -anchor => 'w');
138 skchan 1.3 # Version Text Box:
139 skchan 1.2 $ver_text = $organism_version_window->Text(-width => 5, -height => 1)->pack(-side => 'left', -anchor => 'w');
140    
141 skchan 1.1
142 skchan 1.3 # Clear Button:
143 skchan 1.1 $clear_button = $organism_version_window->Button( -text => ' Clear ',
144 skchan 1.3 -command => \&_clear_text_boxes,
145 skchan 1.1 )->pack(-side => 'right', -anchor => 's');
146    
147 skchan 1.3
148     # OK Button: (submit)
149 skchan 1.1 $ok_button = $organism_version_window->Button( -text => ' OK ',
150     -command => \&_run_create_tiling_path,
151     )->pack(-side => 'right', -anchor => 's');
152    
153 skchan 1.3
154 skchan 1.1 } # closes main();
155 skchan 1.2 # ===================================================================================
156 skchan 1.1 sub _run_create_tiling_path {
157    
158 skchan 1.3 # Get the organism/version ids that the user entered.
159 skchan 1.1 $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 skchan 1.2 # print "entered_org: $entered_org, entered_version: $entered_version\n";
165 skchan 1.3
166     # The user has clicked the 'OK' button. Now get rid of the window:
167 skchan 1.1 $organism_version_window->destroy;
168 skchan 1.3
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 skchan 1.1 if(!exists $orgs{$entered_org}{$entered_version}){
173 skchan 1.2 # pop-up window that tells them to enter valid organism/version ids.
174 skchan 1.5 &pop_up_window("You did not enter a valid organism and/or version id.");
175 skchan 1.2 main();
176     } else {
177    
178 skchan 1.3 # 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 skchan 1.2 $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 skchan 1.3 # 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 skchan 1.2 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 skchan 1.3 $chr_query->execute($entered_version,$entered_org); # execute the above the query with the ids entered by the user.
196 skchan 1.2
197 skchan 1.3
198     # Fetch the results of the query. For each organism ID and version ID, there *should* be one chromsome....
199 skchan 1.2 my @chr = ();
200     while (my ($chr_id)=$chr_query->fetchrow_array) {
201     push @chr,$chr_id;
202     }
203 skchan 1.5 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 skchan 1.2
206 skchan 1.3 # Run create_tilingpath.pl with the specified arguments:
207 skchan 1.2 $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 skchan 1.3 die "Error executing create_tilingpath.pl" if $result3 != 0;
211 skchan 1.2
212     # pop-up window that tells them to click on 'Begin with these settings'
213 skchan 1.5 &pop_up_window("Click on the 'Begin with these settings' button on the Genquire window to begin!");
214 skchan 1.1 }
215    
216    
217     }
218 skchan 1.2 # ===================================================================================
219 skchan 1.1 sub _clear_text_boxes {
220    
221 skchan 1.3 # Subroutine that clears the Organism and Version Text Boxes:
222 skchan 1.1 $org_text->delete('1.0','end');
223     $ver_text->delete('1.0','end');
224    
225     }
226 skchan 1.2 # ===================================================================================
227 skchan 1.5 #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 skchan 1.3 # ===================================================================================