| 1 |
# Copyright [2015-2024] EMBL-European Bioinformatics Institute |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
use strict; |
| 16 |
use warnings; |
| 17 |
use Test::More tests => 21, 'die'; |
| 18 |
use feature qw( say ); |
| 19 |
use FindBin qw( $Bin ); |
| 20 |
|
| 21 |
BEGIN { use_ok 'Bio::DB::HTS::Tabix'; } |
| 22 |
|
| 23 |
my $test_file = $Bin . '/data/test.tsv.gz'; |
| 24 |
|
| 25 |
my $tbx = Bio::DB::HTS::Tabix->new( filename => $test_file, warnings => 0 ); |
| 26 |
my $h = $tbx->header ; |
| 27 |
ok( $h, "#CHROM FROM TO GERP" ) ; |
| 28 |
my @ha = $tbx->header_array ; |
| 29 |
ok( $ha[0], "#CHROM FROM TO GERP" ) ; |
| 30 |
|
| 31 |
ok my $iter = $tbx->query("12:8000000-8000008"), "can query a region"; |
| 32 |
|
| 33 |
#make sure we can call next |
| 34 |
ok my $row = $iter->next, 'can get a value from the iterator'; |
| 35 |
is $row, "12\t8000000\t8000000\t-2.94", 'row value is correct'; |
| 36 |
|
| 37 |
my $num_rows = 0; |
| 38 |
++$num_rows while $iter->next; |
| 39 |
is $num_rows, 7, "correct number of values come back from the iterator"; |
| 40 |
|
| 41 |
#check seqnames |
| 42 |
my $seqnames = $tbx->seqnames; |
| 43 |
isa_ok($seqnames, 'ARRAY'); |
| 44 |
is_deeply $seqnames, [1, 12, 'X', 'HLA-A*01:01:01:01'], 'seqnames are correct'; |
| 45 |
|
| 46 |
## test chr names containing ':' |
| 47 |
# |
| 48 |
ok $iter = $tbx->query_full('HLA-A*01:01:01:01',1,10), "can query a region with ':' in chr"; |
| 49 |
ok $row = $iter->next, 'can get a value from the iterator'; |
| 50 |
is $row, "HLA-A*01:01:01:01\t1\t500\t0.65", "row value is correct with ':' in chr"; |
| 51 |
|
| 52 |
ok $iter = $tbx->query_full('HLA-A*01:01:01:01',1,), "can query a region with ':' in chr, no end"; |
| 53 |
ok $row = $iter->next, 'can get a value from the iterator'; |
| 54 |
is $row, "HLA-A*01:01:01:01\t1\t500\t0.65", "row value is correct with ':' in chr, no end"; |
| 55 |
|
| 56 |
ok $iter = $tbx->query_full('HLA-A*01:01:01:01'), "can query a region with ':' in chr, no coord"; |
| 57 |
ok $row = $iter->next, 'can get a value from the iterator'; |
| 58 |
is $row, "HLA-A*01:01:01:01\t1\t500\t0.65", "row value is correct with ':' in chr, no coord"; |
| 59 |
# |
| 60 |
## end strange chr name testing |
| 61 |
|
| 62 |
$iter = $tbx->query("fake"); |
| 63 |
ok(!$iter, 'querying non existent chrom'); |
| 64 |
$tbx->close; |
| 65 |
|
| 66 |
#More in depth header tests |
| 67 |
$test_file = $Bin . '/data/data.vcf.gz'; |
| 68 |
$tbx = Bio::DB::HTS::Tabix->new( filename => $test_file, warnings => 0 ); |
| 69 |
@ha = $tbx->header_array ; |
| 70 |
ok( $ha[0], "##fileformat=VCFv4.2" ) ; |
| 71 |
ok( $ha[5], "##reference=human_b36_both.fasta" ) ; |
| 72 |
$tbx->close; |
| 73 |
|
| 74 |
done_testing; |