Skip to content

Commit

Permalink
Merge pull request #846 from nerdstrike/fix_merged_lane_sort_order
Browse files Browse the repository at this point in the history
QC View sorting order to put merged lanes before unmerged.
  • Loading branch information
mgcam authored Nov 30, 2023
2 parents aa2237b + 2c81159 commit eba732d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
23 changes: 20 additions & 3 deletions lib/npg_qc/autoqc/role/rpt_key.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ operation on the list. A single hash reference is returned.
'id_run' => '1',
'position' => '2-3',
'tag_index' => '3'
};
};
=cut
sub rpt_list2one_hash {
Expand Down Expand Up @@ -161,10 +161,26 @@ sub _compare_rpt_keys_zero_last {
my $b_map = __PACKAGE__->rpt_list2one_hash($b);

return $a_map->{'id_run'} cmp $b_map->{'id_run'} ||
$a_map->{'position'} cmp $b_map->{'position'} ||
_compare_position($a_map->{'position'}, $b_map->{'position'}) ||
_compare_tags_zero_last($a_map, $b_map);
}

sub _compare_position {## no critic (RequireArgUnpacking)
# Look for - indicating merged positions. Put merges first
my $a_merged = $_[0] =~ /[-]/xms;
my $b_merged = $_[1] =~ /[-]/xms;

if ($a_merged && $b_merged) {
return $_[0] cmp $_[1];
} elsif ($a_merged) {
return $LESS;
} elsif ($b_merged) {
return $MORE;
} else {
return $_[0] <=> $_[1]; # position is purely numeric
}
}

sub _compare_tags_zero_last {## no critic (RequireArgUnpacking)
if ( !exists $_[0]->{'tag_index'} && !exists $_[1]->{'tag_index'} ) { return $EQUAL; }
elsif ( exists $_[0]->{'tag_index'} && exists $_[1]->{'tag_index'} ) {
Expand Down Expand Up @@ -256,10 +272,11 @@ __END__
=head1 AUTHOR
Marina Gourtovaia E<lt>[email protected]E<gt>
Kieron Taylor E<lt>[email protected]E<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2018 GRL
Copyright (C) 2018, 2023 GRL
This file is part of NPG.
Expand Down
33 changes: 32 additions & 1 deletion t/60-autoqc-role-rpt_key.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 3;
use Test::More tests => 5;

use_ok('npg_qc::autoqc::role::rpt_key');

Expand All @@ -18,4 +18,35 @@ subtest 'first rpt key of the rpt lists' => sub {
is (npg_qc::autoqc::role::rpt_key->rpt_list2first_rpt_key('5:1:2:5:3:4'), '5:1:2');
};

subtest 'Unpacking composite RPT strings' => sub {
plan tests => 1;
is_deeply(
npg_qc::autoqc::role::rpt_key->rpt_list2one_hash('1:1:1;1:2:1'),
{
id_run => '1',
position => '1-2',
tag_index => '1'
},
'Composite RPT is turned into a combined object'
);
};

subtest 'Sorting of lane positions and tag indexes in the /checks/runs library lane view' => sub {
plan tests => 7;

my $rpt_tests = [
[['1:1:888'], ['1:1:888'], 'One in, one out'],
[['1:1:0', '1:1:1', '1:1:2'], ['1:1:1', '1:1:2', '1:1:0'], 'All-numeric RPTs are sorted, tag 0 last'],
[['1:20:10', '1:1:9', '1:2:8'], ['1:1:9', '1:2:8', '1:20:10'], 'Positions are sorted numerically over tags'],
[['1:5:1', '2:1:0', '3:8:888'], ['1:5:1', '2:1:0', '3:8:888'], 'id_run always wins'],
[['1:1:0', '1:1:1;1:2:1;1:3:1'], ['1:1:1;1:2:1;1:3:1', '1:1:0'], 'Position ranges are sorted first'],
[['1:1:1;1:2:1;1:3:1', '1:1:0'], ['1:1:1;1:2:1;1:3:1', '1:1:0'], 'Position ranges are sorted first'],
[['1:1:0', '1:1:1;1:2:1', '1:1:888'], ['1:1:1;1:2:1', '1:1:888', '1:1:0'], 'Merge first, then high tag, then zero']
];

foreach my $rpt (@$rpt_tests) {
is_deeply([npg_qc::autoqc::role::rpt_key->sort_rpt_keys_zero_last($rpt->[0])], $rpt->[1], $rpt->[2]);
}
};

1;

0 comments on commit eba732d

Please sign in to comment.