my
$class
=
'Bio::JBrowse::Store::NCList::LazyNCList'
;
use_ok(
$class
);
my
$lazyClass
= 2;
my
%nclist_output
;
my
$list
=
$class
->new(
Bio::JBrowse::Store::NCList::ArrayRepr->new([
{
attributes
=> [
qw( start end strand id name subfeatures )
],
isArrayAttr
=> {
'subfeatures'
=> 1 },
},
{
attributes
=> [
qw( start end strand type )
] },
{
attributes
=> [
qw( start end chunk )
],
isArrayAttr
=> {
'sublist'
=> 1}
},
]
),
$lazyClass
,
sub
{
my
(
$start
,
$end
,
$id
) =
@_
;
[
$lazyClass
,
$start
,
$end
,
$id
];
},
sub
{
$nclist_output
{
$_
[0] }
},
sub
{ 1 +
length
encode_json(
$_
[0] ) },
sub
{
my
(
$toStore
,
$chunkId
) =
@_
;
$nclist_output
{
$chunkId
} =
$toStore
;
},
10_000,
);
my
$features
= decode_json( slurp(
't/data/tomato_features.json'
) );
diag
"loaded "
.
@$features
.
" test features"
;
my
$features_clone
= dclone
$features
;
$list
->addSorted(
$_
)
for
@$features
;
$list
->finish;
{
local
$TODO
=
'not causing problems right now, but needs to be fixed'
;
is_deeply(
$features
,
$features_clone
,
'LazyNCList did not modify the features it was passed'
);
}
my
$correct_nclist
= decode_json( slurp(
't/data/tomato_features_nclist_with_chunksize_10000.json'
) );
is_deeply(
\
%nclist_output
,
$correct_nclist
,
'got the right output chunks'
);
my
$oc_count
= 0;
$list
->overlapCallback(
$list
->minStart,
$list
->maxEnd,
sub
{
$oc_count
++ } );
is(
$oc_count
,
scalar
@$features
,
'overlapCallback hit all features'
);
done_testing;
sub
slurp {
open
my
$f
,
'<'
,
$_
[0];
local
$/; <
$f
> }
sub
find_missing_features {
my
(
$features
,
$nclist_chunks
) =
@_
;
my
$keyfunc
=
sub
{
local
$Data::Dumper::Terse
= 1;
Data::Dumper::Dumper(
@_
);
};
my
%original_features
;
my
%output_features
;
for
(
@$features
) {
my
$key
=
$keyfunc
->(
$_
);
$original_features
{
$key
} = 1;
}
Data::Visitor::Callback->new(
array
=>
sub
{
my
(
$v
,
$array
) =
@_
;
my
$key
=
$keyfunc
->(
$array
);
if
(
$array
->[0] == 0
&& (
@$array
== 7 ||
@$array
== 8)
&&
ref
$array
->[6] eq
'ARRAY'
) {
my
$key
=
$keyfunc
->(
$array
);
$output_features
{
$key
}++;
$v
->visit(
$array
->[7])
if
$array
->[7] &&
ref
$array
->[7] eq
'HASH'
;
}
else
{
$v
->visit(
$_
)
for
@$array
;
}
},
)->visit(
$nclist_chunks
);
is_deeply( \
%original_features
, \
%output_features
);
my
$irregular_count
= 0;
for
my
$key
(
keys
%original_features
) {
my
$count
=
$output_features
{
$key
} || 0;
next
if
$count
== 1;
$irregular_count
++;
diag
"PROBLEM: feature seen $count time(s) in LazyNCList output:\n$key\n"
;
}
is(
$irregular_count
, 0,
"$irregular_count total irregular features"
);
return
$irregular_count
;
}