Skip to content

Commit

Permalink
Source commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrueda committed Aug 7, 2024
1 parent 264ef71 commit 79ccf7b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/Pheno/Ranker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ sub run {
"Sorry, <$target_file> does not contain primary_key <$primary_key>. Are you using the right config file?\n"
unless exists $tar_data->{$primary_key};

# Re-structure interpretations if PXF
restructure_pxf_interpretations($tar_data, $self);

# We store {primary_key} as a variable as it might be deleted from $tar_data (--exclude-terms id)
my $tar_data_id = $tar_data->{$primary_key};

Expand All @@ -479,9 +482,6 @@ sub run {
)
};

# Re-structure interpretations if PXF
restructure_pxf_interpretations($tar_data, $self);

# *** IMPORTANT ***
# The target binary is created from matches to $glob_hash
# Thus, it does not include variables ONLY present in TARGET
Expand Down
35 changes: 30 additions & 5 deletions lib/Pheno/Ranker/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use List::Util qw(any);
use Hash::Util qw(lock_hash);
use YAML::XS qw(LoadFile DumpFile);
use JSON::XS;
#use Data::Dumper;

#use Sort::Naturally qw(nsort);
use Exporter 'import';
Expand Down Expand Up @@ -350,9 +351,14 @@ sub restructure_pxf_interpretations {
# Premature return if the format is not 'PXF'
return unless $self->{format} eq 'PXF';

# Premature return if "interpretations" is excluded
return if (grep { $_ eq 'interpretations' } @{ $self->{exclude_terms} });

say "Restructuring <interpretations> in PXFs..." if defined $self->{verbose};

# Function to restructure individual interpretation
my $restructure_interpretation = sub {
my $interpretation = shift;
my $interpretation = shift;
my $disease_id = $interpretation->{diagnosis}{disease}{id};
my $new_interpretation = {
progressStatus => $interpretation->{progressStatus},
Expand All @@ -366,17 +372,35 @@ sub restructure_pxf_interpretations {
my $interpretation_data;

if ( exists $genomic_interpretation->{variantInterpretation} ) {
$gene_id = $genomic_interpretation->{variantInterpretation}{variationDescriptor}{geneContext}{valueId};
$interpretation_data =
my $variant_interpretation =
$genomic_interpretation->{variantInterpretation};

# Check if geneContext with valueId exists
if (
exists $variant_interpretation->{variationDescriptor}
{geneContext}{valueId} )
{
$gene_id = $variant_interpretation->{variationDescriptor}
{geneContext}{valueId};
}

# Check if id within variationDescriptor exists as an alternative
elsif (
exists $variant_interpretation->{variationDescriptor}{id} )
{
$gene_id =
$variant_interpretation->{variationDescriptor}{id};
}

$interpretation_data = $variant_interpretation;
}
elsif ( exists $genomic_interpretation->{geneDescriptor} ) {
$gene_id = $genomic_interpretation->{geneDescriptor}{valueId};
$interpretation_data =
$genomic_interpretation->{geneDescriptor};
}

$new_interpretation->{genomicInterpretations}->{$gene_id} = {
$new_interpretation->{genomicInterpretations}{$gene_id} = {
interpretationStatus =>
$genomic_interpretation->{interpretationStatus},
(
Expand All @@ -398,7 +422,8 @@ sub restructure_pxf_interpretations {
my $new_data = {};

foreach my $interpretation ( @{ $data->{interpretations} } ) {
my ( $disease_id, $new_interpretation ) = $restructure_interpretation->($interpretation);
my ( $disease_id, $new_interpretation ) =
$restructure_interpretation->($interpretation);
$new_data->{$disease_id} = $new_interpretation;
}

Expand Down
2 changes: 1 addition & 1 deletion t/cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ SKIP: {
my $input_file = catfile( 't', 'interpretations_pxf.json' );

# The reference file to compare the output with
my $reference_file = catfile( 't', 'matrix_interpretations_pxf.txt' );
my $reference_file = catfile( 't', 'matrix_ref_interpretations_pxf.txt' );

# The generated output file
my ( undef, $tmp_file ) =
Expand Down
19 changes: 19 additions & 0 deletions t/interpretations_pxf.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@
"valueId": "HGNC:12345",
"symbol": "GENE1"
}
},
{
"subjectOrBiosampleId": "Subject_2",
"interpretationStatus": "CAUSATIVE",
"variantInterpretation": {
"variationDescriptor": {
"id": "var_vUsarphuwufsiYwRzWVTDjIRF",
"label": "telomeric 11q deletion",
"moleculeContext": "genomic",
"structuralType": {
"id": "SO:1000029",
"label": "chromosomal_deletion"
},
"allelicState": {
"id": "GENO:0000135",
"label": "heterozygous"
}
}
}
}
]
}
Expand Down
3 changes: 0 additions & 3 deletions t/matrix_interpretations_pxf.txt

This file was deleted.

3 changes: 3 additions & 0 deletions t/matrix_ref_interpretations_pxf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sample_1 Sample_2
Sample_1 0 15
Sample_2 15 0

0 comments on commit 79ccf7b

Please sign in to comment.