| 1 | package ISS::AH::Predictor; | |||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use v5.10; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 6 | ||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util qw(looks_like_number); | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | |||||||||||||||||||||||||||||||||
| 10 | ||||||||||||||||||||||||||||||||||
| 11 | ISS::AH::Predictor - Provides prediction models for adult height (AH) in patients with idiopathic short stature (ISS). | |||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||
| 13 | =cut | |||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = '0.1.0'; | ||||||||||||||||||||||||||||||||
| 16 | ||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | |||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||
| 20 | use ISS::AH::Predictor; | |||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||
| 22 | =head1 ATTRIBUTES | |||||||||||||||||||||||||||||||||
| 23 | ||||||||||||||||||||||||||||||||||
| 24 | =head2 MODELS | |||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||
| 26 | This attribute contains the default models and parameters, estimated by Blum et al. | |||||||||||||||||||||||||||||||||
| 27 | ||||||||||||||||||||||||||||||||||
| 28 | my $models = ISS::AH::Predictor::MODELS; | |||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||
| 30 | # each element of the $models arrayref is an arrayref with estimated parameters of one model | |||||||||||||||||||||||||||||||||
| 31 | $models->[0]->[0]; # first parameter (intercept) of the first model | |||||||||||||||||||||||||||||||||
| 32 | ||||||||||||||||||||||||||||||||||
| 33 | =cut | |||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use constant MODELS => [ | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 36 | [ 63.3339, -2.9595, 0.7256, 0.3173, undef, undef, -13.0399, 1.2695, -6.2213 ], | |||||||||||||||||||||||||||||||||
| 37 | [ 62.1795, -2.9892, 0.7328, 0.3442, undef, undef, -12.6821, undef, -6.3021 ], | |||||||||||||||||||||||||||||||||
| 38 | [ 50.3654, -2.6372, 0.6408, 0.3986, undef, undef, undef, undef, -5.9171 ], | |||||||||||||||||||||||||||||||||
| 39 | [ 80.3645, -3.4309, 0.8241, undef, 0.2242, undef, -15.1678, 1.2688, -10.2474 ], | |||||||||||||||||||||||||||||||||
| 40 | [ 83.4866, -3.4717, 0.8374, undef, 0.2234, undef, -14.7156, undef, -10.6257 ], | |||||||||||||||||||||||||||||||||
| 41 | [ 75.8792, -3.1944, 0.7581, undef, 0.2449, undef, undef, undef, -10.9519 ], | |||||||||||||||||||||||||||||||||
| 42 | [ 93.2475, -3.4020, 0.8239, undef, undef, 0.1203, -14.2739, 1.6156, -10.0340 ], | |||||||||||||||||||||||||||||||||
| 43 | [ 94.2381, -3.5784, 0.8759, undef, undef, 0.1348, -14.2476, undef, -10.5319 ], | |||||||||||||||||||||||||||||||||
| 44 | [ 84.3600, -3.2207, 0.7623, undef, undef, 0.1775, undef, undef, -10.8759 ], | |||||||||||||||||||||||||||||||||
| 45 | [ 110.8863, -4.1250, 0.9661, undef, undef, undef, -16.0541, undef, -10.4331 ], | |||||||||||||||||||||||||||||||||
| 46 | 2 | ]; | ||||||||||||||||||||||||||||||||
| 47 | ||||||||||||||||||||||||||||||||||
| 48 | =head2 PARAMETER_NAMES | |||||||||||||||||||||||||||||||||
| 49 | ||||||||||||||||||||||||||||||||||
| 50 | Hashref that contains the names of the model parameters for each variable index. | |||||||||||||||||||||||||||||||||
| 51 | ||||||||||||||||||||||||||||||||||
| 52 | =cut | |||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | use constant PARAMETER_NAMES => { | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 55 | 0 => 'intercept', | |||||||||||||||||||||||||||||||||
| 56 | 1 => 'age', | |||||||||||||||||||||||||||||||||
| 57 | 2 => 'body_height', | |||||||||||||||||||||||||||||||||
| 58 | 3 => 'target_height', | |||||||||||||||||||||||||||||||||
| 59 | 4 => 'mother_height', | |||||||||||||||||||||||||||||||||
| 60 | 5 => 'father_height', | |||||||||||||||||||||||||||||||||
| 61 | 6 => 'bone_age_per_age', | |||||||||||||||||||||||||||||||||
| 62 | 7 => 'birth_weight', | |||||||||||||||||||||||||||||||||
| 63 | 8 => 'sex', | |||||||||||||||||||||||||||||||||
| 64 | 2 | }; | ||||||||||||||||||||||||||||||||
| 65 | ||||||||||||||||||||||||||||||||||
| 66 | =head1 SUBROUTINES/METHODS | |||||||||||||||||||||||||||||||||
| 67 | ||||||||||||||||||||||||||||||||||
| 68 | =head2 predict | |||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||
| 70 | Provide a hash with properties of a subject to predict adult height (AH). | |||||||||||||||||||||||||||||||||
| 71 | You can also provide custom model parameters to overwrite the default once from Blum et al. | |||||||||||||||||||||||||||||||||
| 72 | ||||||||||||||||||||||||||||||||||
| 73 | my $ah = ISS::AH::Predictor::predict( | |||||||||||||||||||||||||||||||||
| 74 | age => ..., # years | |||||||||||||||||||||||||||||||||
| 75 | body_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 76 | target_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 77 | mother_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 78 | father_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 79 | bone_age => ..., # years | |||||||||||||||||||||||||||||||||
| 80 | birth_weight => ..., # kg | |||||||||||||||||||||||||||||||||
| 81 | sex => ..., # 'male' or 'female' | |||||||||||||||||||||||||||||||||
| 82 | models => [ ... ], | |||||||||||||||||||||||||||||||||
| 83 | ); | |||||||||||||||||||||||||||||||||
| 84 | ||||||||||||||||||||||||||||||||||
| 85 | =cut | |||||||||||||||||||||||||||||||||
| 86 | ||||||||||||||||||||||||||||||||||
| 87 | 2 | ▶ | sub predict { | |||||||||||||||||||||||||||||||
|
Subroutine
predict: called CC=6 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||
| 88 | 2 | my %params = _modify_params(@_); | ||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | my $model = get_model(%params) or return undef; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 90 | 1 | my $result = $model->[0]; # intercept | ||||||||||||||||||||||||||||||||
| 91 | ||||||||||||||||||||||||||||||||||
| 92 | 1 | for my $index (keys %{ PARAMETER_NAMES() }) { | ||||||||||||||||||||||||||||||||
| 93 | 9 | my $parameter_name = PARAMETER_NAMES->{$index}; | ||||||||||||||||||||||||||||||||
| 94 | 9 | ▶ | next if ($parameter_name eq 'intercept'); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | next unless (defined $model->[$index] and defined $params{$parameter_name}); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $model->[$index] and defined $params{$parameter_name}
MC/DC50%1/2
defined $model->[$index] and defined $params{$parameter_name}
defined $model->[$index]
defined $params{$parameter_name}
Truth table66%2/3
A and B
A= defined $model->[$index]B= defined $params{$parameter_name}
| ||||||||||||||||||||||||||||||||||
| 96 | 5 | $result += $model->[$index] * $params{$parameter_name}; | ||||||||||||||||||||||||||||||||
| 97 | } | |||||||||||||||||||||||||||||||||
| 98 | ||||||||||||||||||||||||||||||||||
| 99 | 1 | return $result; | ||||||||||||||||||||||||||||||||
| 100 | } | |||||||||||||||||||||||||||||||||
| 101 | ||||||||||||||||||||||||||||||||||
| 102 | =head2 get_model | |||||||||||||||||||||||||||||||||
| 103 | ||||||||||||||||||||||||||||||||||
| 104 | Returns an appropriate model with a set of parameters for the given subject properties. | |||||||||||||||||||||||||||||||||
| 105 | The returned model is determined by the amount of available parameters. | |||||||||||||||||||||||||||||||||
| 106 | You can also provide custom model parameters to overwrite the default once from Blum et al. | |||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||
| 108 | If no model is appropriate, the result is undef. | |||||||||||||||||||||||||||||||||
| 109 | If there are multiple matching models (with identical parameter count), the first one will be returned. | |||||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||||
| 111 | my $model = ISS::AH::Predictor::get_model( | |||||||||||||||||||||||||||||||||
| 112 | age => ..., # years | |||||||||||||||||||||||||||||||||
| 113 | body_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 114 | target_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 115 | mother_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 116 | father_height => ..., # cm | |||||||||||||||||||||||||||||||||
| 117 | bone_age => ..., # years | |||||||||||||||||||||||||||||||||
| 118 | birth_weight => ..., # kg | |||||||||||||||||||||||||||||||||
| 119 | sex => ..., # 'male' or 'female' | |||||||||||||||||||||||||||||||||
| 120 | models => [ ... ], | |||||||||||||||||||||||||||||||||
| 121 | ); | |||||||||||||||||||||||||||||||||
| 122 | ||||||||||||||||||||||||||||||||||
| 123 | =cut | |||||||||||||||||||||||||||||||||
| 124 | ||||||||||||||||||||||||||||||||||
| 125 | 6 | ▶ | sub get_model { | |||||||||||||||||||||||||||||||
|
Subroutine
get_model: called CC=12 SCAR=24.9
Pod
documented
| ||||||||||||||||||||||||||||||||||
| 126 | 6 | my %params = _modify_params(@_); | ||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | my $models = $params{models} || MODELS; | |||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'models'} || [[63.3339, -2.9595, 0.7256, 0.3173, undef, undef, -13.0399, 1.2695, -6.2213], [62.1795, -2.9892, 0.7328, 0.3442, undef, undef, -12.6821, undef, -6.3021], [50.3654, -2.6372, 0.6408, 0.3986, undef, undef, undef, undef, -5.9171], [80.3645, -3.4309, 0.8241, undef, 0.2242, undef, -15.1678, 1.2688, -10.2474], [83.4866, -3.4717, 0.8374, undef, 0.2234, undef, -14.7156, undef, -10.6257], [75.8792, -3.1944, 0.7581, undef, 0.2449, undef, undef, undef, -10.9519], [93.2475, -3.402, 0.8239, undef, undef, 0.1203, -14.2739, 1.6156, -10.034], [94.2381, -3.5784, 0.8759, undef, undef, 0.1348, -14.2476, undef, -10.5319], [84.36, -3.2207, 0.7623, undef, undef, 0.1775, undef, undef, -10.8759], [110.8863, -4.125, 0.9661, undef, undef, undef, -16.0541, undef, -10.4331]]
MC/DC100%1/1
$params{'models'} || [[63.3339, -2.9595, 0.7256, 0.3173, undef, undef, -13.0399, 1.2695, -6.2213], [62.1795, -2.9892, 0.7328, 0.3442, undef, undef, -12.6821, undef, -6.3021], [50.3654, -2.6372, 0.6408, 0.3986, undef, undef, undef, undef, -5.9171], [80.3645, -3.4309, 0.8241, undef, 0.2242, undef, -15.1678, 1.2688, -10.2474], [83.4866, -3.4717, 0.8374, undef, 0.2234, undef, -14.7156, undef, -10.6257], [75.8792, -3.1944, 0.7581, undef, 0.2449, undef, undef, undef, -10.9519], [93.2475, -3.402, 0.8239, undef, undef, 0.1203, -14.2739, 1.6156, -10.034], [94.2381, -3.5784, 0.8759, undef, undef, 0.1348, -14.2476, undef, -10.5319], [84.36, -3.2207, 0.7623, undef, undef, 0.1775, undef, undef, -10.8759], [110.8863, -4.125, 0.9661, undef, undef, undef, -16.0541, undef, -10.4331]]
$params{'models'}
Truth table100%2/2
A
A= $params{'models'}
| ||||||||||||||||||||||||||||||||||
| 128 | 6 | my $results = []; | ||||||||||||||||||||||||||||||||
| 129 | ||||||||||||||||||||||||||||||||||
| 130 | 6 | for my $model (@$models) { | ||||||||||||||||||||||||||||||||
| 131 | 41 | my $match = 1; | ||||||||||||||||||||||||||||||||
| 132 | 41 | for my $index (keys %{ PARAMETER_NAMES() }) { | ||||||||||||||||||||||||||||||||
| 133 | 112 | my $parameter_name = PARAMETER_NAMES->{$index}; | ||||||||||||||||||||||||||||||||
| 134 | 112 | ▶ | $match = 0 if (defined $model->[$index] and !looks_like_number($model->[$index])); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $model->[$index] and not &looks_like_number($model->[$index])
MC/DC0%0/2
defined $model->[$index] and not &looks_like_number($model->[$index])
defined $model->[$index]
not &looks_like_number($model->[$index])
Truth table66%2/3
A and not(B)
A= defined $model->[$index]B= not &looks_like_number($model->[$index])
| ||||||||||||||||||||||||||||||||||
| 135 | 112 | ▶ | next if ($parameter_name eq 'intercept'); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 136 | 102 | ▶ | $match = 0 unless (defined $params{$parameter_name} xor !defined $model->[$index]); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%4/4
defined $params{$parameter_name} xor not defined $model->[$index]
MC/DC100%2/2
defined $params{$parameter_name} xor not defined $model->[$index]
defined $params{$parameter_name}
not defined $model->[$index]
Truth table100%4/4
A xor not(B)
A= defined $params{$parameter_name}B= not defined $model->[$index]
| ||||||||||||||||||||||||||||||||||
| 137 | 102 | ▶ | last unless ($match); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 138 | } | |||||||||||||||||||||||||||||||||
| 139 | 41 | ▶ | push @$results, $model if ($match); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 140 | } | |||||||||||||||||||||||||||||||||
| 141 | ||||||||||||||||||||||||||||||||||
| 142 | 6 | ▶ | return (scalar @$results) ? $results->[0] : undef; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 143 | } | |||||||||||||||||||||||||||||||||
| 144 | ||||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | sub _modify_params { | |||||||||||||||||||||||||||||||
|
Subroutine
_modify_params: called CC=9 SCAR=22.5
| ||||||||||||||||||||||||||||||||||
| 146 | 9 | my %params = @_; | ||||||||||||||||||||||||||||||||
| 147 | ||||||||||||||||||||||||||||||||||
| 148 | $params{bone_age_per_age} = $params{bone_age} / $params{age} | |||||||||||||||||||||||||||||||||
| 149 | 9 | ▶ | if (defined $params{bone_age} and $params{age}); | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params{"bone_age"} and $params{"age"}
MC/DC100%2/2
defined $params{"bone_age"} and $params{"age"}
defined $params{"bone_age"}
$params{"age"}
Truth table100%3/3
A and B
A= defined $params{"bone_age"}B= $params{"age"}
| ||||||||||||||||||||||||||||||||||
| 150 | ||||||||||||||||||||||||||||||||||
| 151 | 9 | ▶ | if (defined $params{sex}) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 152 | 5 | my $sex = lc $params{sex}; | ||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | $params{sex} = ($sex eq 'male') ? 1 : ($sex eq 'female') ? 2 : $sex; | |||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||
| 154 | } | |||||||||||||||||||||||||||||||||
| 155 | ||||||||||||||||||||||||||||||||||
| 156 | 9 | for my $parameter_name (values %{ PARAMETER_NAMES() }) { | ||||||||||||||||||||||||||||||||
| 157 | 81 | ▶ | if (defined $params{$parameter_name} and !looks_like_number($params{$parameter_name})) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params{$parameter_name} and not &looks_like_number($params{$parameter_name})
MC/DC0%0/2
defined $params{$parameter_name} and not &looks_like_number($params{$parameter_name})
defined $params{$parameter_name}
not &looks_like_number($params{$parameter_name})
Truth table66%2/3
A and not(B)
A= defined $params{$parameter_name}B= not &looks_like_number($params{$parameter_name})
| ||||||||||||||||||||||||||||||||||
| 158 | 0 | warn "input parameter $parameter_name removed, because value $params{$parameter_name} is not numeric"; | ||||||||||||||||||||||||||||||||
| 159 | 0 | delete $params{$parameter_name}; | ||||||||||||||||||||||||||||||||
| 160 | } | |||||||||||||||||||||||||||||||||
| 161 | } | |||||||||||||||||||||||||||||||||
| 162 | ||||||||||||||||||||||||||||||||||
| 163 | 9 | return %params; | ||||||||||||||||||||||||||||||||
| 164 | } | |||||||||||||||||||||||||||||||||
| 165 | ||||||||||||||||||||||||||||||||||
| 166 | =head1 AUTHOR | |||||||||||||||||||||||||||||||||
| 167 | ||||||||||||||||||||||||||||||||||
| 168 | Christoph Beger, C<< <christoph.beger at medizin.uni-leipzig.de> >> | |||||||||||||||||||||||||||||||||
| 169 | ||||||||||||||||||||||||||||||||||
| 170 | =cut | |||||||||||||||||||||||||||||||||
| 171 | ||||||||||||||||||||||||||||||||||
| 172 | 2 | 1; | ||||||||||||||||||||||||||||||||