package EndMatchesRead; =head1 NAME EndMatchesRead -- Read a file of clone end matches and save the pertinent information into the database =head1 SYNOPSIS my $boolean = EndMatchesRead -> new; =head1 DESCRIPTION This package reads a file of clone end matches and saves the pertinent data into the database. EndMatchesRead, itself, is not an object and cannot be instantiated. =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() my $boolean = EndMatchesRead->new; Reads a file of clone end matches and loads the data into the database. =cut # package variables # ******************************** new ****************************** sub new { my $self = shift; my $configuration = shift; my $db_manager = shift; my $project = shift; my $file_name = ""; my $file_obtained = TRUE; my $refresh = FALSE; message_start; if($project->{current_project} eq "") { message("You must activate a project, first."); blank_line; press_enter; $file_obtained = FALSE; } # if else { # A project has been activated if($project->{end_matches_file} ne "") { message("Data from MLG file $project->{end_matches_file}"); message("is already in the database."); if(yes("Refresh the database from this file?")) { $file_name = $project->{end_matches_file}; $refresh = TRUE; } # if elsif(!yes("Delete this existing data in the database and continue?")) { return FALSE; } # elsif } # if my $loop = TRUE; while($loop) { if(!$refresh) { message("Give the /path/to/file.txt."); blank_line; $file_name = prompt("Enter path and End Matches file name"); } # if if($file_name eq "Q") { $loop = FALSE; $file_obtained = FALSE; } # if elsif(file_name_ok($file_name, $configuration, $db_manager)) { $loop = FALSE; $file_obtained = TRUE; } # elsif else { $file_obtained = FALSE; if(!yes("Try another file name?")) { $loop = FALSE; } # if } # else } # while } # else(a project has been activated) if($file_obtained) { # save the configuration $project->{end_matches_file} = $file_name; $configuration->save($project); press_enter; TRUE; } # if else { press_enter; FALSE; } # else } # new # ******************************** file_name_ok ****************************** =head2 file_name_ok my $boolean = EndMatchesRead->file_name_ok($file_name, $configuration, $db_manager); Determines if a file name is acceptable. If the file name is ok, then the End Matches file is read and the data is stored in MySQL for later use. For internal usage only. =cut # --------------------------------------------------------------------------------- sub file_name_ok { my $file_name = shift; my $configuration = shift; my $db_manager = shift; my $name_ok = TRUE; my $error = FALSE; my $number_lines = 0; my $end_match_count = 0; my $new_other_side_counter = 0; open(INPUT_FILE, "<", "$file_name") or $error = TRUE; if($error) { message_start; message("Could not read $file_name"); message("$!"); $name_ok = FALSE; } # if else { # Read the End Matches input file message("End Matches file $file_name opened"); message("Connecting to the database."); $db_manager->connect; message("Deleting any previous EndMatches data in the database."); $db_manager->execute("delete from end_matches"); message("Entering data into the database..."); # read the input file my @file_array = ; close INPUT_FILE; $number_lines = scalar(@file_array); # force unbuffered output my $old_fh = select(STDOUT); $| = 1; select($old_fh); # look at each line in the input file my $dbh = $db_manager->{dbh}; print "\n "; for(my $lcv = 4; $lcv < $number_lines; $lcv++) { print "." if($lcv % 1000 == 0); my $current_line = $file_array[$lcv]; my @field_array = split / +/, $current_line; my $eid = $dbh->quote(""); my $ctg1 = $dbh->quote($field_array[0]); my $side1 = $dbh->quote($field_array[1]); my $clone1 = $dbh->quote($field_array[2]); my $bands1 = $dbh->quote(substr($field_array[3], 0, length($field_array[3]) - 1)); my $ctg2 = $dbh->quote($field_array[4]); my $side2 = $dbh->quote($field_array[5]); my $clone2 = $dbh->quote($field_array[6]); my $bands2 = $dbh->quote(substr($field_array[7], 0, length($field_array[7]) - 1)); my $bandsm = $dbh->quote($field_array[9]); my $score = $dbh->quote($field_array[10]); $db_manager->execute("insert into end_matches values($eid, $ctg1, $side1, $clone1, $bands1, $ctg2, $side2, $clone2, $bands2, $bandsm, $score)"); $db_manager->execute("insert into end_matches values($eid, $ctg2, $side2, $clone2, $bands2, $ctg1, $side1, $clone1, $bands1, $bandsm, $score)"); $end_match_count += 2; } # for # execute the select statement print "\n"; message("Executing the end count select statement."); my $sth = $db_manager->execute("select count(ctg1), ctg1, side1 from end_matches group by ctg1, side1"); # read the data and save the counts message("Saving the counts in the database."); my @row = (); while(@row = $sth->fetchrow_array()) { my $eid = $dbh->quote(""); my $count = $dbh->quote(shift @row); my $ctg = $dbh->quote(shift @row); my $side = $dbh->quote(shift @row); $db_manager->execute("insert into end_counts values($eid, $ctg, $side, $count, 0)"); } # while # execute the other side select statement message("Executing the other side end count select statement."); my $sth2 = $db_manager->execute("select count(ctg1), ctg1, side1 from end_matches group by ctg1, side1"); # read the other side data and save the counts message("Saving the other side counts in the database."); my @row2 = (); while(@row2 = $sth2->fetchrow_array()) { my $eid = $dbh->quote(""); my $count = $dbh->quote(shift @row2); my $ctg = $dbh->quote(shift @row2); my $side = shift @row2; if($side eq "L") { $side = "R"; } # if elsif($side eq "R") { $side = "L"; } # elsif $side = $dbh->quote($side); my $sth3 = $db_manager->execute("update end_counts set oscount = $count where ctg = $ctg and side = $side"); if($sth3->rows == 0) { $db_manager->execute("insert into end_counts values($eid, $ctg, $side, 0, $count)"); $new_other_side_counter++; } # if } # while message("Disconnecting from the database."); $db_manager->disconnect; close INPUT_FILE; # print closing information message("Number of End Matches: $end_match_count."); message("Number of New Other Sides: $new_other_side_counter."); } # else if($name_ok) { TRUE; } # if else { FALSE; } # else } # project_name_ok 1