#!/usr/local/bin/perl5.6.1 -w
#
#
#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################
#
#$Id: lclone.pl,v 1.30 2005/04/18 16:03:02 kva Exp $
#
#
###################################################
#                                                 #  
# Search and copying of either St Louis or        #
# Sanger Centre clone for comparison in Confirm.  #
#                                                 #
###################################################


#this line points the script to the addresses of the software that will be needed.

BEGIN { push @INC, ('/usr/local/badger/confirm','/usr/local/badger/bin'); }

my ($entry, $dir);
my ($progname,$path,$suffix) = fileparse($0, '\..*');
$entry = shift;
$entry or die "Usage:$progname <clonename>\n";
print "This is clone = $entry\n";
print "Path: $path\n";
print "Suffix: $suffix\n";

#output buffer is being flushed, so that values displayed 
#to <STDOUT> are displayed in the correct order.
#All the modules and dbfiles in use are outlined below.


$| = 1;
use strict;
use File::Basename;
use File::Copy;
use Cwd;
use Fcntl;
use DB_File;
use Tk;
use Tk::IO;
use Tk::ROText;
use Tk::BrowseEntry;
require Tk::NoteBook;

my ($dbFile,$dbFile2);
#if ($ENV{USER} eq 'kva') {
#   #test data directories.
#    $dbFile = $ENV{HOME}.'/src/confirmstl/SIZE/sizesGSC.db';
#    $dbFile2 = $ENV{HOME}.'/src/confirmstl/SIZE/sizesSC.db';
#} else {
    #directories for real use.
    $dbFile = $ENV{BADGER}.'/confirm/confirmstl/SIZE/sizesGSC.db';
    $dbFile2 = $ENV{BADGER}.'/confirm/confirmstl/SIZE/sizesSC.db';
#}

#DIRECTORIES INDEXING SO FAR.
#Human fingerprinting data - /nfs/GSC/Humanmap_agarose/fpc/Sizes
#Mouse fingerprint data (added in as requested by Richard Evans (29/09/00)) - /nfs/disk59/fpc/MUScdb/Sizes
#MFPC (Vancouver clones) (added in as requested by Richard Evans (30/04/01)) - /nfs/disk59/fpc/CmMUScdb/Sizes
#special mouse directory (added in as requested by Richard Evans (12/09/01)) - /nfs/disk59/fpc/MOUSEBC/SCDATA/SCSIZES
#Zebrafish size directory (added in as requested by Sean Humphries (02/01/02)) - /nfs/disk59/fpc/zebrafish/Sizes
#Tetradon size directory (added in as requested by Sean Humphries (02/01/02)) - /nfs/disk59/fpc/Tetradon/Sizes

my %INDEX;
my %INDEX2;

my @all;
my @all2;
my $n;

#Build perl/Tk Main Window.

my $mw =MainWindow->new;
$mw->configure(-title=>"LCLONE");

my $text = "LCLONE";
my $scrollbox = $mw->Entry(-state => 'disabled',
			   -relief => 'raised',
			   -width => '10',
			   -justify => 'center',
			   -font => '*-times-bold-r-normal--*-240-*-*-p-*-*-*',
			   #-bg => 'LemonChiffon1',
			   -textvariable => \$text,
			   )->pack(side => 'top');

my $titleframe = $mw->Canvas(-relief=>'sunken', -height=>'50', -width=>'800',-bg=>"SkyBlue1")->pack(-side=>'top');

my $mainframe1 = $mw->Frame(-relief=>'groove', -borderwidth=>'2')->pack(-fill=>'x');
my $frame1     = $mainframe1->Frame()->pack(-anchor =>'nw', -fill =>'x', -pady =>10);

my $mainframe2 = $mw->Frame(-relief=>'groove', -borderwidth=>'2')->pack(-fill=>'x');
my $frame2     = $mainframe2->Frame(-relief=>'groove', -borderwidth=>'2')->pack(-anchor =>'e', -fill =>'x');
my $frame2a    = $mainframe2->Frame(-relief=>'groove', -borderwidth=>'2')->pack(-anchor =>'e', -fill =>'x');

my $notebookframe = $mw->Frame(-relief => 'groove', -borderwidth=>'2')->pack(-fill=>'x');

my $mainframe3  = $mw->Frame()->pack(-fill=>'x', -fill=>'y');
my $mainframe4  = $mw->Frame()->pack(-fill=>'x', -fill=>'y');

my $frame3     = $mainframe3->Frame()->pack(-anchor=>'s',-fill=>'x' );

$frame1->Label(-text =>'Clone Name eg bA818B23')->pack(-side=>'top', -padx=>40); 

my $clone_entry = $frame1->Entry(-textvariable=>\$entry, -bg=>"SkyBlue1", -state=>'disabled', -width=>20 )->pack(-side=>'top');

my $go_find = $frame1->Button(-text=>"GO FIND!!", -fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>12, -activebackground=>"DarkSlateGray2", -command=> \&SearchClone)->pack(-side=>'bottom', -anchor=>'s');

#my $copy_log = $mainframe3->ROText(-height=>2, -width=>50, -bg=>"SkyBlue1", -state=>'normal')->pack(-side=>'top');

my $exit_button = $mainframe4->Button(-text=>"EXIT", -fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>10, -activebackground=>"DarkSlateGray2", -command=> \&Exit)->pack(-side=>'right', -anchor=>'s');

my $help_button = $mainframe4->Button(-text=>"HELP", -fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>10, -activebackground=>"DarkSlateGray2", -command=> \&Help )->pack(-side=>'right', -anchor=>'s');

my $credit_button = $mainframe4->Button(-text=>"CREDITS", -fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>10, -activebackground=>"DarkSlateGray2", -command=> \&CreditsInfo )->pack(-side=>'right', -anchor=>'s');

#my $clear_button = $mainframe4->Button(-text=>"CLEAR ALL", -fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>10, -activebackground=>"DarkSlateGray2", -command=> \&Clear )->pack(-side=>'right', -anchor=>'s');

my $notebookframe_label = $notebookframe->Label(-text => "The windows below contain the clones found for a particular clonename.")->pack(-side=>'top');

my $notebookframe_label2 = $notebookframe->Label(-text => "Please make one selection (from either the Sanger Centre or St Louis boxes)")->pack(-side=>'top');

my $notebookframe_label3 = $notebookframe->Label(-text => "and copy that selection by double clicking on the highlighted line.")->pack(-side=>'top');

my $notebookframe_label4 = $notebookframe->Label(-text => "(Confirm can only use one selection).")->pack(-side=>'top');

my $notebook = $notebookframe->NoteBook(-cursor=>"arrow")->pack(-pady=>10);

my $st_louis = $notebook->add("p1", -label=>"St Louis & other external clones ");
my $sanger_centre = $notebook->add("p2", -label=>"Sanger Centre Clones");

my $stlframe = $st_louis->Frame(-relief => 'groove', -borderwidth=>'2')->pack(-fill=>'x');
my $scframe = $sanger_centre->Frame(-relief => 'groove', -borderwidth=>'2')->pack(-fill=>'x');

my $stlinside = $stlframe->ROText(-height=>10, -exportselection=>1, -width=>100, -bg=>"grey");
my $stl_scroll= $stlframe->Scrollbar(-command=>[$stlinside =>'yview']);
$stlinside->configure(-yscrollcommand => [$stl_scroll=>'set']);
$stl_scroll->pack(-side=>'right',-fill=>'y');
$stlinside->pack(-side=>'top');

my $scinside = $scframe->ROText(-height=>10, -exportselection=>1, -width=>100, -bg=>"grey");
my $sc_scroll= $scframe->Scrollbar(-command=>[$scinside =>'yview']);
$scinside->configure(-yscrollcommand => [$sc_scroll=>'set']);
$sc_scroll->pack(-side=>'right',-fill=>'y');
$scinside->pack(-side=>'top');

$notebook->pageconfigure('p1', -state => 'disabled');
$notebook->pageconfigure('p2', -state => 'disabled');

#my $copy_clones = $notebookframe->Button(-text=>"Copy the selected Clone", -takefocus=>1,-fg=>"SteelBlue2", -bg=>"PaleTurquoise1" , -width=>50, -activebackground=>"DarkSlateGray2", -command=> \&CopyClone )->pack(-side=>'top', -anchor=>'s'); 


my $credits;

#this invokes the searchclone method from the command line without having the intermediary step
#of pressing the go-find button. The button actively flashes to let you know it is active, and then
#the button is disabled to disallow any further searches from the console.

$mw->update();
$go_find->invoke();
$go_find->flash();
$go_find->configure(-text=>"Finished!!");
$go_find->configure(-state=>"disabled");
#$clear_button->configure(-state=>"disabled");

MainLoop();


sub SearchClone {
    
    $go_find->configure(-text=>"Locating Clone!!");
    $stlinside->configure(-state => 'normal', bg=>"SkyBlue1");
    $scinside->configure(-state => 'normal', bg=>"SkyBlue1");
    $notebook->pageconfigure('p1', -state => 'normal');
    $notebook->pageconfigure('p2', -state => 'normal');
  

#########################################################
#                                                       #
# Find and copy the equivalent St Louis (GSC) bandsizes #
# and other external clone information                  #
#                                                       #  
#########################################################

    
    print "\n************** Searching for St Louis (GSC) & other external results...\n";
    
#ties this section of the script to search a particular dbFile.
    
    tie (%INDEX, "DB_File", $dbFile,  O_RDONLY, 0664, $DB_HASH);
    
#this deals with the clonename typed into the box.

    @ARGV=$entry;

#the clonename is formatted to be used to find the particular 
#record in the st louis index file, if the clone entered does not 
#follow the pattern the program will shut down.
    
    foreach my $clone (@ARGV) {
        die "incompatible clonename: $clone \n"  unless $clone =~ /^[bdz][A-Z]+\d+[A-Z]+\d+|[df][A-Z]+\d+[A-Z]+\d+|\d+\w+\d+|\w+\d+\w+|\w+|\d+/;
#        if ($clone=~ /^[df][A-Z]\d+[A-Z]\d+|\d+\w\d+/){
#            my $error=("No GSC associated with this clonename: $clone\n");
#	    $stlinside->insert("end", $error);
#            next;
#        }else{
            
        #convert the sanger format into corresponding 
        #st louis format.
        my $gscclone;  
	#my $gscclone = sprintf"N%04d%s%02d", $1, uc($2), $3;
	my $file = $INDEX{"$clone"};
#	print ">>file information found :- $file<<\n";

	if (!defined $file){
	    my $error=("No GSC files associated with this clonename: $clone\n");
	    $stlinside->insert("end", $error);
	    next;	    
	} else {
            #print the output to the screen
            printf "\n%s:", $clone;
            my @f=split(/\t/,$file);
            foreach (@f){
                printf "\n\t%s", $_;
            }
	}
	
#each file found in relation to the clone id is split 
#on the tab character, if there is more than one record.
	
	my @seperates = split(/\t/,$file);
	my %hash;
	my $i = 0;
	
#split the entry into 2 parts on the asterix,
#the first being the file path, the second the 
#clone name.
	foreach my $member(@seperates){
            $member=~ /(.+)\*(.+)/;
            my $fullfilename=$1;
            my $filename=$fullfilename;
            $filename=basename($fullfilename);
            my $gscnm=$2;
            my $pathname=$fullfilename;    

#use the pathname to open the file.
            if (-e $pathname){
                open (F, $pathname) or die "can't open directory (for GSC) $pathname: $!\n";
            } 
    
#each section of the file which relates to the query clonename
#is pulled out and stored in a datastructure (hash).
	    
	    while (<F>){
		if ($_ =~ /^\s*(\S+)\s+\d+/){ 
		    $gscclone=$1;
		    $i = 0;
		}else{
		    chomp $_;
		    my $stldata =$_;
		    $hash{$gscclone}[$i] = "$stldata\n";
		    $i++;
		}
	    }
	    close F;

	    my @sizes;
	    my @s1;
	    my $alltot=0;
	    my $i=0;
	    my $sizes=0;
	    my $total=0;
	    my $tb =0;
	    my $totalband=0;
	    
	    @all=("@{$hash{$gscnm}}");
	    
#this is where the total number of bands and sizes 
#for each key of the hash is calculated.
#foreach key hash in the array (array of hashes), the 
#calulation is done, and linked with a line of data in 
#the interface window, so that when a particular entry is 
#selected the correct list of sizes from the correct file 
#for the correct clone, is obtained and transferred to confirm.
	    
	    foreach (@all){
		@{$hash{$gscnm}}=@_;
		my @total = $_;
		@s1 = $_;
		@sizes = split(/\s+/,$_);
	     
		my $i=0;
		my $alltot=0;
		my $sizes=0;
		
		foreach my $sizes(@sizes){
		    $tb+=@total;
		    $totalband = ($tb -1);
		    if ($sizes=~ /^(\d\d+)/){
                        $sizes=$1;
                    }else{
                        last if /-1/;
                    }
		    $alltot+=$sizes; 
		    $i++;
		}
		
#these variables are used to structure the data 
#efficiently in the output window.

		my $trunc_path = $fullfilename;
                $trunc_path =~ s/.*fpc\///g;
		my $header   = ("$trunc_path");
		my $clonname = ("$gscnm");
		my $bandinfo = ("=$totalband bands  : $alltot t.sizes");

		if ($mw->depth  == 1) {
                    $stlinside->tag('configure', 'hot',
                                    -background => 'black',
                                    -foreground => 'white',
                                    );
                } else {
                    $stlinside->tag('configure', 'hot',
                                    -relief      => 'raised',
                                    -borderwidth => 1,
                                    -background  => 'LightBlue1',
                                    );
                }
                
                my $allinfo2 = sprintf "%-50s %-10s %-15s\n","$header","$clonname","$bandinfo";
                my @logs2;
                $stlinside->insert('end', $allinfo2 , [qw(lclone), $allinfo2]);

#######################################################
#foreach loop for displaying size file name on the fly.
#######################################################
		push (@logs2, $allinfo2);

#the tags are then set up, the selected clone has it's file copied by double clicking 
#on the blue highlighted line. The selected line goes white to show selection.
#On double clicking the selection wanted, the console is exited automatically, 
#if no selection is to be made, the exit button is selected to explicitly exit the console.
                
                foreach my $log (@logs2) {
                    
                    $stlinside->bindtags(qw(lclone));
                    $stlinside->tag('configure', 'title');
                    $stlinside->tag('configure', $log);
                    
                    $stlinside->tag('bind', $log,
                                    '<Double-Button-1>' => sub {
                                        my $index = $stlinside->index('current');
                                        my @tags = $stlinside->tag('names', $index);
                                        my $tag = $tags[2];
                                        $tag =~ /(\S+)\s+(\S+)\s+/;
                                        $trunc_path=$1;
                                        my $n=$2;
                                        
                                        if ($n = $gscnm) {
                                            open(F, ">$clone.HindIII.0.stl") || die "Can't open '$clone.HindIII.0.stl': $!\n";
                                            my $hindfile = '$clone.HindIII.0.stl';
                                            if (-e $hindfile){
                                                unlink ($hindfile) or die "Can't delete $hindfile:$!\n";
                                            }
                                            my $s1 = shift @s1;
                                            $s1 =~ s/\s+/\n/g;
                                            my $file=$filename;
                                            
                                            #finally remove the .sizes tag.
                                            $file=~ s/\.sizes//;
                                            print F "\t$gscnm $totalband $file \n$s1";
                                            close F;
                                        }
                                        
                                        if ($n ne " "){
                                            $stlinside->tagConfigure($tag, -foreground => 'white');
                                            $stlinside->update;
                                        }
                                        &Exit($n,$trunc_path);
                                    });
                    
                    
                    my $lastLine = '';
                    $stlinside->tag('bind', $log,
                                    '<Enter>' => sub {
                                        my $e = $stlinside->XEvent;
                                        my($x, $y) = ($e->x, $e->y);
                                        $lastLine = $stlinside->index("\@$x,$y linestart");
                                        $stlinside->tag('add', 'hot', $lastLine, "$lastLine lineend");
                                    });
                    
                    $stlinside->tag('bind', $log,
                                    '<Leave>' => sub {
                                        $stlinside->tag('remove', 'hot', '1.0', 'end');
                                    });
                    
                    
                    $stlinside->tag('bind', $log,
                                    '<Motion>' => sub {
                                        my $e = $stlinside->XEvent;
                                        my($x, $y) = ($e->x, $e->y);
                                        my $newLine = $stlinside->index("\@$x,$y linestart");
                                        if ($newLine ne $lastLine) {
                                            $stlinside->tag('remove', 'hot', '1.0', 'end');
                                            $lastLine = $newLine;
                                            $stlinside->tag('add', 'hot', $lastLine, "$lastLine lineend");
                                        }
                                    });
                }
	    }
	}
    }
    untie %INDEX;
    

    
########################################################
#                                                      #
# Find and copy the equivalent Sanger Centre bandsizes #
#                                                      #
########################################################
    
    print "\n**************** Searching for Sanger Centre results...\n";
    
#this is tied to the index which contains the 
#sanger centre clone index, you can also search 
#for dj clones.
    
    tie (%INDEX2, "DB_File", $dbFile2, O_RDONLY, 0664, $DB_HASH);
    
    @ARGV=$entry;

#the clonename is formatted to be used to find the particular 
#record in the sanger center index file, if the clone entered does not 
#follow the pattern the program will shut down. 
   
    foreach my $clone (@ARGV) {
	my $scclone=$clone;
        die "incompatible clonename: $scclone\n"  unless $scclone =~ /^[bdz][A-Z]+\d+[A-Z]+\d+|[df][A-Z]+\d+[A-Z]+\d+|\d+\w+\d+|\w+\d+\w+|\w+|\d+/;
	my $file = $INDEX2{"$scclone"};
	
	if (!defined $file){
	    my $error2=("No SC files associated with this clonename: $scclone\n");
	    $scinside->insert("end", $error2);
	    next;
	} else {
            #print the output to the screen.
            printf "\n%s:", $scclone;
            my @f=split(/\t/,$file);
            foreach (@f){
                printf "\n\t%s", $_;
            }
	}

#each file found in relation to the clone id is split 
#on the tab character, if there is more than one record.
	
	my @seperates = split(/\t/,$file);
	my %hash;
	my $i = 0;
	
	foreach my $member(@seperates){
            $member=~ /(.+)\*(.+)/;
            my $fullfilename=$1;
            my $filename=$fullfilename;
            $filename=basename($fullfilename);
            my $scnm=$2;
            my $pathname=$fullfilename;    

            if (-e $pathname){
                open (F, $pathname) or die "can't open directory (for SC) $pathname: $!\n";
            } 
	    while (<F>){ 
		if ($_ =~ /^\s*(\S+)\s+\d+/){
		    $scclone=$1;
		    $i = 0;
		}else{
		    chomp $_;
		    my $stldata =$_;
		    $hash{$scclone}[$i] = "$stldata\n";
		    $i++;
		}
	    }
	    close F;
	    
	    my @sizes2;
	    my @s2;
	    my $alltot2=0;
	    my $i=0;
	    my $sizes2=0;
	    my $total2=0;
	    my $tb2=0;
	    my $totalband2=0;

	    @all2=("@{$hash{$scnm}}");	    

	    foreach (@all2){
		@{$hash{$scnm}}=@_;
		my @total2 = $_;
		@s2 = $_;
		@sizes2 = split(/\s+/,$_);
                
		my $i=0;
		my $alltot2=0;
		my $sizes2=0;
		
		foreach my $sizes2(@sizes2){
		    $tb2+=@total2;
		    $totalband2 = ($tb2 -1);
		    if ($sizes2=~ /^(\d\d+)/){
                        $sizes2=$1;
                    }else{
                        last if /-1/;
                    }
		    $alltot2+=$sizes2; 
		    $i++;
		}

                my $trunc_path = $fullfilename;
                $trunc_path =~ s/.*fpc\///g;
		my $header   = ("$trunc_path");
		my $clonname = ("$scnm");
		my $bandinfo = ("=$totalband2 bands : $alltot2 t.sizes");
                
                if ($mw->depth  == 1) {
                    $scinside->tag('configure', 'hot',
                                   -background => 'black',
                                   -foreground => 'white',
                                   );
                } else {
                    $scinside->tag('configure', 'hot',
                                   -relief      => 'raised',
                                   -borderwidth => 1,
                                   -background  => 'LightBlue1',
                                   );
                }
                
                my $allinfo2 = sprintf "%-50s %-10s %-15s\n","$header","$clonname","$bandinfo";
                my @logs2;
                $scinside->insert('end', $allinfo2 , [qw(lclone), $allinfo2]);
                
#######################################################
#foreach loop for displaying size file name on the fly.
#######################################################
                push (@logs2, $allinfo2);
                
                foreach my $log (@logs2) {
                    
                    $scinside->bindtags(qw(lclone));
                    $scinside->tag('configure', 'title');
                    $scinside->tag('configure', $log);
                    
                    
                    $scinside->tag('bind', $log,
                                   '<Double-Button-1>' => sub {
                                       my $index = $scinside->index('current');
                                       my @tags2 = $scinside->tag('names', $index);
                                       my $tag2 = $tags2[2];
                                       $tag2 =~ /(\S+)\s+(\S+)\s+/;
                                       $trunc_path=$1;
                                       my $n=$2;
                                       
                                       if ($n = $scnm) {
                                           open(F, ">$clone.HindIII.0.stl") 
                                               or die "Can't open '$clone.HindIII.0.stl': $!\n";
                                           my $hindfile2 = '$clone.HindIII.0.stl';
                                           if (-e $hindfile2){
                                               unlink ($hindfile2) or die "Can't delete $hindfile2:$!\n";
                                           }
                                           my $s2 = shift @s2;
                                           $s2 =~ s/\s+/\n/g;
                                           my $file=$filename;
                                           $file=~ s/\.sizes//;
                                           
                                           print F "\t$scnm $totalband2 $file \n$s2";
                                           close F;
                                       }
                                       
                                       if ($n ne " "){
                                           $scinside->tagConfigure($tag2, -foreground => 'white');
                                           $scinside->update;
                                       }
                                       &Exit($n, $trunc_path);
                                       
                                   });
                    
                    
                    my $lastLine = '';
                    $scinside->tag('bind', $log,
                                   '<Enter>' => sub {
                                       my $e = $scinside->XEvent;
                                       my($x, $y) = ($e->x, $e->y);
                                       $lastLine = $scinside->index("\@$x,$y linestart");
                                       $scinside->tag('add', 'hot', $lastLine, "$lastLine lineend");
                                   });
                    
                    $scinside->tag('bind', $log, 
                                   '<Leave>' => sub {
                                       $scinside->tag('remove', 'hot', '1.0', 'end');
                                   });
                    
                    
                    $scinside->tag('bind', $log,
                                   '<Motion>' => sub {
                                       my $e = $scinside->XEvent;
                                       my($x, $y) = ($e->x, $e->y);
                                       my $newLine = $scinside->index("\@$x,$y linestart");
                                       if ($newLine ne $lastLine) {
                                           $scinside->tag('remove', 'hot', '1.0', 'end');
                                           $lastLine = $newLine;
                                           $scinside->tag('add', 'hot', $lastLine, "$lastLine lineend");
                                       }
                                   });
                }
	    } 
	}
    }   
    untie %INDEX2;


}


#this subroutine just hold the help information.
 
sub Help {
	my $help;
	$help->destroy if Exists($help);
	$help = $mw->Toplevel();
	$help->configure(-title=>"Lclone Help");
	$help->minsize(450, 250);
	$help->maxsize(450, 250);    
	$help->packPropagate(0);
	
	my $h_frame = $help->Frame(-relief=>'flat', -borderwidth=>2)->pack(-fill=>'x', -fill=>'y');
	my $frame1 = $h_frame->Frame()->pack(-anchor=>'nw', -fill=>'x');

	my $title = $frame1->Label(-text=>"HELP")->pack();
	
	my $h_exitbutton = $frame1->Button(-text=>'Exit Help ', -width=>30,  -activebackground=>'DarkSlateGray2', -command=>sub{$help->destroy;})->pack(-side=>'bottom', -anchor=>'w');

	my $text_frame = $help->Frame(-relief=>'groove', -borderwidth=>2)->pack(-fill=>'x', -fill=>'y');

	my $frame2 = $text_frame->Frame()->pack(-anchor=>'s', -fill=>'x', -pady=>10);
	
	my $text  = $frame2->ROText(-width =>50, -wrap=>'word', -bg=>'LightSkyBlue1', -height=>50);
	my $help_scroll = $frame2->Scrollbar(-command=>[$text =>'yview']);
	$text->configure(-yscrollcommand => [$help_scroll=>'set']);
	$help_scroll->pack(-side=>'right',-fill=>'y');
	$text->pack(-side=>'top');

	$text->tagConfigure('BLUETEXT', -foreground => 'blue');
        $text->tagConfigure('REDTEXT', -foreground => 'red');

	$text->insert('end', "Overview\n\n", 'BLUETEXT');
	$text->insert('end', "This is the help information in relation to this module.\n  Lclone enables choices to be made, where there are more than one entry for a particular clone name.\n\n\n");

	$text->insert('end', "How It Works\n\n", 'BLUETEXT');
	$text->insert('end', "The program is called (and replaces importSTL) as an intermediary step before importCRD and CONFIRM. The entries relating to the clonename are listed in either the St Louis box or the Sanger Centre box. Either box can be viewed by clicking on the tabs above the boxes. The tabs appear light grey when being viewed and dark grey, when in the background.\n\n\n");

        $text->insert('end', "Returned Data Format\n\n", 'BLUETEXT');
	$text->insert('end', "The data is returned in the following format:\n\n");
        $text->insert('end', "The 1st section", 'REDTEXT');
        $text->insert('end', " details the size file the data was extracted from.\n\n");
        $text->insert('end', "The 2nd section", 'REDTEXT'); 
        $text->insert('end', " details the clone name in either St louis notation in the St Louis box or Sanger notation in the Sanger Centre box.\n\n");
        $text->insert('end', "The 3rd section", 'REDTEXT');
        $text->insert('end', " provides the number of bands in the gel.\n\n");
        $text->insert('end', "The last section",'REDTEXT');  
        $text->insert('end', " provides the total number of sizes (t.sizes) in the file for that particular clone.\n 
This ensures that the windows are less cluttered with information, and that the user can make an easy choice into which clone entry they would like to copy.\n\n\n");

	$text->insert('end', "Process of Selection and Exiting\n\n", 'BLUETEXT');
	$text->insert('end', "To select a clone, double click on the highlighted row. Only ONE selection from either the St Louis or Sanger Centre box can be made, as a selection causes the module to copy the file associated with the selection, exit and importCRD to be called. Also exiting the program via the explicit exit button, causes the user to exit the program completely and not continue with the process.\n\n\n");  
   
    }


#this subroutine just hold the credits.  
    
sub CreditsInfo {
	my $credit;
	$credit->destroy if Exists($credit);
	$credit = $mw->Toplevel();
	$credit->configure(-title=>"Lclone Credits");
	$credit->minsize(175, 200);
	$credit->maxsize(175, 200);
	$credit->packPropagate(0);
	
	my $c_frame = $credit->Frame(-relief=>'groove', -borderwidth=>2)->pack(-fill=>'x', -fill=>'y');
	my $frame1 = $c_frame->Frame()->pack(-anchor=>'nw', -fill=>'x');

	my $text_frame = $credit->Frame(-relief=>'groove', -borderwidth=>2)->pack(-fill=>'x', -fill=>'y');
	my $frame2 = $text_frame->Frame()->pack(-anchor=>'s', -fill=>'x', -pady=>10);
	
	my $title = $frame1->Label(-text=>"CREDITS")->pack();
	
	my $c_exitbutton = $frame1->Button(-text=>'Exit Credits ', -width=>30,  -activebackground=>'DarkSlateGray2', -command=>sub{$credit->destroy;})->pack(-side=>'bottom', -anchor=>'w');
	
	my $text  = $frame2->ROText(-width =>50, -wrap=>'word', -bg=>'LightSkyBlue1', -height=>50)->pack();
	$text->pack(-side=>'top');
	
	$text->insert('end', "This module was written by Karen Ambrose.\n\n\n");
	
    }
    
#this subroutine clears all the data out from all the boxes ready to search for a new clone.
    
    sub Clear {
	
	$clone_entry->delete('0.0', 'end');
	$stlinside->delete('0.0', 'end');
	$scinside->delete('0.0', 'end');
	
	$go_find->configure(-state=>"normal");
	$stlinside->configure(-state => 'disabled', bg=>"grey");
	$scinside->configure(-state => 'disabled', bg=>"grey");
	$notebook->pageconfigure('p1', -state => 'disabled');
	$notebook->pageconfigure('p2', -state => 'disabled');
    }


sub Exit {
    my ($n, $filename)=@_;
    if (!defined $n){
	print "\nNo Selection Made\n";
	exit 1;
    }
    else {
	print "\nSelection Made : $n ($filename)\n";
	exit 0;
    }	
}


#_END OF PROGRAM_




