<commit_before>package EnsEMBL::Web::Component::Gene::GeneSVTable;

use strict;

use Bio::EnsEMBL::Variation::Utils::Constants;

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

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

sub content {
  my $self   = shift;
  my $hub    = $self->hub;
  my $object = $self->object;
	my $html;
	
	my $slice = $object->slice;
	
	
	#### Image configuration ####
	
	my $gene_slice = $slice;#$slice->expand(10e3, 10e3);
     $gene_slice = $gene_slice->invert if $object->seq_region_strand < 0;
     
  # Get the web_image_config
  my $image_config = $object->get_imageconfig('gene_sv_view');
  
  $image_config->set_parameters({
    container_width => $gene_slice->length,
    image_width     => $object->param('i_width') || $self->image_width || 800,
    slice_number    => '1|1',
  });
  
  $self->_attach_das($image_config);

	# Transcript track
  my $key  = $image_config->get_track_key('transcript', $object);
  my $node = $image_config->get_node(lc $key);
  $node->set('display', 'transcript_label') if $node && $node->get('display') eq 'off';

  my $image = $self->new_image($gene_slice, $image_config, [ $object->stable_id ]);
  
  #return if $self->_export_image($image);
  
  $image->imagemap         = 'yes';
  $image->{'panel_number'} = 'top';
  $image->set_button('drag', 'title' => 'Drag to select region');
  
  $html .= $image->render;
	
	
	#### Table configuration ####
	
	my $columns = [
     { key => 'id',          sort => 'string',        title => 'Name'   },
     { key => 'location',    sort => 'position_html', title => 'Chr:bp' },
		 { key => 'size',    		 sort => 'string',        title => 'Genomic size (bp)' },
     { key => 'class',       sort => 'string',        title => 'Class'  },
     { key => 'source',      sort => 'string',        title => 'Source Study' },
     { key => 'description', sort => 'string',        title => 'Study description', width => '50%' },
  ];
	
	
	# structural variation table
  $html .= $self->structural_variation_table($slice, $columns);
  
	# copy number variant probe table
  $html .= $self->cnv_probe_table($slice, $columns);
	
	return $html;
}


sub structural_variation_table{
  my $self     = shift;
  my $slice    = shift;
	my $columns  = shift;
  my $hub      = $self->hub;
  my $title    = 'Structural variants';
	my $table_id = 'sv';
	my $html;
  
  my $rows;
	
	foreach my $sv (@{$slice->get_all_StructuralVariations}) {
		my $name        = $sv->variation_name;
    my $description = $sv->source_description;
		my $ext_ref     = $sv->external_reference;
	 	my $sv_class    = $sv->class;
	  my $source      = $sv->source;
		my $study_url   = $sv->study_url;
	  
		# SV size (format the size with comma separations, e.g: 10000 to 10,000)
		my $sv_size = ($sv->end-$sv->start+1);
		my $int_length = length($sv_size);
		if ($int_length>3){
			my $nb = 0;
			my $int_string = '';
			while (length($sv_size)>3) {
				$sv_size =~ /(\d{3})$/;
				if ($int_string ne '') {	$int_string = ','.$int_string; }
				$int_string = $1.$int_string;
				$sv_size = substr($sv_size,0,(length($sv_size)-3));
			}	
			$sv_size = "$sv_size,$int_string";
		}	
		
	  # Add study information
	  if ($sv->study_name ne '') {
	  	$source .= ":".$sv->study_name;
			$source = sprintf ('<a rel="external" href="%s">%s</a>',$study_url,$source);
			$description .= $sv->study_description;
	  }
      
    if ($ext_ref =~ /pubmed\/(.+)/) {
			my $pubmed_id = $1;
			my $pubmed_link = $hub->get_ExtURL('PUBMED', $pubmed_id);
      $description =~ s/$pubmed_id/'<a href="'.$pubmed_link.'" target="_blank">'.$&.'<\/a>'/eg;
    }
			
    my $sv_link = $hub->url({
       		type    => 'StructuralVariation',
        	action  => 'Summary',
        	sv      => $name
       	});      

    my $loc_string = $sv->seq_region_name . ':' . $sv->seq_region_start . '-' . $sv->seq_region_end;
        
    my $loc_link = $hub->url({
        	type   => 'Location',
        	action => 'View',
        	r      => $loc_string,
      	});
      
    my %row = (
        	id          => qq{<a href="$sv_link">$name</a>},
        	location    => qq{<a href="$loc_link">$loc_string</a>},
					size        => $sv_size,
        	class       => $sv_class,<commit_msg>Update the Structural variants table<commit_after>package EnsEMBL::Web::Component::Gene::GeneSVTable;

use strict;

use Bio::EnsEMBL::Variation::Utils::Constants;

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

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

sub content {
  my $self   = shift;
  my $hub    = $self->hub;
  my $object = $self->object;
	my $html;
	
	my $slice = $object->slice;
	
	
	#### Image configuration ####
	
	my $gene_slice = $slice;
     $gene_slice = $gene_slice->invert if $object->seq_region_strand < 0;
     
  # Get the web_image_config
  my $image_config = $object->get_imageconfig('gene_sv_view');
  
  $image_config->set_parameters({
    container_width => $gene_slice->length,
    image_width     => $object->param('i_width') || $self->image_width || 800,
    slice_number    => '1|1',
  });
  
  $self->_attach_das($image_config);

	# Transcript track
  my $key  = $image_config->get_track_key('transcript', $object);
  my $node = $image_config->get_node(lc $key);
  $node->set('display', 'transcript_label') if $node && $node->get('display') eq 'off';

  my $image = $self->new_image($gene_slice, $image_config, [ $object->stable_id ]);
  
  #return if $self->_export_image($image);
  
  $image->imagemap         = 'yes';
  $image->{'panel_number'} = 'top';
  $image->set_button('drag', 'title' => 'Drag to select region');
  
  $html .= $image->render;
	
	
	#### Table configuration ####
	
	my $columns = [
     { key => 'id',          sort => 'string',        title => 'Name'   },
     { key => 'location',    sort => 'position_html', title => 'Chr:bp' },
		 { key => 'size',    		 sort => 'string',        title => 'Genomic size (bp)' },
     { key => 'class',       sort => 'string',        title => 'Class'  },
     { key => 'source',      sort => 'string',        title => 'Source Study' },
     { key => 'description', sort => 'string',        title => 'Study description', width => '50%' },
  ];
	
	
	# structural variation table
  $html .= $self->structural_variation_table($slice, $columns);
  
	# copy number variant probe table
  $html .= $self->cnv_probe_table($slice, $columns);
	
	return $html;
}


sub structural_variation_table{
  my $self     = shift;
  my $slice    = shift;
	my $columns  = shift;
  my $hub      = $self->hub;
  my $title    = 'Structural variants';
	my $table_id = 'sv';
	my $html;
  
  my $rows;
	
	foreach my $sv (@{$slice->get_all_StructuralVariations}) {
		my $name        = $sv->variation_name;
    my $description = $sv->source_description;
		my $ext_ref     = $sv->external_reference;
	 	my $sv_class    = $sv->class;
	  my $source      = $sv->source;
		my $study_url   = $sv->study_url;
	  
		# SV size (format the size with comma separations, e.g: 10000 to 10,000)
		my $sv_size = ($sv->end-$sv->start+1);
		my $int_length = length($sv_size);
		if ($int_length>3){
			my $nb = 0;
			my $int_string = '';
			while (length($sv_size)>3) {
				$sv_size =~ /(\d{3})$/;
				if ($int_string ne '') {	$int_string = ','.$int_string; }
				$int_string = $1.$int_string;
				$sv_size = substr($sv_size,0,(length($sv_size)-3));
			}	
			$sv_size = "$sv_size,$int_string";
		}	
		
	  # Add study information
	  if ($sv->study_name ne '') {
	  	$source .= ":".$sv->study_name;
			$source = sprintf ('<a rel="external" href="%s">%s</a>',$study_url,$source);
			$description .= ': '.$sv->study_description;
	  }
      
    if ($ext_ref =~ /pubmed\/(.+)/) {
			my $pubmed_id = $1;
			my $pubmed_link = $hub->get_ExtURL('PUBMED', $pubmed_id);
      $description =~ s/$pubmed_id/'<a href="'.$pubmed_link.'" target="_blank">'.$&.'<\/a>'/eg;
    }
			
    my $sv_link = $hub->url({
       		type    => 'StructuralVariation',
        	action  => 'Summary',
        	sv      => $name
       	});      

    my $loc_string = $sv->seq_region_name . ':' . $sv->seq_region_start . '-' . $sv->seq_region_end;
        
    my $loc_link = $hub->url({
        	type   => 'Location',
        	action => 'View',
        	r      => $loc_string,
      	});
      
    my %row = (
        	id          => qq{<a href="$sv_link">$name</a>},
        	location    => qq{<a href="$loc_link">$loc_string</a>},
					size        => $sv_size,
        	class       => $sv_class,
{'fraction_non_alphanumeric': 0.19396653311336318, 'fraction_numerical': 0.007541833608296017, 'mean_word_length': 2.7669773635153128, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 180, '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': '6264878', 'n_tokens_mistral': 3291, 'n_tokens_neox': 3046, 'n_words': 620}