<commit_before>=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package EnsEMBL::Draw::GlyphSet::structural_variation;

### Draws structural variation tracks on e.g. Region in Detail

use strict;

use List::Util qw(min max);

use Bio::EnsEMBL::Variation::StructuralVariationFeature;

use base qw(EnsEMBL::Draw::GlyphSet_simple);

sub somatic { return $_[0]->{'my_config'}->id =~ /somatic/; }
sub class   { return 'group' if $_[0]{'display'} eq 'compact'; }
sub depth   { return $_[0]{'display'} eq 'compact' ? 1 : $_[0]{'container'}->length <= 2e5 && $_[0]->my_config('max_size') ? undef : $_[0]->SUPER::depth; }

sub colour_key {
  my ($self, $f) = @_;
  
  if (!$self->{'colours_keys'}{$f}) {
    return $self->{'colours_keys'}{$f} = 'copy_number_variation'      if $self->{'display'} eq 'compact';
    return $self->{'colours_keys'}{$f} = 'somatic_breakpoint_variant' if $f->is_somatic && $f->breakpoint_order;
    
    if ($f->class_SO_term eq 'copy_number_variation') {
      my $ssv_class = $f->get_all_supporting_evidence_classes;
      return $self->{'colours_keys'}{$f} = $ssv_class->[0] if scalar @$ssv_class == 1;
    }
    
    $self->{'colours_keys'}{$f} = $f->class_SO_term;
  }
  
  return $self->{'colours_keys'}{$f};
}

sub render_compact {
  my $self = shift;
  $self->{'my_config'}->set('height', 12);
  return $self->render_normal;
}

sub features {
  my $self   = shift; 
  my $config = $self->{'config'};
  my $id     = $self->type;
  
  if (!$self->cache($id)) {
    my $slice      = $self->{'container'};
    my $set_name   = $self->my_config('set_name');
    my $study_name = $self->my_config('study_name');
    my $var_db     = $self->my_config('db') || 'variation';
    my $svf_adaptor = $self->{'config'}->hub->get_adaptor('get_StructuralVariationFeatureAdaptor', $var_db);
    my $src_adaptor = $self->{'config'}->hub->get_adaptor('get_SourceAdaptor', $var_db);

    my ($features, %colours);
    
    if ($set_name) {
      $features = $svf_adaptor->fetch_all_by_Slice_VariationSet($slice, $self->{'config'}->hub->get_adaptor('get_VariationSetAdaptor', $var_db)->fetch_by_name($set_name));
    } elsif ($study_name) {
      $features = $svf_adaptor->fetch_all_by_Slice_Study($slice, $self->{'config'}->hub->get_adaptor('get_StudyAdaptor', $var_db)->fetch_by_name($study_name), undef);
    }
    else {
      my $source_name = $self->my_config('source');
      my $source_ = $src_adaptor->fetch_by_name($source_name);
      my $min_size = $self->my_config('min_size');
      my $max_size = $self->my_config('max_size');
      my $start    = $slice->start;
      my $end      = $slice->end;
      my @display_features;
      
      # By source
      if ($source) {
        my $func  = $self->somatic ? 'fetch_all_somatic_by_Slice_Source' : 'fetch_all_by_Slice_Source';
        $features = $svf_adaptor->$func($slice, $source, undef);
      }
      else {
        my $func  = $self->somatic ? 'fetch_all_somatic_by_Slice' : 'fetch_all_by_Slice';
        $features = $svf_adaptor->$func($slice);
      }
      
      if ($min_size || $max_size) {
        for (my $i = 0; $i < scalar @$features; $i++) {
          my $length = $features->[$i]->length;
          push @display_features, $features->[$i] if ($max_size && $length <= $max_size) || ($min_size && $length >= $min_size);
        }
        
        # Generate blocks when the track is compacted in one line (except for the Larger Structural Variants track)
        if ($max_size && $self->{'display'} eq 'compact') {
          my $slice_adaptor    = $self->{'container'}->adaptor->db->get_db_adaptor('core')->get_SliceAdaptor;
          my @list             = sort { $a->seq_region_start <=> $b->seq_region_start } @display_features;
          my $block_nb         = 1;
             @display_features = ();
          
          for (my $i = 0; $i < scalar @list; $i++) {
            my $svf     = $list[$i];
            my $start   = $svf->seq_region_start;
            my $end     = $svf->seq_region_end;
            my $b_start = $start;<commit_msg>Create source object only if source name is provided<commit_after>=head1 LICENSE

Copyright [1999-2016] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package EnsEMBL::Draw::GlyphSet::structural_variation;

### Draws structural variation tracks on e.g. Region in Detail

use strict;

use List::Util qw(min max);

use Bio::EnsEMBL::Variation::StructuralVariationFeature;

use base qw(EnsEMBL::Draw::GlyphSet_simple);

sub somatic { return $_[0]->{'my_config'}->id =~ /somatic/; }
sub class   { return 'group' if $_[0]{'display'} eq 'compact'; }
sub depth   { return $_[0]{'display'} eq 'compact' ? 1 : $_[0]{'container'}->length <= 2e5 && $_[0]->my_config('max_size') ? undef : $_[0]->SUPER::depth; }

sub colour_key {
  my ($self, $f) = @_;
  
  if (!$self->{'colours_keys'}{$f}) {
    return $self->{'colours_keys'}{$f} = 'copy_number_variation'      if $self->{'display'} eq 'compact';
    return $self->{'colours_keys'}{$f} = 'somatic_breakpoint_variant' if $f->is_somatic && $f->breakpoint_order;
    
    if ($f->class_SO_term eq 'copy_number_variation') {
      my $ssv_class = $f->get_all_supporting_evidence_classes;
      return $self->{'colours_keys'}{$f} = $ssv_class->[0] if scalar @$ssv_class == 1;
    }
    
    $self->{'colours_keys'}{$f} = $f->class_SO_term;
  }
  
  return $self->{'colours_keys'}{$f};
}

sub render_compact {
  my $self = shift;
  $self->{'my_config'}->set('height', 12);
  return $self->render_normal;
}

sub features {
  my $self   = shift; 
  my $config = $self->{'config'};
  my $id     = $self->type;
  
  if (!$self->cache($id)) {
    my $slice      = $self->{'container'};
    my $set_name   = $self->my_config('set_name');
    my $study_name = $self->my_config('study_name');
    my $var_db     = $self->my_config('db') || 'variation';
    my $svf_adaptor = $self->{'config'}->hub->get_adaptor('get_StructuralVariationFeatureAdaptor', $var_db);
    my $src_adaptor = $self->{'config'}->hub->get_adaptor('get_SourceAdaptor', $var_db);

    my ($features, %colours);
    
    if ($set_name) {
      $features = $svf_adaptor->fetch_all_by_Slice_VariationSet($slice, $self->{'config'}->hub->get_adaptor('get_VariationSetAdaptor', $var_db)->fetch_by_name($set_name));
    } elsif ($study_name) {
      $features = $svf_adaptor->fetch_all_by_Slice_Study($slice, $self->{'config'}->hub->get_adaptor('get_StudyAdaptor', $var_db)->fetch_by_name($study_name), undef);
    }
    else {
      my $source_name = $self->my_config('source');
      my $min_size = $self->my_config('min_size');
      my $max_size = $self->my_config('max_size');
      my $start    = $slice->start;
      my $end      = $slice->end;
      my @display_features;
      
      # By source
      if ($source_name) {
        my $source = $src_adaptor->fetch_by_name($source_name);
        my $func  = $self->somatic ? 'fetch_all_somatic_by_Slice_Source' : 'fetch_all_by_Slice_Source';
        $features = $svf_adaptor->$func($slice, $source, undef);
      }
      else {
        my $func  = $self->somatic ? 'fetch_all_somatic_by_Slice' : 'fetch_all_by_Slice';
        $features = $svf_adaptor->$func($slice);
      }
      
      if ($min_size || $max_size) {
        for (my $i = 0; $i < scalar @$features; $i++) {
          my $length = $features->[$i]->length;
          push @display_features, $features->[$i] if ($max_size && $length <= $max_size) || ($min_size && $length >= $min_size);
        }
        
        # Generate blocks when the track is compacted in one line (except for the Larger Structural Variants track)
        if ($max_size && $self->{'display'} eq 'compact') {
          my $slice_adaptor    = $self->{'container'}->adaptor->db->get_db_adaptor('core')->get_SliceAdaptor;
          my @list             = sort { $a->seq_region_start <=> $b->seq_region_start } @display_features;
          my $block_nb         = 1;
             @display_features = ();
          
          for (my $i = 0; $i < scalar @list; $i++) {
            my $svf     = $list[$i];
            my $start   = $svf->seq_region_start;
            my $end     = $svf->seq_region_end;
            my $b_start = $start;
{'fraction_non_alphanumeric': 0.16378662659654394, 'fraction_numerical': 0.0062251797788987874, 'mean_word_length': 3.3603182030884415, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4735556', 'n_tokens_mistral': 3302, 'n_tokens_neox': 3180, 'n_words': 721}