Skip to content

Commit

Permalink
Merge pull request #884 from Clinical-Genomics/feature/pli_file
Browse files Browse the repository at this point in the history
Feature/pli file
  • Loading branch information
henrikstranneheim committed Jul 14, 2019
2 parents 2c29aae + d3a0707 commit ede2a1a
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 57 deletions.
96 changes: 96 additions & 0 deletions lib/MIP/File/Format/Pli.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package MIP::File::Format::Pli;

use 5.026;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
use strict;
use utf8;
use warnings;
use warnings qw{ FATAL utf8 };

## CPANM
use autodie qw{ :all };
use Readonly;

## MIPs lib/
use MIP::Constants qw{ $COLON $NEWLINE $SPACE $TAB };

BEGIN {
require Exporter;
use base qw{ Exporter };

# Set the version for version checking
our $VERSION = 1.00;

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{ load_pli_file };
}

sub load_pli_file {

## Function : Load plI file values
## Returns :
## Arguments: $infile_path => Infile path
## : $log => Log object
## : $pli_score_href => Pli scores hash

my ($arg_href) = @_;

## Flatten argument(s)
my $infile_path;
my $log;
my $pli_score_href;

my $tmpl = {
infile_path => {
defined => 1,
required => 1,
store => \$infile_path,
strict_type => 1,
},
log => {
defined => 1,
required => 1,
store => \$log,
},
pli_score_href => {
default => {},
defined => 1,
required => 1,
store => \$pli_score_href,
strict_type => 1,
},
};

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

my $FILEHANDLE = IO::Handle->new();

open $FILEHANDLE, q{<}, $infile_path
or $log->logdie( q{Cannot open } . $infile_path . $COLON . $OS_ERROR, $NEWLINE );

LINE:
while (<$FILEHANDLE>) {

chomp;

## Unpack line
my $line = $_;

## Get hgnc symbol and pli score
my ( $hgnc_symbol, $pli_score ) = split $TAB, $line;

## Skip header
next LINE if ( $pli_score eq q{pLI} );

## Set rounded pli score to hash
$pli_score_href->{$hgnc_symbol} = sprintf q{%.2f}, $pli_score;
}
close $FILEHANDLE;
return 1;
}

1;
2 changes: 2 additions & 0 deletions t/data/references/gnomad_pli_per_gene_-_r2.1.1-.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HGNC_SYMBOL pLI
ADK 0.91234
87 changes: 87 additions & 0 deletions t/load_pli_file.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env perl

use 5.026;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ dirname };
use File::Spec::Functions qw{ catdir catfile };
use FindBin qw{ $Bin };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
use Test::More;
use utf8;
use warnings qw{ FATAL utf8 };

## CPANM
use autodie qw { :all };
use Modern::Perl qw{ 2017 };
use Readonly;

## MIPs lib/
use lib catdir( dirname($Bin), q{lib} );
use MIP::Constants qw{ $COMMA $SPACE };
use MIP::Test::Fixtures qw{ test_log test_standard_cli };

my $VERBOSE = 1;
our $VERSION = 1.00;

$VERBOSE = test_standard_cli(
{
verbose => $VERBOSE,
version => $VERSION,
}
);

BEGIN {

use MIP::Test::Fixtures qw{ test_import };

### Check all internal dependency modules and imports
## Modules with import
my %perl_module = (
q{MIP::File::Format::Pli} => [qw{ load_pli_file }],
q{MIP::Test::Fixtures} => [qw{ test_log test_standard_cli }],
);

test_import( { perl_module_href => \%perl_module, } );
}

use MIP::File::Format::Pli qw{ load_pli_file };

diag( q{Test load_pli_file from Pli.pm v}
. $MIP::File::Format::Pli::VERSION
. $COMMA
. $SPACE . q{Perl}
. $SPACE
. $PERL_VERSION
. $SPACE
. $EXECUTABLE_NAME );

## Constants
Readonly my $ADK_PLI => 0.91;

my $log = test_log( {} );

## Given a pli file
my $pli_values_file_path =
catfile( $Bin, qw{ data references gnomad_pli_per_gene_-_r2.1.1-.txt } );
my %pli_score;

my $is_ok = load_pli_file(
{
infile_path => $pli_values_file_path,
log => $log,
pli_score_href => \%pli_score,
}
);

my %expected_pli_score = ( ADK => $ADK_PLI );

## Then load plI file should return true
ok( $is_ok, q{Loaded plI file} );

## Then pli_score hash should be loaded with hgnc_symbol and corresponding pli score
is_deeply( \%pli_score, \%expected_pli_score, q{Loaded plI data into hash} );

done_testing();
59 changes: 2 additions & 57 deletions vcfparser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use MIP::Check::Modules qw{ check_perl_modules };
use MIP::Constants qw{ %ANALYSIS $COLON $COMMA $NEWLINE $SPACE $TAB };
use MIP::File::Format::Feature_file qw{ read_feature_file };
use MIP::File::Format::Pli qw{ load_pli_file };
use MIP::Log::MIP_log4perl qw{ initiate_logger };
use MIP::Script::Utils qw{ help };
use MIP::Vcfparser qw{ define_select_data_headers define_snpeff_annotations };
Expand Down Expand Up @@ -171,6 +172,7 @@ BEGIN
load_pli_file(
{
infile_path => $pli_values_file_path,
log => $log,
pli_score_href => \%pli_score,
}
);
Expand Down Expand Up @@ -380,63 +382,6 @@ sub define_consequence_severity {
return %consequence_severity;
}

sub load_pli_file {

## Function : Load plI file values
## Returns :
## Arguments: $infile_path => Infile path
## : $pli_score_href => Pli scores hash

my ($arg_href) = @_;

## Flatten argument(s)
my $infile_path;
my $pli_score_href;

my $tmpl = {
infile_path => {
defined => 1,
required => 1,
store => \$infile_path,
strict_type => 1,
},
pli_score_href => {
default => {},
defined => 1,
required => 1,
store => \$pli_score_href,
strict_type => 1,
},
};

check( $tmpl, $arg_href, 1 ) or die q{Could not parse arguments!};

my $FILEHANDLE = IO::Handle->new();

open $FILEHANDLE, q{<}, $infile_path
or $log->logdie( q{Cannot open } . $infile_path . $COLON . $!, $NEWLINE );

LINE:
while (<$FILEHANDLE>) {

chomp;

## Unpack line
my $line = $_;

## Get hgnc symbol and pli score
my ( $hgnc_symbol, $pli_score ) = split $TAB, $line;

## Skip header
next if ( $pli_score eq q{pLI} );

## Set rounded pli score to hash
$pli_score_href->{$hgnc_symbol} = sprintf( "%.2f", $pli_score );
}
close $FILEHANDLE;
return;
}

sub read_infile_vcf {

##read_infile_vcf
Expand Down

0 comments on commit ede2a1a

Please sign in to comment.