<commit_before>=head1 LICENSE

Copyright [1999-2015] 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::Web::File::AttachedFormat::VCF;

use strict;
use warnings;
no warnings 'uninitialized';

use base qw(EnsEMBL::Web::File::AttachedFormat);

use EnsEMBL::Web::File::Utils::URL qw(chase_redirects);

sub check_data {
  my ($self) = @_;
  my $url = $self->{'url'};
  my $error = '';
  require Bio::EnsEMBL::IO::Adaptor::VCFAdaptor;

  $url = chase_redirects($url, {'hub' => $self->{'hub'}});
  if ($url =~ /^ftp:\/\//i && !$self->{'hub'}->species_defs->ALLOW_FTP_VCF) {
    $error = "The VCF file could not be added - FTP is not supported, please use HTTP.";
  } 
  else {
    # try to open and use the VCF file
    # this checks that the VCF and index files are present and correct, 
    # and should also cause the index file to be downloaded and cached in /tmp/ 
    my ($dba, $index);
    eval {
      $dba =  Bio::EnsEMBL::ExternalData::VCF::VCFAdaptor->new($url);
      $dba->fetch_variations(1, 1, 10);
    };
    warn $@ if $@;
    warn "Failed to open VCF $url\n $@\n " if $@; 
    warn "Failed to open VCF $url\n $@\n " unless $dba;
          
    if ($@ or !$dba) {
      $error = qq{
        Unable to open/index remote VCF file: $url
        <br />Ensembl can only display sorted, indexed VCF files
        <br />Ensure you have sorted and indexed your file and that your web server is accessible to the Ensembl site 
        <br />For more information on the type of file expected please see the large file format <a href="/info/website/upload/large.html">documentation.</a>
      };
    }
  }
  return ($url, $error);
}

1;

<commit_msg>Update to use new adaptor<commit_after>=head1 LICENSE

Copyright [1999-2015] 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::Web::File::AttachedFormat::VCF;

use strict;
use warnings;
no warnings 'uninitialized';

use base qw(EnsEMBL::Web::File::AttachedFormat);

use EnsEMBL::Web::File::Utils::URL qw(chase_redirects);
use Bio::EnsEMBL::IO::Adaptor::VCFAdaptor;

sub check_data {
  my ($self) = @_;
  my $url = $self->{'url'};
  my $error = '';

  my $url_check = chase_redirects($url, {'hub' => $self->{'hub'}});
  
  if (ref($url_check) eq 'HASH') {
    if ($url_check->{'error'}) {
      $error = $url_check->{'error'}[0];
    }
    else {
      $url = $url_check->{'url'};
    }
  }
  else {
    $url = $url_check;
  }

  if ($url =~ /^ftp:\/\//i && !$self->{'hub'}->species_defs->ALLOW_FTP_VCF) {
    $error = "The VCF file could not be added - FTP is not supported, please use HTTP.";
  } 
  else {
    # try to open and use the VCF file
    # this checks that the VCF and index files are present and correct, 
    # and should also cause the index file to be downloaded and cached in /tmp/ 
    my ($adaptor, $index);
    eval {
          $adaptor =  Bio::EnsEMBL::IO::Adaptor::VCFAdaptor->new($url);
          $adaptor->fetch_variations(1, 1, 10);
    };
    warn $@ if $@;
    warn "Failed to open VCF $url\n $@\n " if $@; 
    warn "Failed to open VCF $url\n $@\n " unless $adaptor;
          
    if ($@ or !$adaptor) {
      $error = qq{
          Unable to open/index remote VCF file: $url
          <br />Ensembl can only display sorted, indexed VCF files
          <br />Ensure you have sorted and indexed your file and that your web server is accessible to the Ensembl site 
          <br />For more information on the type of file expected please see the large file format <a href="/info/website/upload/large.html">documentation.</a>
      };
    }
  }
  return ($url, $error);
}

1;


{'fraction_non_alphanumeric': 0.12433694037767876, 'fraction_numerical': 0.007850625928283471, 'mean_word_length': 3.277676950998185, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217482', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1483, 'n_words': 553}