line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# tabdelim_to_db.pm |
5
|
|
|
|
|
|
|
# Copyright (C) 2005-2007 by John Heidemann |
6
|
|
|
|
|
|
|
# $Id: 1a976a31ff4f2b1a666224af678a0ad4ca3e47c4 $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is distributed under terms of the GNU general |
9
|
|
|
|
|
|
|
# public license, version 2. See the file COPYING |
10
|
|
|
|
|
|
|
# in $dblib for details. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Fsdb::Filter::tabdelim_to_db; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
tabdelim_to_db - convert tab-delimited data into fsdb |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
tabdelim_to_db target.fsdb |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Converts a tab-delimited data stream to Fsdb format. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The input is tab-delimited (I fsdb): |
28
|
|
|
|
|
|
|
the first row is taken to be the names of the columns; |
29
|
|
|
|
|
|
|
tabs separate columns. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The output is a fsdb file with a proper header |
32
|
|
|
|
|
|
|
and a tab field-separator. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=for comment |
35
|
|
|
|
|
|
|
begin_standard_fsdb_options |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This module also supports the standard fsdb options: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item B<-d> |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Enable debugging output. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item B<-i> or B<--input> InputSource |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Read from InputSource, typically a file name, or C<-> for standard input, |
48
|
|
|
|
|
|
|
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item B<-o> or B<--output> OutputDestination |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Write to OutputDestination, typically a file name, or C<-> for standard output, |
53
|
|
|
|
|
|
|
or (if in Perl) a IO::Handle, Fsdb::IO or Fsdb::BoundedQueue objects. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item B<--autorun> or B<--noautorun> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
By default, programs process automatically, |
58
|
|
|
|
|
|
|
but Fsdb::Filter objects in Perl do not run until you invoke |
59
|
|
|
|
|
|
|
the run() method. |
60
|
|
|
|
|
|
|
The C<--(no)autorun> option controls that behavior within Perl. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item B<--help> |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Show help. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item B<--man> |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Show full manual. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=back |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=for comment |
73
|
|
|
|
|
|
|
end_standard_fsdb_options |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SAMPLE USAGE |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 Input: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
name email test1 |
81
|
|
|
|
|
|
|
Tommy Trojan tt@usc.edu 80 |
82
|
|
|
|
|
|
|
Joe Bruin joeb@ucla.edu 85 |
83
|
|
|
|
|
|
|
J. Random jr@caltech.edu 90 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 Command: |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
tabdelim_to_db |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 Output: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#fsdb -Ft name email test1 |
92
|
|
|
|
|
|
|
Tommy Trojan tt@usc.edu 80 |
93
|
|
|
|
|
|
|
Joe Bruin joeb@ucla.edu 85 |
94
|
|
|
|
|
|
|
J. Random jr@caltech.edu 90 |
95
|
|
|
|
|
|
|
# | dbcoldefine name email test1 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 CLASS FUNCTIONS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
@ISA = qw(Fsdb::Filter); |
108
|
|
|
|
|
|
|
$VERSION = 2.0; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
1
|
|
6010
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
111
|
1
|
|
|
1
|
|
6
|
use Pod::Usage; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
137
|
|
112
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
1
|
|
5
|
use Fsdb::Filter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
115
|
1
|
|
|
1
|
|
4
|
use Fsdb::IO::Writer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
667
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 new |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$filter = new Fsdb::Filter::tabdelim_to_db(@arguments); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Create a new tabdelim_to_db object, taking command-line arguments. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub new ($@) { |
127
|
0
|
|
|
0
|
1
|
|
my $class = shift @_; |
128
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
129
|
0
|
|
|
|
|
|
bless $self, $class; |
130
|
0
|
|
|
|
|
|
$self->set_defaults; |
131
|
0
|
|
|
|
|
|
$self->parse_options(@_); |
132
|
0
|
|
|
|
|
|
$self->SUPER::post_new(); |
133
|
0
|
|
|
|
|
|
return $self; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 set_defaults |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$filter->set_defaults(); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Internal: set up defaults. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub set_defaults ($) { |
146
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
147
|
0
|
|
|
|
|
|
$self->SUPER::set_defaults(); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 parse_options |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
$filter->parse_options(@ARGV); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Internal: parse command-line arguments. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub parse_options ($@) { |
159
|
0
|
|
|
0
|
1
|
|
my $self = shift @_; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my(@argv) = @_; |
162
|
|
|
|
|
|
|
$self->get_options( |
163
|
|
|
|
|
|
|
\@argv, |
164
|
0
|
|
|
0
|
|
|
'help|?' => sub { pod2usage(1); }, |
165
|
0
|
|
|
0
|
|
|
'man' => sub { pod2usage(-verbose => 2); }, |
166
|
|
|
|
|
|
|
'autorun!' => \$self->{_autorun}, |
167
|
|
|
|
|
|
|
'd|debug+' => \$self->{_debug}, |
168
|
0
|
|
|
0
|
|
|
'i|input=s' => sub { $self->parse_io_option('input', @_); }, |
169
|
|
|
|
|
|
|
'log!' => \$self->{_logprog}, |
170
|
0
|
|
|
0
|
|
|
'o|output=s' => sub { $self->parse_io_option('output', @_); }, |
171
|
0
|
0
|
|
|
|
|
) or pod2usage(2); |
172
|
0
|
0
|
|
|
|
|
pod2usage(2) if ($#argv >= 0); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 setup |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$filter->setup(); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Internal: setup, parse headers. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub setup ($) { |
184
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$self->finish_fh_io_option('input'); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
my($header); |
189
|
0
|
|
|
|
|
|
$header = $self->{_in}->getline; |
190
|
0
|
|
|
|
|
|
my(@columns) = Fsdb::IO::clean_potential_columns(split(/\t/, $header)); |
191
|
0
|
0
|
|
|
|
|
croak $self->{_prog} . ": don't find any column headings in the first row.\n" |
192
|
|
|
|
|
|
|
if ($#columns == -1); |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$self->finish_io_option('output', -fscode => 't', -cols => \@columns); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 run |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$filter->run(); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Internal: run over each rows. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
sub run ($) { |
205
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $write_fastpath_sub = $self->{_out}->fastpath_sub(); |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
for (;;) { |
210
|
0
|
|
|
|
|
|
my $line = $self->{_in}->getline; |
211
|
0
|
0
|
|
|
|
|
last if (!defined($line)); |
212
|
0
|
|
|
|
|
|
chomp $line; |
213
|
0
|
|
|
|
|
|
my @row = split(/\t/, $line); |
214
|
0
|
|
|
|
|
|
&{$write_fastpath_sub}(\@row); |
|
0
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
}; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 AUTHOR and COPYRIGHT |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Copyright (C) 1991-2008 by John Heidemann |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This program is distributed under terms of the GNU general |
224
|
|
|
|
|
|
|
public license, version 2. See the file COPYING |
225
|
|
|
|
|
|
|
with the distribution for details. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; |