package EstRead; =head1 NAME LocusRead -- Read an EST file and save the pertinent information into the database =head1 SYNOPSIS my $boolean = EstRead -> new; =head1 DESCRIPTION This package reads an EST file and saves the pertinent data into the database. EstRead, 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 = EstRead->new; Reads an EST file 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."); $file_obtained = FALSE; } # if else { # A project has been activated if($project->{est_file} ne "") { message("Data from EST file $project->{est_file}"); message("is already in the database."); if(yes("Refresh the database from this file?")) { $file_name = $project->{est_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 EST file name"); } # if if($file_name eq "Q") { $loop = FALSE; $file_obtained = FALSE; } # if elsif(file_name_ok($file_name, $configuration, $db_manager, $project)) { $loop = FALSE; $file_obtained = TRUE; } # elsif else { $file_obtained = FALSE; if(!yes("Try another file name?")) { $loop = FALSE; } # if } # else } # while } # else if($file_obtained) { # save the configuration $project->{est_file} = $file_name; $configuration->save($project); press_enter; TRUE; } # if else { press_enter; FALSE; } # else } # new # ******************************** file_name_ok ****************************** =head2 project_name_ok my $boolean = EstRead->file_name_ok($file_name, $configuration, $db_manager, $project); Determines if a file name is acceptable. If the file name is ok, then the EST 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 $project = shift; my $name_ok = TRUE; my $error = FALSE; my $number_lines = 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 EST input file message("EST file $file_name opened"); message("Connecting to the database."); $db_manager->connect; message("Deleting any previous est data in the database."); $db_manager->execute("delete from est"); message("Entering data into the database..."); # read the input file my @file_array = ; close INPUT_FILE; $number_lines = scalar(@file_array); my $clone = ""; my $est = ""; my $comment = ""; # look at each line in the input file for(my $line_number=0; $line_number < $number_lines; $line_number++) { my $current_line = $file_array[$line_number]; chomp $current_line; my @field_array = split /\t/, $current_line; $clone = $field_array[0]; $est = $field_array[1]; if($field_array[2]) { $comment = $field_array[2]; # trim the white space $comment =~ s/^\s*//; $comment =~ s/\s*$//; } # else { $comment = ""; } # else $comment = "" if ($comment eq "EST"); $comment = substr($comment, 1) if(substr($comment, 0, 1) eq "\""); $comment = substr($comment, 0,-1) if(substr($comment, -1, 1) eq "\""); # trim the white space (again) $comment =~ s/^\s*//; $comment =~ s/\s*$//; $comment = substr($comment, 0,-1) if(substr($comment, -1, 1) eq "."); $comment = substr($comment, 0,-1) if(substr($comment, -1, 1) eq ","); # Save the relations in the clone2locus database table my $eid = $db_manager->{dbh}->quote(""); my $db_clone = $db_manager->{dbh}->quote("$clone"); my $db_est = $db_manager->{dbh}->quote("$est"); my $db_comment = $db_manager->{dbh}->quote("$comment"); $db_manager->execute("insert into est values($eid, $db_clone, $db_est, $db_comment)"); } # for # print closing information message("Number of est: $number_lines."); } # else message("Disconnecting from the database."); $db_manager->disconnect; close INPUT_FILE; if($name_ok) { TRUE; } # if else { FALSE; } # else } # project_name_ok 1