Debian Codegraph @

t/02faidx.t

raw
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
16 #########################
17
18 use strict;
19 use warnings;
20 use FindBin '$Bin';
21 use lib "$Bin/../lib", "$Bin/../blib/lib", "$Bin/../blib/arch";
22 use Test::More tests => 15 ;
23
24 #########################
25
26 BEGIN { use_ok('Bio::DB::HTS') } ;
27 ok(1) ;
28
29 BEGIN { use_ok('Bio::DB::HTS::Faidx') } ;
30 ok(1) ;
31
32 my $fasta = "$Bin/data/Saccharomyces_cerevisiae.R64-1-1.dna.chromosome.I.fa.gz" ;
33 my $location = "I:1-100" ;
34 my $index = Bio::DB::HTS::Faidx->new($fasta);
35 ok($index) ;
36
37 my $seq = "" ;
38 my $length = 0 ;
39 ($seq, $length) = $index->get_sequence($location);
40 ok($seq eq
41 'CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTG');
42 ok($length eq 100);
43
44
45 my @seq_ids = $index->get_all_sequence_ids();
46 ok($seq_ids[0] eq 'I') ;
47
48 $seq = $index->get_sequence_no_length($location);
49 ok($seq eq
50 'CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTG');
51
52
53 $seq = "" ;
54 $length = 0 ;
55 ($seq, $length) = $index->get_sequence2("I",1,99);
56 ok($seq eq
57 'CACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTG');
58 ok($length eq 99);
59
60
61 $seq = "" ;
62 $length = 0 ;
63 $seq = $index->get_sequence2_no_length("I",1,99);
64 ok($seq eq
65 'CACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTG');
66
67
68
69 $length = $index->length('I');
70 note $length ;
71 ok($length eq 230218, "length of I");
72
73 my $has_seq = $index->has_sequence('I');
74 ok($has_seq eq 1, "has sequence I");
75
76 $has_seq = $index->has_sequence('II');
77 ok($has_seq eq 0, "Does not have sequence II");