Skip to content
Snippets Groups Projects
Unverified Commit 0a81f2c9 authored by Mira's avatar Mira Committed by GitHub
Browse files

Merge pull request #119 from Ensembl/Feature/BCFLocation

Feature/bcf location
parents a3be6527 26b4c61f
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ use warnings; ...@@ -34,7 +34,7 @@ use warnings;
use Carp; use Carp;
use Bio::DB::HTS::VCF; use Bio::DB::HTS::VCF;
use Bio::DB::HTS::VCF::Iterator; use Bio::DB::HTS::VCF::Iterator;
use Cwd qw(getcwd);
use parent qw/Bio::EnsEMBL::IO::Parser/; use parent qw/Bio::EnsEMBL::IO::Parser/;
sub open { sub open {
...@@ -51,6 +51,21 @@ sub open { ...@@ -51,6 +51,21 @@ sub open {
return $self; return $self;
} }
sub open_with_location {
my ($caller, $filename, $location, @other_args) = @_;
my $class = ref($caller) || $caller;
# initialize generic parser
my $self = $class->SUPER::new(@other_args);
my $currentDir = getcwd();
chdir($location);
$self->{record} = undef;
$self->{bcf_file} = Bio::DB::HTS::VCF->new( filename => $filename );
$self->{iterator} = undef;
chdir($currentDir);
return $self;
}
sub seek { sub seek {
my ($self, $chrom, $start, $end) = @_; my ($self, $chrom, $start, $end) = @_;
......
...@@ -17,6 +17,7 @@ use warnings; ...@@ -17,6 +17,7 @@ use warnings;
use Test::More; use Test::More;
use Bio::EnsEMBL::IO::Parser::BCF; use Bio::EnsEMBL::IO::Parser::BCF;
use Cwd qw(getcwd);
use FindBin qw( $Bin ); use FindBin qw( $Bin );
...@@ -26,6 +27,14 @@ my $test_file = $Bin . '/input/test.bcf'; ...@@ -26,6 +27,14 @@ my $test_file = $Bin . '/input/test.bcf';
ok (my $parser = Bio::EnsEMBL::IO::Parser::BCF->open($test_file), "BCF file open"); ok (my $parser = Bio::EnsEMBL::IO::Parser::BCF->open($test_file), "BCF file open");
is ($parser->num_variants(), 9, 'correct number of variants identified in file'); is ($parser->num_variants(), 9, 'correct number of variants identified in file');
#test open with $location
my $currentDir = getcwd();
chdir('/');
ok ($parser = Bio::EnsEMBL::IO::Parser::BCF->open($test_file, $currentDir), "BCF file open with location");
is ($parser->num_variants(), 9, 'correct number of variants identified in file');
chdir($currentDir);
ok (my $h = $parser->header(), "Got header"); ok (my $h = $parser->header(), "Got header");
my $header_str = <<HEADER; my $header_str = <<HEADER;
##fileformat=VCFv4.0 ##fileformat=VCFv4.0
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment