package CountContigAnchors; =head1 NAME CountContigAnchors -- Counts the number of clone anchors for each contig and saves the results in the contigs table. =head1 SYNOPSIS CountContigAnchors -> new; =head1 DESCRIPTION CountContigAnchors -- Counts the number of clone anchors for each contig and saves the results in the contigs table. =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 The module is under development and is not yet finished. =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() CountContigAnchors->new; Counts the number of clone anchors for each contig and saves the results in the contigs 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->{clone_anchors_updated}) { message("You must update clone anchors, first."); } # elsif else { # The counts can be made message("Connecting to the database."); $db_manager->connect; message("Getting the duplicated clones from clone_anchors."); my $sth = $db_manager->execute("select clone, dup_t from clone_anchors where dup_t > 1 group by clone"); message("Saving the duplicate counts to contig2clone."); my @row = (); while(@row = $sth->fetchrow_array()) { my $db_clone = $db_manager->{dbh}->quote(shift @row); my $db_dup_t = $db_manager->{dbh}->quote(shift @row); $db_manager->execute("update contig2clone set dup_t = $db_dup_t where clone = $db_clone"); } # while $project->{contig_anchors_counted} = TRUE; message("Counting the contig anchors."); $db_manager->execute("update contigs set anchors = 0"); my $sth2 = $db_manager->execute("select ctg, sum(contig2clone.dup_t) from contig2clone, clone_anchors where contig2clone.clone = clone_anchors.clone group by ctg"); message("Saving the counts to contigs."); my @row2 = (); while(@row2 = $sth2->fetchrow_array()) { my $db_ctg = $db_manager->{dbh}->quote(shift @row2); my $db_anchors = $db_manager->{dbh}->quote(shift @row2); my $db_gamma = $db_manager->{dbh}->quote("gamma"); $db_manager->execute("update contigs set anchors = $db_anchors, type = $db_gamma where ctg = $db_ctg"); } # while message("Getting contigs with multiple anchors."); my $sth3 = $db_manager->execute("select contigs.ctg, clone_anchors.clone, clone_anchors.mlg, clone_anchors.anchor from contig2clone, clone_anchors, contigs where contigs.anchors > 1 and contigs.ctg = contig2clone.ctg and contig2clone.clone = clone_anchors.clone order by contigs.anchors, ctg, mlg, anchor"); message("Saving the contig information to ../working_data/contig_dups.txt"); my $output_error = FALSE; open (OUTPUT_FILE, ">", "../working_data/contig_dups.txt") or $output_error = TRUE; if($output_error) { message("Could not open ../working/data/contig_dups.txt"); message("$!"); } # if my @row3 = (); while(@row3 = $sth3->fetchrow_array()) { my $contig = shift @row3; my $clone = shift @row3; my $mlg = shift @row3; my $anchor = shift @row3; if(!$output_error) { print OUTPUT_FILE "$contig\t$clone\t$mlg\t$anchor\n"; } # if } # while close OUTPUT_FILE; message("Disconnecting from the database."); $db_manager->disconnect; } # else press_enter; } # new 1