package UpdateLocusNames; =head1 NAME UpdateLocusNames -- Updates the locus names in the clone2locus table so that they match locus names in the locus table. =head1 SYNOPSIS UpdateLocusNames -> new; =head1 DESCRIPTION UpdateLocusNames -- Updates the locus names in the clone2locus table so that they matche locus names in the locus table. The updating is done via a file, ../working_data/locus_name_changes.txt, provided by the user. This is a two-column tab-delimited text file with the first column being the old locus name and the second column being the corresponding new locus name. =head1 VERSION 0.001 (last update: 6/30/04) =head1 AUTHOR Chet Langin, clangin@siu.edu SIU Plant Biotechnology and Genomics Core-facility =head1 BUGS None known. =head1 SEE ALSO extropy ExtropyConstants ExtropyUtils Extropy::MenuMain =head1 COPYRIGHT Copyright 2004, Chet Langin, All Rights Reserved. This program is free software. You may copy or redistribute it under the same terms as Perl itself. =head1 METHODS The remainder of this document describes the methods available to the programmer. =cut # load the pragmas use warnings; use strict; # load other modules use ExtropyConstants; use ExtropyUtils; =head2 new() UpdateLocusNames->new; Updates the locus names in the clone2locus table so that they match locus names in the loci table. =cut # package variables # ******************************** new ****************************** sub new { my $self = shift; my $configuration = shift; my $db_manager = shift; my $project = shift; my $number_lines = 0; message_start; if($project->{current_project} eq "") { message("You must activate a project, first."); } # if elsif(!$project->{locus_names_crosschecked}) { message("You must crosscheck locus names, first."); } # elsif else { # The updates can be made message("Connecting to the database."); $db_manager->connect; # Open and read the update file message("Opening ../working_data/locus_name_changes.txt."); my $open_error = FALSE; open(INPUT_FILE, "<", "../working_data/locus_name_changes.txt") or $open_error = TRUE; if($open_error) { message_start; message("Could not open ../working_data/locus_name_changes.txt"); message("$!"); } # if else { message("Making locus name changes to clone2locus2 table."); # Deleting clone2locus2 for new data message("Deleting clone2locus2 for new data"); $db_manager->execute("delete from clone2locus2"); # Copy clone2locus data to clone2locus2 message("Copying clone2locus data to clone2locus2"); $db_manager->execute("insert into clone2locus2 select * from clone2locus"); my @file_array = ; close INPUT_FILE; my $number_lines = scalar(@file_array); # look at each line in the input file for(my $current_line=0; $current_line < $number_lines; $current_line++) { # Get a name change my $this_line = $file_array[$current_line]; chomp $this_line; my @field_array = split /\t/, $this_line; my $old_name = $db_manager->{dbh}->quote($field_array[0]); my $new_name = $db_manager->{dbh}->quote($field_array[1]); # Save the name change in the clone2locus2 table my $handle = $db_manager->execute("update clone2locus2 set locus = $new_name where locus = $old_name"); my $rows = $handle->rows; # print "$rows "; } # for # Deleting clone_loci2 for new data message("Deleting clone_loci2 for new data"); $db_manager->execute("delete from clone_loci2"); # Get the new clone names from clone2loci; message("Getting the new locus names from clone2locus."); my $sth = $db_manager->execute("select locus from clone2locus2"); # Read and save the results message("Saving the new locus names in clone_loci2."); my @row = (); while(@row = $sth->fetchrow_array()) { my $eid = $db_manager->{dbh}->quote(""); my $db_locus = $db_manager->{dbh}->quote(shift @row); my $db_no = $db_manager->{dbh}->quote("no"); $db_manager->execute("insert into clone_loci2 values($eid, $db_locus, $db_no)"); } # while # Find the loci in clone_loci2 that match USDA loci message("Crosschecking the new loci."); my $sth2 = $db_manager->execute("select clone_loci2.locus from clone_loci2, loci where clone_loci2.locus = loci.locus"); # Read and save the results message("Marking the results in clone_loci2."); my @row2 = (); while(@row2 = $sth2->fetchrow_array()) { my $db_locus = $db_manager->{dbh}->quote(shift @row2); my $db_yes = $db_manager->{dbh}->quote("yes"); $db_manager->execute("update clone_loci2 set good = $db_yes where locus = $db_locus"); } # while # Find the loci names that are still bad my $db_no = $db_manager->{dbh}->quote("no"); my $sth3 = $db_manager->execute("select locus from clone_loci2 where good = $db_no"); # Processing loci that still have bad names message("Deleting clone2locus3 table data to accomodate new data"); $db_manager->execute("delete from clone2locus3"); message("Deleting bad_clone2locus table data to accomodate new data"); $db_manager->execute("delete from bad_clone2locus"); message("Saving bad loci names into bad_loci_names2.txt,"); message("and rearranging table data to reflect bad loci names."); my $output_error = FALSE; open(OUTPUT_FILE, ">", "../working_data/bad_loci_names2.txt") or $output_error = TRUE; if($output_error) { message_start; message("Could not open ../working/data/bad_loci_names2.txt"); message("$!"); } # if else { # output file has been successfully opened my @row3 = (); while(@row3 = $sth3->fetchrow_array()) { my $output_locus = $db_manager->{dbh}->quote(shift @row3); my $db_no = $db_manager->{dbh}->quote("no"); my $db_yes = $db_manager->{dbh}->quote("yes"); my $db_locus = $output_locus; $output_locus = substr($output_locus, 1, length($output_locus) - 2); print OUTPUT_FILE "$output_locus\n"; $db_manager->execute("insert into bad_clone2locus select clone2locus2.eid, clone2locus2.clone, clone2locus2.locus, clone2locus2.mlg from clone2locus2, clone_loci2 where clone2locus2.locus = clone_loci2.locus and clone_loci2.good = $db_no"); $db_manager->execute("insert into clone2locus3 select clone2locus2.eid, clone2locus2.clone, clone2locus2.locus, clone2locus2.mlg from clone2locus2, clone_loci2 where clone2locus2.locus = clone_loci2.locus and clone_loci2.good = $db_yes"); } # while $project->{locus_names_updated} = TRUE; } # else close OUTPUT_FILE; message("Disconnecting from the database."); $db_manager->disconnect; } # else } # else press_enter; } # new 1