Skip to content

Commit

Permalink
Set the display name for Metagenotypes dynamically
Browse files Browse the repository at this point in the history
The metagenotype ID is stored as the range value in extensions.  The
rangeDisplayName is now calculated from the ID as needed.

Refs #2505
  • Loading branch information
kimrutherford committed Apr 8, 2022
1 parent 72c82ee commit eccd05c
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions lib/Canto/Curs/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ use Moose;
use Clone qw(clone);
use JSON;

use Scalar::Util qw(looks_like_number);

use Canto::Curs::GeneProxy;
use Canto::Curs::ConditionUtil;
use Canto::Curs::MetadataStorer;
Expand Down Expand Up @@ -221,10 +223,12 @@ sub _make_metagenotype_details
$ontology_lookup, $organism_lookup);

my $metagenotype_display_name =
$pathogen_genotype_details{organism}->{full_name} . ' ' .
$pathogen_genotype_details{genotype_display_name} . ' / ' .
$host_genotype_details{organism}->{full_name} . ' ' .
$host_genotype_details{genotype_display_name};
$pathogen_genotype_details{genotype_display_name} . ' ' .
$pathogen_genotype_details{organism}->{full_name} . ' (' .
$pathogen_genotype_details{strain_name} . ') / ' .
$host_genotype_details{genotype_display_name} . ' ' .
$host_genotype_details{organism}->{full_name} . ' (' .
$host_genotype_details{strain_name} . ')';

return (
pathogen_genotype => \%pathogen_genotype_details,
Expand All @@ -237,6 +241,39 @@ sub _make_metagenotype_details
);
}

sub _make_extension
{
my $config = shift;
my $schema = shift;
my $ontology_lookup = shift;
my $organism_lookup = shift;
my $extension = shift // [];

for my $and_group (@$extension) {
for my $ext_part (@$and_group) {
if ($ext_part->{rangeType} &&
$ext_part->{rangeType} eq 'Metagenotype') {
my $metagenotype_id = $ext_part->{rangeValue};
if (looks_like_number($metagenotype_id)) {
my $rs = $schema->resultset('Metagenotype')
->search({ metagenotype_id => $metagenotype_id });
my $metagenotype = $rs->first();
if ($metagenotype) {
my %metagenotype_details =
_make_metagenotype_details($schema, $metagenotype, $config,
$ontology_lookup, $organism_lookup);
$ext_part->{rangeDisplayName} = $metagenotype_details{metagenotype_display_name};
next;
}
}
$ext_part->{rangeDisplayName} = 'Unknown Metagenotype';
}
}
}

return $extension;
}

=head2 make_ontology_annotation
Usage : my $hash = Canto::Curs::Utils::make_ontology_annotation(...);
Expand Down Expand Up @@ -400,6 +437,10 @@ sub make_ontology_annotation
my $completed = defined $evidence_code &&
(!$needs_with || defined $with_gene_identifier);

my $extension = _make_extension($config, $schema,
$ontology_lookup, $organism_lookup,
$data->{extension});

my $ret = {
%gene_details,
%genotype_details,
Expand All @@ -426,7 +467,7 @@ sub make_ontology_annotation
with_gene_id => $with_gene_id,
taxonid => $taxonid,
completed => $completed,
extension => $data->{extension} || [],
extension => $extension,
is_obsolete_term => $is_obsolete_term,
curator => $curator,
status => $annotation->status(),
Expand Down

0 comments on commit eccd05c

Please sign in to comment.