package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
HTML::Mason::Exception::Params->throw
    ( error =>
      "Odd number of parameters passed to component expecting name/value pairs"
    ) if @_ % 2;
my ( $marker );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }

    foreach my $arg ( qw( marker ) )
    {
        HTML::Mason::Exception::Params->throw
            ( error => "no value sent for required parameter '$arg'" )
                unless exists $pos{$arg};
    }
#line 30 "/home/production/cxgn/sgn/mason/markers/polymorphisms.mas"
    $marker = $_[ $pos{'marker'} ];
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 1 "/home/production/cxgn/sgn/mason/markers/polymorphisms.mas"
$m->print( '
' );
#line 28 "/home/production/cxgn/sgn/mason/markers/polymorphisms.mas"
$m->print( '
' );
#line 32 "/home/production/cxgn/sgn/mason/markers/polymorphisms.mas"
$m->print( '
' );
#line 33 "/home/production/cxgn/sgn/mason/markers/polymorphisms.mas"

  my $polymorphisms_html='';
my $dbh = $marker->{dbh};

my $displayed_experiments = $marker->current_mapping_experiments;
my @displayed_pcr = map ( $_->{pcr_experiment} , @$displayed_experiments);
my @displayed_ids;
foreach my $ex (@displayed_pcr) {
  push  @displayed_ids, $ex->pcr_experiment_id if $ex;
}

my $experiments=$marker->experiments();
if($experiments and @{$experiments}) {
  for my $experiment(@{$experiments}) {
    my $pcr=$experiment->{pcr_experiment};
    my $rflp=$experiment->{rflp_experiment};
    if($pcr and !grep {$_==$pcr->pcr_experiment_id()} @displayed_ids) {
      my $pcr_bands=$pcr->pcr_bands_hash_of_strings();
      my $digest_bands=$pcr->pcr_digest_bands_hash_of_strings();
      my $pcr_bands_html='';
      my $digest_bands_html='';
      for my $stock_id(keys(%{$pcr_bands})) {
	#my $accession_name=CXGN::Accession->new($dbh,$accession_id)->verbose_name();
	my $sth = $dbh->prepare("SELECT organism.species || ' ' ||  stock.name FROM public.stock JOIN public.organism USING(organism_id) WHERE stock_id=?");
	$sth->execute($stock_id);
	my ($stock_name) = $sth->fetchrow_array();
	$pcr_bands_html.="<b>$stock_name:</b> $pcr_bands->{$stock_id}<br />";
      }
      for my $stock_id(keys(%{$digest_bands})) {
	my $sth = $dbh->prepare("SELECT organism.species || ' ' ||  stock.name FROM public.stock JOIN public.organism USING(organism_id) WHERE stock_id=?");
	$sth->execute($stock_id);
	my ($stock_name) = $sth->fetchrow_array();
#	my $accession_name=CXGN::Accession->new($dbh,$accession_id)->verbose_name();
	$digest_bands_html.="<b>$stock_name:</b> $digest_bands->{$stock_id}<br />";
      }
      my $mg='';
      if($pcr->mg_conc()) {   
	$mg=$pcr->mg_conc().'mM';
      }
      my $temp='';
      if($pcr->temp()) { 
	$temp=$pcr->temp().'&deg;C';
      }                    
      $polymorphisms_html.='<tr><td width="100%">';
      my $fwd=$pcr->fwd_primer();
      my $rev=$pcr->rev_primer();
      if($fwd) {
	$fwd='<span class="sequence">'.$fwd.'</span>';
      }
      else {
	$fwd='<span class="ghosted">Unknown</span>';
      }
      if($rev) {
	$rev='<span class="sequence">'.$rev.'</span>';
      }
      else {
	$rev='<span class="ghosted">Unknown</span>';
      }  
      my $enz=$pcr->enzyme()||'unknown enzyme';                 
      my $additional_enzymes= $pcr->additional_enzymes;
      $temp||='<span class="ghosted">Unknown</span>';
      $mg||='<span class="ghosted">Unknown</span>';
      my $digest_title="Digested band sizes (using $enz)";
      unless($digest_bands_html) {
	$digest_title='&nbsp;'; 
	$digest_bands_html='&nbsp;'; 
      }
      $polymorphisms_html.=CXGN::Page::FormattingHelpers::info_table_html
	(
	 '__title'=>"PCR data&nbsp;&nbsp;&nbsp;<span class=\"tinytype\">Exp. ID ".$pcr->pcr_experiment_id."</span>",
	 "Forward primer (5'-3')"=>"<span class=\"sequence\">$fwd</span>",
	 "Reverse primer (5'-3')"=>"<span class=\"sequence\">$rev</span>",
	 'Accessions and product sizes'=>$pcr_bands_html,
	 $digest_title=>$digest_bands_html,
	 'Enzymes'               => $additional_enzymes,
	 'Approximate temperature'=>$temp,
	 'Mg<sup>+2</sup> concentration'=>$mg,
	 '__multicol'=>3,
	 '__tableattrs'=>"width=\"100%\"",
	);
      $polymorphisms_html.='</td></tr>';
    }
  }
}
if($polymorphisms_html) {
 print  info_section_html(title=>'Other PCR data',contents=>'<table width="100%" cellspacing="0" cellpadding="0" border="0">'.$polymorphisms_html.'</table>');
}
else {
  return '';
}

;return;
},
'declared_args' => {
  '$marker' => { default => undef }
},
'load_time' => 1763079527,

)
;