Skip to content

Commit 2808eb2

Browse files
committed
Remove duplicates from the allele name completion
If there is a matching existing allele and a matching local allele with the same name, description and type remove the local version from the completions. Refs #2758
1 parent 83454e0 commit 2808eb2

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

lib/Canto/Curs/ServiceUtils.pm

+25-12
Original file line numberDiff line numberDiff line change
@@ -894,22 +894,13 @@ sub _get_alleles_name_complete
894894
$query->{name} = { -like => $search_string . '%' };
895895
}
896896

897-
my $allele_rs = $curs_schema->resultset('Allele')
898-
->search($query,
899-
{
900-
join => 'gene',
901-
# only return alleles that are part of a genotype
902-
where => \"me.allele_id IN (SELECT allele FROM allele_genotype)",
903-
});
904-
my @res = map {
905-
$self->_allele_details_hash($_);
906-
} $allele_rs->all();
897+
my $max_results = 15;
907898

908899
my $allele_lookup = $self->allele_lookup();
909900

910-
my $max_results = 15;
901+
my @res = ();
911902

912-
if (@res < $max_results && $allele_lookup) {
903+
if ($allele_lookup) {
913904
my $lookup_res = $allele_lookup->lookup(gene_primary_identifier =>
914905
$gene_primary_identifier,
915906
search_string => $search_string);
@@ -921,6 +912,28 @@ sub _get_alleles_name_complete
921912
}
922913
}
923914

915+
my $allele_rs = $curs_schema->resultset('Allele')
916+
->search($query,
917+
{
918+
join => 'gene',
919+
# only return alleles that are part of a genotype
920+
where => \"me.allele_id IN (SELECT allele FROM allele_genotype)",
921+
});
922+
my @local_res =
923+
map {
924+
$self->_allele_details_hash($_);
925+
} $allele_rs->all();
926+
927+
for my $local_allele (@local_res) {
928+
if (!grep {
929+
safe_equals($local_allele->{name}, $_->{name}) &&
930+
safe_equals($local_allele->{type}, $_->{type}) &&
931+
safe_equals($local_allele->{description}, $_->{description});
932+
} @res) {
933+
push @res, $local_allele;
934+
}
935+
}
936+
924937
return @res;
925938
}
926939

0 commit comments

Comments
 (0)