<commit_before>package EnsEMBL::Web::Component::VariationImage;

use strict;

use base qw(EnsEMBL::Web::Component::Gene);

sub _init {
  my $self = shift;
  $self->cacheable(0);
  $self->ajaxable(1);
  $self->has_image(1);
}

sub content {
  my $self        = shift;
  my $no_snps     = shift;
  my $ic_type     = shift || 'GeneSNPView';
  my $hub         = $self->hub;
  my $object      = $self->object;
  my $image_width = $self->image_width     || 800;  
  my $context     = $hub->param('context') || 100; 
  my $extent      = $context eq 'FULL' ? 5000 : $context;
  my @confs       = qw(gene transcripts_top transcripts_bottom);
  my ($image_configs, $snp_counts, $gene_object, $transcript_object, $config_type, @trans);
  my $config_type = 'GeneSNPView'; 

  if ($object->isa('EnsEMBL::Web::Object::Gene') || $object->isa('EnsEMBL::Web::Object::LRG')){
    $gene_object = $object;
  } else {
    $transcript_object = $object;
    $gene_object = $self->hub->core_objects->{'gene'};
  }
 
  # Padding
  # Get 4 configs - and set width to width of context config
  # Get two slice -  gene (4/3x) transcripts (+/-extent)
  
  push @confs, 'snps' unless $no_snps;  

  foreach (@confs) { 
    $image_configs->{$_} = $hub->get_imageconfig($config_type, $_);  
    $image_configs->{$_}->set_parameters({
      image_width => $image_width, 
      context     => $context
    });
  }


  $gene_object->get_gene_slices(
    $image_configs->{'gene'},
    [ 'gene',        'normal', '33%'   ],
    [ 'transcripts', 'munged', $extent ]
  );
  
  my $transcript_slice = $gene_object->__data->{'slices'}{'transcripts'}[1]; 
  my $sub_slices       = $gene_object->__data->{'slices'}{'transcripts'}[2];  

  # Fake SNPs
  # Grab the SNPs and map them to subslice co-ordinate
  # $snps contains an array of array each sub-array contains [fake_start, fake_end, B:E:Variation object] # Stores in $object->__data->{'SNPS'}
  my ($count_snps, $snps, $context_count) = $gene_object->getVariationsOnSlice($transcript_slice, $sub_slices);  
  my $start_difference   = $gene_object->__data->{'slices'}{'transcripts'}[1]->start - $gene_object->__data->{'slices'}{'gene'}[1]->start;
  my @fake_filtered_snps = map [ $_->[2]->start + $start_difference, $_->[2]->end + $start_difference, $_->[2] ], @$snps;
  my @domain_logic_names = qw(Pfam scanprosite Prints pfscan PrositePatterns PrositeProfiles Tigrfam Superfamily Smart PIRSF);
  
  $image_configs->{'gene'}->{'filtered_fake_snps'} = \@fake_filtered_snps unless $no_snps;
  
  # Make fake transcripts
  $gene_object->store_TransformedTranscripts;                            # Stores in $transcript_object->__data->{'transformed'}{'exons'|'coding_start'|'coding_end'}
  $gene_object->store_TransformedDomains($_) for @domain_logic_names;    # Stores in $transcript_object->__data->{'transformed'}{'Pfam_hits'}
  $gene_object->store_TransformedSNPS unless $no_snps;                   # Stores in $transcript_object->__data->{'transformed'}{'snps'}


  # This is where we do the configuration of containers
  my (@transcripts, @containers_and_configs);

  # sort so trancsripts are displayed in same order as in transcript selector table  
  my $strand = $object->Obj->strand;
  @trans  = @{$gene_object->get_all_transcripts};
  my @sorted_trans;
  
  if ($strand == 1) {
    @sorted_trans = sort { $b->Obj->external_name cmp $a->Obj->external_name || $b->Obj->stable_id cmp $a->Obj->stable_id } @trans;
  } else {
    @sorted_trans = sort { $a->Obj->external_name cmp $b->Obj->external_name || $a->Obj->stable_id cmp $b->Obj->stable_id } @trans;
  } 

  foreach my $trans_obj (@sorted_trans) {
    next if $transcript_object && $trans_obj->stable_id ne $transcript_object->stable_id;
    my $image_config = $hub->get_imageconfig($ic_type, $trans_obj->stable_id);
    $image_config->init_transcript;
    
    # create config and store information on it
    $trans_obj->__data->{'transformed'}{'extent'} = $extent;
    
    $image_config->{'geneid'}      = $gene_object->stable_id;
    $image_config->{'snps'}        = $snps unless $no_snps;
    $image_config->{'subslices'}   = $sub_slices;
    $image_config->{'extent'}      = $extent;
    $image_config->{'_add_labels'} = 1;
    
    # Store transcript information on config
    my $transformed_slice = $trans_obj->__data->{'transformed'};

    $image_config->{'transcript'} = {
      exons        => $transformed_slice->{'exons'},
      coding_start => $transformed_slice->{'coding_start'},
      coding_end   => $transformed_slice->{'coding_end'},
      transcript   => $trans_obj->Obj,
      gene         => $gene_object->Obj
    };
    
    $image_config->{'transcript'}{'snps'} = $transformed_slice->{'snps'} unless $no_snps;
    
    # Turn on track associated with this db/logic name
    $image_config->modify_configs(
      [ $image_config->get_track_key('gsv_transcript', $gene_object) ],
      { display => 'normal', show_labels => 'off', caption => '' }
    );

    $image_config->{'transcript'}{lc($_) . '_hits'} = $transformed_slice->{lc($_) . '_hits'} for @domain_logic_names;
    $image_config->set_parameters({ container_width => $gene_object->__data->{'slices'}{'transcripts'}[3] });

    if ($gene_object->seq_region_strand < 0) {
      push @containers_and_configs, $transcript_slice, $image_config;
    } else {
      unshift @containers_and_configs, $transcript_slice, $image_config; # If forward strand we have to draw these in reverse order (as forced on -ve strand)
    }
    
    push @transcripts, { exons => $transformed_slice->{'exons'} };
  }
  
  # Map SNPs for the last SNP display
  my $snp_rel     = 5;  # relative length of snp to gap in bottom display
  my $fake_length = -1; # end of last drawn snp on bottom display
  my $slice_trans = $transcript_slice;

  # map snps to fake evenly spaced co-ordinates
  my @snps2;
  
  if (!$no_snps) {
    foreach (sort { $a->[0] <=> $b->[0] } @$snps) {
      $fake_length += $snp_rel + 1;
      <commit_msg>updated image config names<commit_after>package EnsEMBL::Web::Component::VariationImage;

use strict;

use base qw(EnsEMBL::Web::Component::Gene);

sub _init {
  my $self = shift;
  $self->cacheable(0);
  $self->ajaxable(1);
  $self->has_image(1);
}

sub content {
  my $self        = shift;
  my $no_snps     = shift;
  my $ic_type     = shift || 'gene_variation';  
  my $hub         = $self->hub;
  my $object      = $self->object;
  my $image_width = $self->image_width     || 800;  
  my $context     = $hub->param('context') || 100; 
  my $extent      = $context eq 'FULL' ? 5000 : $context;
  my @confs       = qw(gene transcripts_top transcripts_bottom);
  my ($image_configs, $config_type, $snp_counts, $gene_object, $transcript_object, @trans);

  if ($object->isa('EnsEMBL::Web::Object::Gene') || $object->isa('EnsEMBL::Web::Object::LRG')){
    $gene_object = $object;
    $config_type = 'gene_variation';
  } else {
    $transcript_object = $object;
    $gene_object = $self->hub->core_objects->{'gene'};
    $config_type = $ic_type;
  }
 
  # Padding
  # Get 4 configs - and set width to width of context config
  # Get two slice -  gene (4/3x) transcripts (+/-extent)
  
  push @confs, 'snps' unless $no_snps;  

  foreach (@confs) { 
    $image_configs->{$_} = $hub->get_imageconfig($_ eq 'gene' ? $ic_type : $config_type, $_);  
    $image_configs->{$_}->set_parameters({
      image_width => $image_width, 
      context     => $context
    });
  }


  $gene_object->get_gene_slices(
    $image_configs->{'gene'},
    [ 'gene',        'normal', '33%'   ],
    [ 'transcripts', 'munged', $extent ]
  );
  
  my $transcript_slice = $gene_object->__data->{'slices'}{'transcripts'}[1]; 
  my $sub_slices       = $gene_object->__data->{'slices'}{'transcripts'}[2];  

  # Fake SNPs
  # Grab the SNPs and map them to subslice co-ordinate
  # $snps contains an array of array each sub-array contains [fake_start, fake_end, B:E:Variation object] # Stores in $object->__data->{'SNPS'}
  my ($count_snps, $snps, $context_count) = $gene_object->getVariationsOnSlice($transcript_slice, $sub_slices);  
  my $start_difference   = $gene_object->__data->{'slices'}{'transcripts'}[1]->start - $gene_object->__data->{'slices'}{'gene'}[1]->start;
  my @fake_filtered_snps = map [ $_->[2]->start + $start_difference, $_->[2]->end + $start_difference, $_->[2] ], @$snps;
  my @domain_logic_names = qw(Pfam scanprosite Prints pfscan PrositePatterns PrositeProfiles Tigrfam Superfamily Smart PIRSF);
  
  $image_configs->{'gene'}->{'filtered_fake_snps'} = \@fake_filtered_snps unless $no_snps;
  
  # Make fake transcripts
  $gene_object->store_TransformedTranscripts;                            # Stores in $transcript_object->__data->{'transformed'}{'exons'|'coding_start'|'coding_end'}
  $gene_object->store_TransformedDomains($_) for @domain_logic_names;    # Stores in $transcript_object->__data->{'transformed'}{'Pfam_hits'}
  $gene_object->store_TransformedSNPS unless $no_snps;                   # Stores in $transcript_object->__data->{'transformed'}{'snps'}


  # This is where we do the configuration of containers
  my (@transcripts, @containers_and_configs);

  # sort so trancsripts are displayed in same order as in transcript selector table  
  my $strand = $object->Obj->strand;
  @trans  = @{$gene_object->get_all_transcripts};
  my @sorted_trans;
  
  if ($strand == 1) {
    @sorted_trans = sort { $b->Obj->external_name cmp $a->Obj->external_name || $b->Obj->stable_id cmp $a->Obj->stable_id } @trans;
  } else {
    @sorted_trans = sort { $a->Obj->external_name cmp $b->Obj->external_name || $a->Obj->stable_id cmp $b->Obj->stable_id } @trans;
  } 

  foreach my $trans_obj (@sorted_trans) {
    next if $transcript_object && $trans_obj->stable_id ne $transcript_object->stable_id;
    my $image_config = $hub->get_imageconfig($ic_type, $trans_obj->stable_id);
    $image_config->init_transcript;
    
    # create config and store information on it
    $trans_obj->__data->{'transformed'}{'extent'} = $extent;
    
    $image_config->{'geneid'}      = $gene_object->stable_id;
    $image_config->{'snps'}        = $snps unless $no_snps;
    $image_config->{'subslices'}   = $sub_slices;
    $image_config->{'extent'}      = $extent;
    $image_config->{'_add_labels'} = 1;
    
    # Store transcript information on config
    my $transformed_slice = $trans_obj->__data->{'transformed'};

    $image_config->{'transcript'} = {
      exons        => $transformed_slice->{'exons'},
      coding_start => $transformed_slice->{'coding_start'},
      coding_end   => $transformed_slice->{'coding_end'},
      transcript   => $trans_obj->Obj,
      gene         => $gene_object->Obj
    };
    
    $image_config->{'transcript'}{'snps'} = $transformed_slice->{'snps'} unless $no_snps;
    
    # Turn on track associated with this db/logic name 
    $image_config->modify_configs(
      [ $image_config->get_track_key('gsv_transcript', $gene_object) ],
      { display => 'normal', show_labels => 'off', caption => '' }
    );

    $image_config->{'transcript'}{lc($_) . '_hits'} = $transformed_slice->{lc($_) . '_hits'} for @domain_logic_names;
    $image_config->set_parameters({ container_width => $gene_object->__data->{'slices'}{'transcripts'}[3] });

    if ($gene_object->seq_region_strand < 0) {
      push @containers_and_configs, $transcript_slice, $image_config;
    } else {
      unshift @containers_and_configs, $transcript_slice, $image_config; # If forward strand we have to draw these in reverse order (as forced on -ve strand)
    }
    
    push @transcripts, { exons => $transformed_slice->{'exons'} };
  }
  
  # Map SNPs for the last SNP display
  my $snp_rel     = 5;  # relative length of snp to gap in bottom display
  my $fake_length = -1; # end of last drawn snp on bottom display
  my $slice_trans = $transcript_slice;

  # map snps to fake evenly spaced co-ordinates
  my @snps2;
  
  if (!$no_snps) {
    foreach (sort { $a->[0] <=> $b->[0] } @$snps) {
      $fake_length += $snp_rel + 1;
      
{'fraction_non_alphanumeric': 0.16201350112509375, 'fraction_numerical': 0.005833819484957079, 'mean_word_length': 3.7058823529411766, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 229, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7051440', 'n_tokens_mistral': 4464, 'n_tokens_neox': 4142, 'n_words': 854}