| 1 | package Pheno::Ranker::Compare::Alignment; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | our @EXPORT_OK = qw(create_alignment recreate_array); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 82 | ▶ | sub create_alignment { | ||||||||||||||||||||||||||
|
Subroutine
create_alignment: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # NB: The alignment will use the weighted string | ||||||||||||||||||||||||||||
| 12 | 82 | my $arg = shift; | |||||||||||||||||||||||||||
| 13 | 82 | my $ref_key = $arg->{ref_key}; | |||||||||||||||||||||||||||
| 14 | 82 | my $binary_string1 = $arg->{ref_str_weighted}; | |||||||||||||||||||||||||||
| 15 | 82 | my $binary_string2 = $arg->{tar_str_weighted}; | |||||||||||||||||||||||||||
| 16 | 82 | my $sorted_keys_glob_hash = $arg->{sorted_keys_glob_hash}; | |||||||||||||||||||||||||||
| 17 | 82 | my $labels = $arg->{labels}; | |||||||||||||||||||||||||||
| 18 | 82 | my $glob_hash = $arg->{glob_hash}; | |||||||||||||||||||||||||||
| 19 | 82 | my $length1 = length($binary_string1); | |||||||||||||||||||||||||||
| 20 | 82 | my $length2 = length($binary_string2); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Check that l1 = l2 | ||||||||||||||||||||||||||||
| 23 | 82 | ▶ | die "The binary strings must have the same length" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | if ( $length1 != $length2 ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Expand array to have weights as N-elements | ||||||||||||||||||||||||||||
| 27 | 82 | my $recreated_array = recreate_array( $glob_hash, $sorted_keys_glob_hash ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Initialize some variables | ||||||||||||||||||||||||||||
| 30 | 82 | my $out_ascii = "REF -- TAR\n"; | |||||||||||||||||||||||||||
| 31 | 82 | my @out_csv; | |||||||||||||||||||||||||||
| 32 | 82 | my $cum_distance = 0; | |||||||||||||||||||||||||||
| 33 | 82 | my $n_00 = 0; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # For loop with 2 variables | ||||||||||||||||||||||||||||
| 36 | # i index for weighted | ||||||||||||||||||||||||||||
| 37 | # j the number of variables | ||||||||||||||||||||||||||||
| 38 | 82 | my ( $i, $j ) = ( 0, 0 ); | |||||||||||||||||||||||||||
| 39 | 82 | ▶ | for ( $i = 0 ; $i < $length1 ; $i++, $j++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Load key and value | ||||||||||||||||||||||||||||
| 42 | 11468 | my $key = $recreated_array->[$i]; | |||||||||||||||||||||||||||
| 43 | 11468 | my $val = sprintf( "%3d", $glob_hash->{$key} ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # We have to keep track with $j | ||||||||||||||||||||||||||||
| 46 | 11468 | my $sorted_key = $sorted_keys_glob_hash->[$j]; | |||||||||||||||||||||||||||
| 47 | 11468 | my $label = $labels->[$j]; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Load chars | ||||||||||||||||||||||||||||
| 50 | 11468 | my $char1 = substr( $binary_string1, $i, 1 ); | |||||||||||||||||||||||||||
| 51 | 11468 | my $char2 = substr( $binary_string2, $i, 1 ); | |||||||||||||||||||||||||||
| 52 | 11468 | ▶ | $n_00++ if ( $char1 == 0 && $char2 == 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char1 == 0 and $char2 == 0
MC/DC100%2/2
$char1 == 0 and $char2 == 0
$char1 == 0
$char2 == 0
Truth table100%3/3
A and B
A= $char1 == 0B= $char2 == 0
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Correct $i index by adding weights | ||||||||||||||||||||||||||||
| 55 | 11468 | $i = $i + $glob_hash->{$key} - 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Load metrics | ||||||||||||||||||||||||||||
| 58 | 11468 | ▶ | $cum_distance += $glob_hash->{$key} if $char1 ne $char2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 11468 | my $cum_distance_pretty = sprintf( "%3d", $cum_distance ); | |||||||||||||||||||||||||||
| 60 | 11468 | ▶ | my $distance = $char1 eq $char2 ? 0 : $glob_hash->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 11468 | my $distance_pretty = sprintf( "%3d", $distance ); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # w = weight, d = distance, cd = cumul distance | ||||||||||||||||||||||||||||
| 64 | 11468 | my %format = ( | |||||||||||||||||||||||||||
| 65 | '11' => '-----', | ||||||||||||||||||||||||||||
| 66 | '10' => 'xxx--', | ||||||||||||||||||||||||||||
| 67 | '01' => '--xxx', | ||||||||||||||||||||||||||||
| 68 | '00' => ' ' | ||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||
| 70 | 11468 | $out_ascii .= | |||||||||||||||||||||||||||
| 71 | qq/$char1 $format{ $char1 . $char2 } $char2 | (w:$val|d:$distance_pretty|cd:$cum_distance_pretty|) $sorted_key ($label)\n/; | ||||||||||||||||||||||||||||
| 72 | 11468 | push @out_csv, | |||||||||||||||||||||||||||
| 73 | qq/$ref_key;$char1;$format{ $char1 . $char2 };$char2;$glob_hash->{$key};$distance;$sorted_key;$label/; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #REF(107:week_0_arm_1);indicator;TAR(125:week_0_arm_1);weight;hamming-distance;json-path | ||||||||||||||||||||||||||||
| 76 | #0;;0;1;0;diseases.ageOfOnset.ageRange.end.iso8601duration.P16Y | ||||||||||||||||||||||||||||
| 77 | #0;;0;1;0;diseases.ageOfOnset.ageRange.end.iso8601duration.P24Y | ||||||||||||||||||||||||||||
| 78 | #1;-----;1;1;0;diseases.ageOfOnset.ageRange.end.iso8601duration.P39Y | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 82 | return $n_00, \$out_ascii, \@out_csv; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 82 | ▶ | sub recreate_array { | ||||||||||||||||||||||||||
|
Subroutine
recreate_array: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 82 | my ( $glob_hash, $sorted_keys_glob_hash ) = @_; | |||||||||||||||||||||||||||
| 85 | 82 | my @recreated_array; | |||||||||||||||||||||||||||
| 86 | 82 | foreach my $key (@$sorted_keys_glob_hash) { | |||||||||||||||||||||||||||
| 87 | 11468 | ▶ | for ( my $i = 0 ; $i < $glob_hash->{$key} ; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 11756 | push @recreated_array, $key; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 82 | return \@recreated_array; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 8 | 1; | |||||||||||||||||||||||||||