Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.


Can You Identify The Bug?


use 5.010 ;
use strict ;
use warnings ;
use Carp ;
use Data::Dumper ;
use Getopt::Long ;
use Pod::Usage ;

use lib '/home/ltl/lib' ;
use SecGenTools::Run 'get_run_data' ;
use SecGenTools::Accession 'get_accession_data' ;
use SecGenTools::Request 'get_request_data' ;

my $config      = config() ;
my $run_stub    = get_run_data( $config->{ run_id } ) ;
my $run         = $run_stub->{ $config->{ run_id } } ;
my $run_samples = get_run_sample( $config->{ run_id } ) ;
my %conversion =
    map { $_, $run->{ max_regions } + 1 - $_ } 1 .. $run->{ max_regions } ;

for my $region ( 1 .. $run->{ max_regions } ) {
   my $conversion = $conversion{ $region } ;
   for my $sample_id ( sort keys %$run_samples ) {
       my $sample = $run_samples->{ $sample_id } ;
       next if $sample->{ region } != $region ;
       $sample->{ region } = $conversion ;
       update_run_sample( $sample ) ;
       say join "\n\t" , $sample_id ,
           $sample->{ accession_id } ,
           $region ,
           $conversion ,

exit 1 ;

This is the core of the code. config() puts all the configuration options into a hash and returns it. get_run_data(), get_request_data(), andget_accession_data(), are wrappers around database calls.

An accession is an individual sample to be analyzed. A request is one or more accessions. A run is one or more requests, assigning the accessions to one of the regions. And, because this is a mapping between a data structure and a physical object, it is possible for the user to start at the wrong end. This program is supposed to take all the requests and reverse the regions. That is, for an 8-region run, all the accessions in region 1 should be in region 8 and vice versa.

This code puts everything in regions 1-4. It took me a morning to figure out why, although part of that was restoring the database to the way it was before.

It took me a while to get it, so stop here if you're still looking.

In a word, persistence.

$sample is a reference to the data in $run_samples. In my mind, my $sample = $run_samples->{ $sample_id } made a local copy, but it didn't. That meant that, when the code hits region 5, it works on the accessions just moved over from region 4, too, and so on.

And, in working around that, I decided that looping on region was useless except to massage the retentive control freak in me, and once I convinced myself of that, things got better. So, like the Monster at the End of the Book, the bug is me.