0

Perl Script for get range value from matrix file

Matrix.txt(content inside)(tap(\t) and newline(\n))

\t100050\t100070\t100100\t100200\t100300\n
100050\t1\t0.0890344\t0.361651\t0.266263\t0.368639\n
100070\t0.0890344\t1\t0.0873663\t0.0267854\t0.148069\n
100100\t0.361651\t0.0873663\t1\t0.0423538\t0.269991\n
100200\t0.266263\t0.0267854\t0.0423538\t1\t0.215814\n
100300\t0.368639\t0.148069\t0.269991\t0.215814\t1

martix file like
--------100050 100070 100100 100200 100300
100050 1 0.0890344 0.361651 0.266263 0.368639
100070 0.0890344 1 0.0873663 0.0267854 0.148069
100100 0.361651 0.0873663 1 0.0423538 0.269991
100200 0.266263 0.0267854 0.0423538 1 0.215814
100300 0.368639 0.148069 0.269991 0.215814 1

I need only value range(0.3 to 1) with two head label (if less then 0.3 not print)

matrix is symmetric: I.e. $m[$i][$j] == $m[$j][$i] for all indices $i and $j.

$m[$i][$j] == $m[$j][$i] value same

no need print $j $i $v if $i $j $v already exit I.e 100050 100100 0.361651 so need to print (100100 100050 0.361651)
output.txt

Label1  label2  value
100050  100050  1
100050  100100  0.361651
100050  100300  0.368639
100070  100070  1
100100      100100  1
100200      100200  1
100300      100300  1
4

2 に答える 2

1
use strict;
use warnings;

my ($dummy, @headers) = split(/\s+/, <DATA>);
my %seen;
while (<DATA>) {
    my ($head, @v) = split; 
    for (my $i = 0; $i < @v; $i++) {
        printf "%10s %10s %8.2f\n", 
            $head, $headers[$i], $v[$i] if $v[$i] >= 0.3 and not $seen{
              join(":", sort ($head, $headers[$i]))
            }++;
    }   
}

__DATA__
--------    100050  100070  100100  100200  100300
100050  1   0.0890344   0.361651    0.266263    0.368639
100070  0.0890344   1   0.0873663   0.0267854   0.148069
100100  0.361651    0.0873663   1   0.0423538   0.269991
100200  0.266263    0.0267854   0.0423538   1   0.215814
100300  0.368639    0.148069    0.269991    0.215814    1
于 2013-06-19T20:53:34.597 に答える