in reply to Sliding window intervals and average values for specific coordinates
I'm not quite sure what you mean by your last sentence as I wouldn't have thought all the markers in one particular window will all be members of the same windows. Anyway, is this something like what you are trying to do?
use strict; use warnings; use 5.010; use List::Util qw{ sum }; use Data::Dumper; open my $windowsFH, q{<}, \ <<EOD or die qq{open: < HEREDOC: $!\n}; 10 19 0.287 11 20 0.502 12 21 0.462 13 22 0.407 14 23 0.254 15 24 0.335 16 25 0.474 EOD my %values; while ( <$windowsFH> ) { my( $min, $max, $value ) = split; push @{ $values{ $_ } }, $value for $min .. $max; } close $windowsFH or die qq{close: < HEREDOC: $!\n}; print Data::Dumper ->Dumpxs( [ \ %values ], [ qw{ *values } ] ); open my $markersFH, q{<}, \ <<EOD or die qq{open: < HEREDOC: $!\n}; 12 15 17 EOD while ( <$markersFH> ) { chomp; say qq{$_ - }, ( sum @{ $values{ $_ } } ) / @{ $values{ $_ } }; } close $markersFH or die qq{close: < HEREDOC: $!\n};
The output.
%values = ( '25' => [ '0.474' ], '11' => [ '0.287', '0.502' ], '21' => [ '0.462', '0.407', '0.254', '0.335', '0.474' ], '17' => [ '0.287', '0.502', '0.462', '0.407', '0.254', '0.335', '0.474' ], '12' => [ '0.287', '0.502', '0.462' ], '20' => [ '0.502', '0.462', '0.407', '0.254', '0.335', '0.474' ], '15' => [ '0.287', '0.502', '0.462', '0.407', '0.254', '0.335' ], '14' => [ '0.287', '0.502', '0.462', '0.407', '0.254' ], '22' => [ '0.407', '0.254', '0.335', '0.474' ], '18' => [ '0.287', '0.502', '0.462', '0.407', '0.254', '0.335', '0.474' ], '24' => [ '0.335', '0.474' ], '23' => [ '0.254', '0.335', '0.474' ], '19' => [ '0.287', '0.502', '0.462', '0.407', '0.254', '0.335', '0.474' ], '10' => [ '0.287' ], '13' => [ '0.287', '0.502', '0.462', '0.407' ], '16' => [ '0.287', '0.502', '0.462', '0.407', '0.254', '0.335', '0.474' ] ); 12 - 0.417 15 - 0.3745 17 - 0.388714285714286
I hope this is helpful.
Cheers,
JohnGG
|
|---|