-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #884 from Clinical-Genomics/feature/pli_file
Feature/pli file
- Loading branch information
Showing
4 changed files
with
187 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
HGNC_SYMBOL pLI | ||
ADK 0.91234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters