line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package DataCube::FileUtils::FileReader; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1988
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
6
|
use Time::HiRes; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
103
|
use Fcntl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
367
|
|
10
|
1
|
|
|
1
|
|
48
|
use DataCube; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use DataCube::Schema; |
12
|
|
|
|
|
|
|
use DataCube::FileUtils; |
13
|
|
|
|
|
|
|
use Storable qw(nstore retrieve); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
my($class,%opts) = @_; |
17
|
|
|
|
|
|
|
bless { %opts }, ref($class) || $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub read { |
21
|
|
|
|
|
|
|
my($self,$file) = @_; |
22
|
|
|
|
|
|
|
open(my $F, '<' , $file) or die |
23
|
|
|
|
|
|
|
"DataCube::FileUtils::FileReader(read):\ncant open file:\n$file\n$!\n"; |
24
|
|
|
|
|
|
|
my $fields = <$F>; |
25
|
|
|
|
|
|
|
chomp($fields); |
26
|
|
|
|
|
|
|
my @fields = split/\t/,$fields,-1; |
27
|
|
|
|
|
|
|
my %fields = map { $fields[$_] => $_ } 0 .. $#fields; |
28
|
|
|
|
|
|
|
my %reverse = reverse %fields; |
29
|
|
|
|
|
|
|
$self->{fields} = \%fields; |
30
|
|
|
|
|
|
|
$self->{handle} = $F; |
31
|
|
|
|
|
|
|
$self->{reverse} = \%reverse; |
32
|
|
|
|
|
|
|
$self->{columns} = $#fields; |
33
|
|
|
|
|
|
|
$self->{nfields} = $#fields + 1; |
34
|
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub nextrow_hashref { |
38
|
|
|
|
|
|
|
my($self) = @_; |
39
|
|
|
|
|
|
|
my $F = $self->{handle}; |
40
|
|
|
|
|
|
|
my $line = <$F>; |
41
|
|
|
|
|
|
|
return unless defined $line; |
42
|
|
|
|
|
|
|
chomp($line); |
43
|
|
|
|
|
|
|
return $self->nextrow_hashref unless length($line); |
44
|
|
|
|
|
|
|
my @line = split/\t/,$line,-1; |
45
|
|
|
|
|
|
|
my %data; |
46
|
|
|
|
|
|
|
$data{$self->{reverse}->{$_}} = $line[$_] for 0 .. $self->{columns}; |
47
|
|
|
|
|
|
|
return \%data; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub slurp { |
51
|
|
|
|
|
|
|
my($self,$file) = @_; |
52
|
|
|
|
|
|
|
sysopen(my $F, $file, O_RDONLY) |
53
|
|
|
|
|
|
|
or die "DataCube::FileUtils::FileReader(slurp):\ncant sysopen:\n$file\n$!\n"; |
54
|
|
|
|
|
|
|
my $size = -s($file); |
55
|
|
|
|
|
|
|
my $read = sysread($F, my $data, $size); |
56
|
|
|
|
|
|
|
die "DataCube::FileUtils::FileReader(slurp | bytes):\nsysread return: $read bytes\nwanted to get: $size bytes\n$!\n" |
57
|
|
|
|
|
|
|
unless $size == $read; |
58
|
|
|
|
|
|
|
close $F; |
59
|
|
|
|
|
|
|
my @lines = split/\n+/,$data; |
60
|
|
|
|
|
|
|
$data = undef; |
61
|
|
|
|
|
|
|
return () unless @lines; |
62
|
|
|
|
|
|
|
my $head = shift @lines; |
63
|
|
|
|
|
|
|
my @heads = split/\t/,$head,-1; |
64
|
|
|
|
|
|
|
my %lookup = map { $_ => $heads[$_] } 0 .. $#heads; |
65
|
|
|
|
|
|
|
my @results; |
66
|
|
|
|
|
|
|
while(my $line = shift @lines){ |
67
|
|
|
|
|
|
|
my @line = split/\t/,$line,-1; |
68
|
|
|
|
|
|
|
my %data = map { $lookup{$_} => $line[$_] } 0 .. $#heads; |
69
|
|
|
|
|
|
|
push @results, \%data; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
return @results; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |