Created
March 13, 2013 12:40
-
-
Save anonymous/5151700 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl -w | |
use strict; | |
# Lea Benedicte Skov Hansen, Mar 2013 | |
# This program reads a table, sums the rows and create a histogram of the sums | |
my $input = 'test_count.txt'; #'count.matrix.ratio_new'; | |
my $output = 'row_sum_his.txt'; | |
my $interval = 5; | |
# Open input and output files | |
open(IN, '<', $input) or die "Can't read file '$input': $!\n"; | |
open(OUT, '>', $output) or die "Can't write to file '$output': $!\n"; | |
# Declaring all interval variables | |
my $count1 = 0; | |
my $count2 = 0; | |
my $count3 = 0; | |
my $count4 = 0; | |
my $count5 = 0; | |
my $count6 = 0; | |
my $count7 = 0; | |
my $count8 = 0; | |
my $count9 = 0; | |
my $count10 = 0; | |
my $count11 = 0; | |
my $count12 = 0; | |
my $count13 = 0; | |
my $count14 = 0; | |
my $count15 = 0; | |
my $count16 = 0; | |
my $count17 = 0; | |
my $count18 = 0; | |
my $count19 = 0; | |
my $count20 = 0; | |
# Read the input file | |
my @row = (); | |
my $header = <IN>; | |
my $sum = 0; | |
while (defined (my $line = <IN>)) { | |
chomp $line; | |
@row = split(' ', $line); | |
shift(@row); | |
# Loop that calculates the sum of the row | |
foreach my $numbers (@row) { | |
$sum += $numbers; | |
} | |
# for loop.... | |
# Creating a histogram of 20 first intervals | |
$count1++ if (0 < $sum <= $interval); | |
$count2++ if ($interval < $sum <= $interval*2); | |
$count3++ if ($interval*2 < $sum <= $interval*3); | |
$count4++ if ($interval*3 < $sum <= $interval*4); | |
$count5++ if ($interval*4 < $sum <= $interval*5); | |
$count6++ if ($interval*5 < $sum <= $interval*6); | |
$count7++ if ($interval*6 < $sum <= $interval*7); | |
$count8++ if ($interval*7 < $sum <= $interval*8); | |
$count9++ if ($interval*8 < $sum <= $interval*9); | |
$count10++ if ($interval*9 < $sum <= $interval*10); | |
$count11++ if ($interval*10 < $sum <= $interval*11); | |
$count12++ if ($interval*11 < $sum <= $interval*12); | |
$count13++ if ($interval*12 < $sum <= $interval*13); | |
$count14++ if ($interval*13 < $sum <= $interval*14); | |
$count15++ if ($interval*14 < $sum <= $interval*15); | |
$count16++ if ($interval*15 < $sum <= $interval*16); | |
$count17++ if ($interval*16 < $sum <= $interval*17); | |
$count18++ if ($interval*17 < $sum <= $interval*18); | |
$count19++ if ($interval*18 < $sum <= $interval*19); | |
$count20++ if ($interval*19 < $sum <= $interval*20); | |
} | |
close IN; | |
close OUT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment