<commit_before># $Id$

package EnsEMBL::Web::ViewConfig::Export;

use strict;

use EnsEMBL::Web::Constants;

use base qw(EnsEMBL::Web::ViewConfig);

sub init {
  my $view_config = shift;
  my $misc_sets  = $view_config->species_defs->databases->{'DATABASE_CORE'}->{'tables'}->{'misc_feature'}->{'sets'};
  
  my %defaults;
  
  $defaults{'output'} = 'fasta';
  $defaults{'strand'} = $view_config->hub->action eq 'Location' ? 'forward' : 'feature';
  
  $defaults{$_} = 0 for qw(flank5_display flank3_display);
  
  $defaults{'fasta_' . $_} = 'yes' for qw(cdna coding peptide utr5 utr3 exon intron);
  $defaults{'gff3_'  . $_} = 'yes' for qw(gene transcript exon intron cds);
  $defaults{'bed_'  . $_} = 'yes' for qw(userdata description);
  $defaults{'gtf_'  . $_} = 'yes' for qw(similarity repeat genscan contig variation marker gene vegagene estgene);
#  $defaults{'psl_'  . $_} = 'yes' for qw();
  $defaults{'fasta_genomic'} = 'unmasked';
  
  foreach my $f (qw(csv tab gff)) {
    $defaults{$f . '_' . $_} = 'yes' for qw(similarity repeat genscan variation gene);
    
    next if $f eq 'gff';
    
    $defaults{$f . '_miscset_' . $_} = 'yes' for keys %$misc_sets;
  }
  
  foreach my $f (qw(embl genbank)) {
    $defaults{$f . '_' . $_} = 'yes' for qw(similarity repeat genscan contig variation marker gene vegagene estgene);
  }
  
  $view_config->_set_defaults(%defaults);
  $view_config->storable       = 1;
  $view_config->default_config = 0;
}

sub form {
  my ($view_config, $object) = @_;
  
  my $hub      = $view_config->hub;
  my $function = $hub->function;
  
  return if $function !~ /Location|Gene|Transcript/;
  
  my $action              = $hub->action;
  my $config              = $object->config;
  my $slice               = $object->slice;
  my $form_action         = $hub->url({ action => 'Form', function => $function }, 1);
  my %gene_markup_options = EnsEMBL::Web::Constants::GENE_MARKUP_OPTIONS;
  
  $view_config->get_form->set_attribute('action', $form_action->[0]);
  $view_config->get_form->set_attribute('id', 'export_configuration');
  $view_config->get_form->set_attribute('class', ' export');
  $view_config->get_form->set_attribute('method', 'get');
    
  $view_config->add_fieldset;
  
  $view_config->add_form_element({
    type    => 'Hidden',
    name    => 'panel_type',
    classes => [ 'panel_type' ],
    value   => 'Exporter'
  });
  
  $view_config->add_form_element({
    type  => 'Hidden',
    name  => 'save',
    value => 'yes'
  });
  
  foreach (keys %{$form_action->[1]}) {
    $view_config->add_form_element({
      type  => 'Hidden',
      name  => $_,
      value => $form_action->[1]->{$_}
    });
  }
  
  $view_config->add_form_element({
    type  => 'NoEdit',
    name  => 'location_to_export',
    label => 'Location to export',
    value => $slice->name
  });
  
  if ($function eq 'Gene') {
    $view_config->add_form_element({
      type  => 'NoEdit',
      name  => 'gene_to_export',
      label => 'Gene to export',
      value => $hub->core_objects->{'gene'}->long_caption
    });
  } elsif ($function eq 'Transcript') {    
    $view_config->add_form_element({
      type  => 'NoEdit',
      name  => 'transcript_to_export',
      label => 'Transcript to export',
      value => $hub->core_objects->{'transcript'}->long_caption
    });
  } 
  
  $view_config->add_fieldset(undef, 'general_options');
  
  my @output_values;
  
  foreach my $c (sort keys %$config) {
    foreach (@{$config->{$c}->{'formats'}}) {
      push (@output_values, { group => $config->{$c}->{'label'}, value => $_->[0], name => $_->[1] });
    }
  }
  
  if (scalar @output_values) {
    $view_config->add_form_element({
      type     => 'DropDown', 
      select   => 'select',
      required => 'yes',
      name     => 'output',
      classes  => [ 'output_type' ],
      label    => 'Output',
      values   => \@output_values
    });
  }
  
  if ($function eq 'Location') {
    my $s = $slice->strand;
    my @strand = map $s == $_ ? 'selected="selected"' : '', (1, -1);
    
    $view_config->get_form->add_field({
      label     => 'Select location',
      inline    => 1,
      elements  => [
        {'type' => 'string',    'size' => '1', 'value' => $slice->seq_region_name, 'name' => 'new_region', 'required' => 1},
        {'type' => 'posint',    'size' => '8', 'value' => $slice->start,           'name' => 'new_start',  'required' => 1},
        {'type' => 'posint',    'size' => '8', 'value' => $slice->end,             'name' => 'new_end',    'required' => 1},
        {'type' => 'dropdown',  'size' => '1', 'value' => $slice->strand,          'name' => 'strand', 'options' => [{'value' => '1', 'caption' => '1'}, {'value' => '-1', 'caption' => '-1'}]},
      ],
    });
  } else {
    $view_config->add_form_element({<commit_msg>options for a dropdown goes in 'values' key, not 'options'<commit_after># $Id$

package EnsEMBL::Web::ViewConfig::Export;

use strict;

use EnsEMBL::Web::Constants;

use base qw(EnsEMBL::Web::ViewConfig);

sub init {
  my $view_config = shift;
  my $misc_sets  = $view_config->species_defs->databases->{'DATABASE_CORE'}->{'tables'}->{'misc_feature'}->{'sets'};
  
  my %defaults;
  
  $defaults{'output'} = 'fasta';
  $defaults{'strand'} = $view_config->hub->action eq 'Location' ? 'forward' : 'feature';
  
  $defaults{$_} = 0 for qw(flank5_display flank3_display);
  
  $defaults{'fasta_' . $_} = 'yes' for qw(cdna coding peptide utr5 utr3 exon intron);
  $defaults{'gff3_'  . $_} = 'yes' for qw(gene transcript exon intron cds);
  $defaults{'bed_'  . $_} = 'yes' for qw(userdata description);
  $defaults{'gtf_'  . $_} = 'yes' for qw(similarity repeat genscan contig variation marker gene vegagene estgene);
#  $defaults{'psl_'  . $_} = 'yes' for qw();
  $defaults{'fasta_genomic'} = 'unmasked';
  
  foreach my $f (qw(csv tab gff)) {
    $defaults{$f . '_' . $_} = 'yes' for qw(similarity repeat genscan variation gene);
    
    next if $f eq 'gff';
    
    $defaults{$f . '_miscset_' . $_} = 'yes' for keys %$misc_sets;
  }
  
  foreach my $f (qw(embl genbank)) {
    $defaults{$f . '_' . $_} = 'yes' for qw(similarity repeat genscan contig variation marker gene vegagene estgene);
  }
  
  $view_config->_set_defaults(%defaults);
  $view_config->storable       = 1;
  $view_config->default_config = 0;
}

sub form {
  my ($view_config, $object) = @_;
  
  my $hub      = $view_config->hub;
  my $function = $hub->function;
  
  return if $function !~ /Location|Gene|Transcript/;
  
  my $action              = $hub->action;
  my $config              = $object->config;
  my $slice               = $object->slice;
  my $form_action         = $hub->url({ action => 'Form', function => $function }, 1);
  my %gene_markup_options = EnsEMBL::Web::Constants::GENE_MARKUP_OPTIONS;
  
  $view_config->get_form->set_attribute('action', $form_action->[0]);
  $view_config->get_form->set_attribute('id', 'export_configuration');
  $view_config->get_form->set_attribute('class', ' export');
  $view_config->get_form->set_attribute('method', 'get');
    
  $view_config->add_fieldset;
  
  $view_config->add_form_element({
    type    => 'Hidden',
    name    => 'panel_type',
    classes => [ 'panel_type' ],
    value   => 'Exporter'
  });
  
  $view_config->add_form_element({
    type  => 'Hidden',
    name  => 'save',
    value => 'yes'
  });
  
  foreach (keys %{$form_action->[1]}) {
    $view_config->add_form_element({
      type  => 'Hidden',
      name  => $_,
      value => $form_action->[1]->{$_}
    });
  }
  
  $view_config->add_form_element({
    type  => 'NoEdit',
    name  => 'location_to_export',
    label => 'Location to export',
    value => $slice->name
  });
  
  if ($function eq 'Gene') {
    $view_config->add_form_element({
      type  => 'NoEdit',
      name  => 'gene_to_export',
      label => 'Gene to export',
      value => $hub->core_objects->{'gene'}->long_caption
    });
  } elsif ($function eq 'Transcript') {    
    $view_config->add_form_element({
      type  => 'NoEdit',
      name  => 'transcript_to_export',
      label => 'Transcript to export',
      value => $hub->core_objects->{'transcript'}->long_caption
    });
  } 
  
  $view_config->add_fieldset(undef, 'general_options');
  
  my @output_values;
  
  foreach my $c (sort keys %$config) {
    foreach (@{$config->{$c}->{'formats'}}) {
      push (@output_values, { group => $config->{$c}->{'label'}, value => $_->[0], name => $_->[1] });
    }
  }
  
  if (scalar @output_values) {
    $view_config->add_form_element({
      type     => 'DropDown', 
      select   => 'select',
      required => 'yes',
      name     => 'output',
      classes  => [ 'output_type' ],
      label    => 'Output',
      values   => \@output_values
    });
  }
  
  if ($function eq 'Location') {
    my $s = $slice->strand;
    my @strand = map $s == $_ ? 'selected="selected"' : '', (1, -1);
    
    $view_config->get_form->add_field({
      label     => 'Select location',
      inline    => 1,
      elements  => [
        {'type' => 'string',    'size' => '1', 'value' => $slice->seq_region_name, 'name' => 'new_region', 'required' => 1},
        {'type' => 'posint',    'size' => '8', 'value' => $slice->start,           'name' => 'new_start',  'required' => 1},
        {'type' => 'posint',    'size' => '8', 'value' => $slice->end,             'name' => 'new_end',    'required' => 1},
        {'type' => 'dropdown',  'size' => '1', 'value' => $slice->strand,          'name' => 'strand',     'values' => [{'value' => '1', 'caption' => '1'}, {'value' => '-1', 'caption' => '-1'}]},
      ],
    });
  } else {
    $view_config->add_form_element({
{'fraction_non_alphanumeric': 0.20022835789910734, 'fraction_numerical': 0.005812746522731991, 'mean_word_length': 2.9487704918032787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 243, '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': '919248', 'n_tokens_mistral': 3525, 'n_tokens_neox': 3421, 'n_words': 688}