line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ########################################################################## #
|
4
|
|
|
|
|
|
|
# Title: Write data stream to tab separated stream
|
5
|
|
|
|
|
|
|
# Creation date: 2007-03-05
|
6
|
|
|
|
|
|
|
# Author: Michael Zedeler
|
7
|
|
|
|
|
|
|
# Description: Writes data stream to a handle (IO::Handle)
|
8
|
|
|
|
|
|
|
# Data Stream class
|
9
|
|
|
|
|
|
|
# Transformer
|
10
|
|
|
|
|
|
|
# File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/TabStreamWriter.pm,v $
|
11
|
|
|
|
|
|
|
# Repository: kronhjorten
|
12
|
|
|
|
|
|
|
# State: $State: Exp $
|
13
|
|
|
|
|
|
|
# Documentation: inline
|
14
|
|
|
|
|
|
|
# Recepient: -
|
15
|
|
|
|
|
|
|
# #TODO Must store field order internally. Ask not where to get it from.
|
16
|
|
|
|
|
|
|
# ########################################################################## #
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package DS::Transformer::TabStreamWriter;
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
1015
|
use base qw{ DS::Transformer::TypePassthrough };
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
695
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
23
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
24
|
1
|
|
|
1
|
|
6
|
use Carp::Assert;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our ($VERSION) = $DS::VERSION;
|
27
|
|
|
|
|
|
|
our ($REVISION) = '$Revision: 1.2 $' =~ /(\d+\.\d+)/;
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new {
|
30
|
2
|
|
|
2
|
1
|
828
|
my( $class, $fh, $field_order, $source, $target ) = @_;
|
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
15
|
my $self = $class->SUPER::new( $source, $target );
|
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
15
|
assert($fh->isa('IO::Handle'));
|
35
|
2
|
|
|
|
|
9
|
$self->{fh} = $fh;
|
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
4
|
$self->{field_order} = $field_order;
|
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
6
|
return $self;
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub receive_row {
|
43
|
24
|
|
|
24
|
1
|
32
|
my( $self, $row ) = @_;
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# TODO (V3) This needs to be rewritten once a new typing system is in place
|
46
|
|
|
|
|
|
|
# Trying to figure out field order here is just plain ugly and only
|
47
|
|
|
|
|
|
|
# something we do to allow TabFileWriter to work (it needs field order to be
|
48
|
|
|
|
|
|
|
# set before process is called.
|
49
|
24
|
50
|
|
|
|
54
|
unless( $self->{field_order} ) {
|
50
|
0
|
|
|
|
|
0
|
$self->{field_order} = [sort keys %$row];
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
24
|
|
|
|
|
72
|
return $self->SUPER::receive_row( $row );
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub include_header {
|
57
|
0
|
|
|
0
|
0
|
0
|
my( $self ) = @_;
|
58
|
0
|
|
|
|
|
0
|
$self->{include_header} = 1;
|
59
|
0
|
|
|
|
|
0
|
return;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub exclude_header {
|
63
|
0
|
|
|
0
|
0
|
0
|
my( $self ) = @_;
|
64
|
0
|
|
|
|
|
0
|
$self->{include_header} = 0;
|
65
|
0
|
|
|
|
|
0
|
return;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub process {
|
69
|
24
|
|
|
24
|
1
|
33
|
my( $self, $row) = @_;
|
70
|
|
|
|
|
|
|
|
71
|
24
|
100
|
|
|
|
46
|
if( $row ) {
|
72
|
22
|
50
|
33
|
|
|
54
|
if( $self->{include_header} and not $self->{header_included} ) {
|
73
|
0
|
|
|
|
|
0
|
$self->write_header;
|
74
|
0
|
|
|
|
|
0
|
$self->{header_included} = 1;
|
75
|
|
|
|
|
|
|
}
|
76
|
22
|
|
|
|
|
30
|
$self->{fh}->print(join("\t", @$row{@{$self->{field_order}}}), "\r\n");
|
|
22
|
|
|
|
|
115
|
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
|
79
|
24
|
|
|
|
|
162
|
return $row;
|
80
|
|
|
|
|
|
|
}
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub write_header {
|
83
|
2
|
|
|
2
|
0
|
4
|
my( $self ) = @_;
|
84
|
2
|
|
|
|
|
6
|
assert( $self->{field_order} );
|
85
|
2
|
|
|
|
|
9
|
$self->{fh}->print(join("\t", @{$self->{field_order}}), "\r\n");
|
|
2
|
|
|
|
|
17
|
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1;
|
89
|
|
|
|
|
|
|
|