annotate multijoin @ 0:5314e5d6f040 draft

Imported from capsule None
author bgruening
date Thu, 29 Jan 2015 07:53:17 -0500
parents
children 20344ce0c811
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
1 #!/usr/bin/env perl
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
2 use strict;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
3 use warnings;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
4 use Getopt::Long qw(:config no_ignore_case);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
5 use Data::Dumper;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
6 use Carp;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
7 use File::Basename;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
8 use Sort::Key::Natural qw(natsort);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
9
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
10 my $version = "0.1.1";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
11 my $field_sep = "\t";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
12 my $key_column;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
13 my @values_columns;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
14 my $max_value_column;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
15 my @input_files;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
16 my $input_headers ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
17 my $output_headers;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
18 my $filler = "0";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
19 my $filler_string ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
20 my $ignore_duplicates;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
21 my $debug = 0 ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
22 my %input_headers;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
23 my $have_file_labels;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
24 my %file_labels;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
25
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
26 sub parse_command_line_parameters();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
27 sub show_help();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
28 sub read_input_file($);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
29 sub print_combined_data();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
30 sub sanitize_filename($);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
31 sub print_output_header();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
32 sub show_examples();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
33
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
34 ##
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
35 ## Program Start
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
36 ##
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
37
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
38 parse_command_line_parameters();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
39
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
40 my %data;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
41 foreach my $file (@input_files) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
42 read_input_file($file);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
43 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
44 #print STDERR Dumper(\%input_headers),"\n";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
45 #print STDERR Dumper(\%data) if $debug;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
46 print_output_header() if $output_headers;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
47 print_combined_data();
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
48
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
49
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
50 ##
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
51 ## Program End
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
52 ##
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
53 sub print_output_header()
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
54 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
55 my @output = ("key");
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
56 foreach my $file ( @input_files ) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
57 foreach my $column ( @values_columns ) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
58 my $column_name = ( exists $input_headers{$file}->{$column} ) ?
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
59 $input_headers{$file}->{$column} :
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
60 "V$column" ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
61
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
62 push @output, $file_labels{$file} . "_" . $column_name;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
63 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
64 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
65 print join($field_sep,@output),"\n"
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
66 or die "Output error: can't write output line: $!\n";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
67 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
68
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
69 sub print_combined_data()
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
70 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
71 my @keys = natsort keys %data ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
72
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
73 foreach my $key ( @keys ) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
74 my @outputs;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
75
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
76 foreach my $file (@input_files) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
77 push @outputs,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
78 (exists $data{$key}->{$file}) ? $data{$key}->{$file} : $filler_string;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
79 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
80
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
81 print join($field_sep,$key,@outputs),"\n"
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
82 or die "Output error: can't write output line: $!\n";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
83 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
84 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
85
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
86 sub sanitize_filename($)
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
87 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
88 my ($filename) = shift or croak "missing file name";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
89 my $file_ID = basename($filename);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
90 $file_ID =~ s/\.\w+$//; # remove extension
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
91 $file_ID =~ s/^[^\w\.\-]+//;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
92 $file_ID =~ s/[^\w\.\-]+$//;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
93 $file_ID =~ s/[^\w\.\-]+/_/g; # sanitize bad characters
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
94 return $file_ID;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
95 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
96
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
97 sub read_input_file($)
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
98 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
99 my ($filename) = shift or croak "Missing input file name";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
100
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
101 my @value_indexes = map { $_-1 } @values_columns; #zero-based indexes for value columns
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
102
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
103 open FILE, "<", $filename
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
104 or die "Error: can't open file '$filename': $!\n";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
105
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
106 ## Read file's header
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
107 if ($input_headers) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
108 my $line = <FILE>;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
109 chomp $line;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
110 my @fields = split $field_sep, $line;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
111
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
112 my $num_input_fields = scalar(@fields);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
113 die "Input error: file '$filename' line $. doesn't have enough columns (value column = $max_value_column, line has only $num_input_fields columns)\n" if $num_input_fields < $max_value_column ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
114
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
115 foreach my $col (@values_columns) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
116 $input_headers{$filename}->{$col} = $fields[$col-1] ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
117 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
118 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
119
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
120
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
121 ## Read file's data
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
122 while ( my $line = <FILE> ) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
123 chomp $line;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
124 my @fields = split $field_sep, $line;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
125
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
126 my $num_input_fields = scalar(@fields);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
127 die "Input error: file '$filename' line $. doesn't have enough columns (key column = $key_column, line has only $num_input_fields columns)\n" if $num_input_fields < $key_column ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
128 die "Input error: file '$filename' line $. doesn't have enough columns (value column = $max_value_column, line has only $num_input_fields columns)\n" if $num_input_fields < $max_value_column ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
129
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
130
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
131 my $key = $fields[$key_column-1];
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
132 my $value = join($field_sep, @fields[@value_indexes]);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
133
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
134 die "Input error: file '$filename' line $. have duplicated key '$key'.\n"
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
135 if (exists $data{$key}->{$filename} && !$ignore_duplicates) ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
136 $data{$key}->{$filename} = $value;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
137 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
138 close FILE
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
139 or die "Error: can't write and close file '$filename': $!\n";
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
140 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
141
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
142 sub parse_command_line_parameters()
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
143 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
144 my $values_columns_string;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
145
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
146 my $rc = GetOptions("help" => \&show_help,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
147 "key|k=i" => \$key_column,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
148 "values|v=s" => \$values_columns_string,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
149 "t=s" => \$field_sep,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
150 "in-header" => \$input_headers,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
151 "out-header|h" => \$output_headers,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
152 "H" => sub { $input_headers = 1 ; $output_headers = 1 ; },
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
153 "ignore-dups" => \$ignore_duplicates,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
154 "filler|f=s" => \$filler,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
155 "examples" => \&show_examples,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
156 "labels" => \$have_file_labels,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
157 );
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
158 die "Error: inalid command-line parameters.\n" unless $rc;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
159
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
160 die "Error: missing key column. use --key N. see --help for more details.\n" unless defined $key_column;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
161 die "Error: Invalid key column ($key_column). Must be bigger than zero. see --help for more details.\n" if $key_column <= 0 ;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
162
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
163 die "Error: missing values column. use --values V1,V2,Vn. See --help for more details.\n" unless defined $values_columns_string;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
164 @values_columns = split(/\s*,\s*/, $values_columns_string);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
165
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
166 die "Error: missing values column. use --values N,N,N. see --help for more details.\n" unless scalar(@values_columns)>0;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
167 foreach my $v (@values_columns) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
168 die "Error: invalid value column ($v), please use only numbers>=1. see --help for more details.\n"
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
169 unless $v =~ /^\d+$/ && $v>=1;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
170
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
171 $max_value_column = $v unless defined $max_value_column && $max_value_column>$v;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
172 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
173
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
174 $filler_string = join($field_sep, map { $filler } @values_columns);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
175
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
176
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
177 if ($have_file_labels) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
178 ## have file labels - each pair of parameters is a file/label pair.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
179 die "Error: missing input files and labels\n" if scalar(@ARGV)==0;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
180 die "Error: when using --labels, a pair of file names + labels is required (got odd number of argiments)\n" unless scalar(@ARGV)%2==0;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
181
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
182 while (@ARGV) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
183 my $filename = shift @ARGV;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
184 my $label = shift @ARGV;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
185 $label =~ s/^[^\.\w\-]+//;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
186 $label =~ s/[^\.\w\-]+$//g;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
187 $label =~ s/[^\.\w\-]+/_/g;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
188
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
189 my $file_ID = sanitize_filename($filename);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
190 $file_labels{$filename} = $label;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
191 push @input_files, $filename;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
192 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
193 } else {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
194 ## no file labels - the rest of the arguments are just file names;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
195 @input_files = @ARGV;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
196 die "Error: missing input files\n" if scalar(@input_files)==0;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
197 die "Error: need more than one input file to join.\n" if scalar(@input_files)==1;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
198
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
199 foreach my $file (@input_files) {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
200 my $file_ID = sanitize_filename($file);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
201 $file_labels{$file} = $file_ID;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
202 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
203 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
204
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
205 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
206
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
207 sub show_help()
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
208 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
209 print<<EOF;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
210 Multi-File join, version $version
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
211 Copyright (C) 2012 - A. Gordon (gordon at cshl dot edu)
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
212 License AGPLv3+: Affero GPL version 3 or later (http://www.gnu.org/licenses/agpl.html)
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
213
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
214 Usage:
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
215 multijoin [OPTIONS] -k N -v V1,V2,Vn,.. FILE1 FILE2 ... FILEn
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
216
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
217 Options:
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
218
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
219 --help This helpful help screen.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
220
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
221 -k N
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
222 --key N Use column N as key column.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
223
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
224 -v V1,V2,Vn
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
225 --values V1,V2,Vn
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
226 Use columns V1,V2,Vn as value columns - those will be joined
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
227 According to the Key column.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
228 Multiple columns can be specified.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
229
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
230 -t SEP Use SEP as field separator character (default: tab).
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
231
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
232 -h
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
233 --out-header Add a header line to the output file.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
234
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
235 --in-header The input files have a header line.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
236 The first line will not be joined.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
237 if '--out-header' is also used, the output column headers will
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
238 be constructed based on the input header column names.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
239
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
240 -H
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
241 --headers Same as '--in-header --out-header' combined.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
242
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
243 --ignore-dups Ignore duplicated keys (within a file).
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
244 By default, duplicated keys cause an error.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
245
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
246 -f X
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
247 --filler X Fill missing values with X.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
248 (Default: '$filler').
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
249
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
250 --labels When printning output headers with '-h', instead of using the file name,
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
251 use specific labels.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
252 Each file name must be followed by a name.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
253
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
254 example (without labels):
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
255 \$ multijoin -h -k 1 -v 2 A.TXT B.TXT C.TXT
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
256
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
257 example (with labels):
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
258 \$ multijoin -h --labels -k 1 -v 2 A.TXT Sample1 B.TXT SampleB C.TXT SampleC
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
259
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
260 --examples Show detailed examples.
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
261
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
262 EOF
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
263 exit(0);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
264 }
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
265
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
266 sub show_examples()
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
267 {
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
268 print<<EOF;
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
269
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
270 To join three files, based on the 4th column, and keeping the 7th,8th,9th columns:
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
271
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
272 \$ head *.txt
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
273 ==> AAA.txt <==
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
274 chr4 888449 890171 FBtr0308778 0 + 266 1527 1722
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
275 chr4 972167 979017 FBtr0310651 0 - 3944 6428 6850
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
276 chr4 972186 979017 FBtr0089229 0 - 3944 6428 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
277 chr4 972186 979017 FBtr0089231 0 - 3944 6428 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
278 chr4 972186 979017 FBtr0089233 0 - 3944 6428 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
279 chr4 995793 996435 FBtr0111046 0 + 7 166 642
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
280 chr4 995793 997931 FBtr0111044 0 + 28 683 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
281 chr4 995793 997931 FBtr0111045 0 + 28 683 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
282 chr4 1034029 1047719 FBtr0089223 0 - 5293 13394 13690
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
283
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
284 ==> BBB.txt <==
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
285 chr4 90286 134453 FBtr0309803 0 + 657 29084 44167
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
286 chr4 251355 266499 FBtr0089116 0 + 56 1296 15144
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
287 chr4 252050 266506 FBtr0308086 0 + 56 1296 14456
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
288 chr4 252050 266506 FBtr0308087 0 + 56 1296 14456
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
289 chr4 252053 266528 FBtr0300796 0 + 56 1296 14475
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
290 chr4 252053 266528 FBtr0300800 0 + 56 1296 14475
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
291 chr4 252055 266528 FBtr0300798 0 + 56 1296 14473
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
292 chr4 252055 266528 FBtr0300799 0 + 56 1296 14473
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
293 chr4 252541 266528 FBtr0300797 0 + 56 1296 13987
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
294
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
295 ==> CCC.txt <==
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
296 chr4 972167 979017 FBtr0310651 0 - 9927 6738 6850
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
297 chr4 972186 979017 FBtr0089229 0 - 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
298 chr4 972186 979017 FBtr0089231 0 - 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
299 chr4 972186 979017 FBtr0089233 0 - 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
300 chr4 995793 996435 FBtr0111046 0 + 5 304 642
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
301 chr4 995793 997931 FBtr0111044 0 + 17 714 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
302 chr4 995793 997931 FBtr0111045 0 + 17 714 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
303 chr4 1034029 1047719 FBtr0089223 0 - 17646 13536 13690
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
304
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
305 \$ multijoin -h --key 4 --values 7,8,9 *.txt | head -n 10
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
306 key AAA__V7 AAA__V8 AAA__V9 BBB__V7 BBB__V8 BBB__V9 CCC__V7 CCC__V8 CCC__V9
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
307 FBtr0089116 0 0 0 56 1296 15144 0 0 0
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
308 FBtr0089223 5293 13394 13690 0 0 0 17646 13536 13690
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
309 FBtr0089229 3944 6428 6831 0 0 0 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
310 FBtr0089231 3944 6428 6831 0 0 0 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
311 FBtr0089233 3944 6428 6831 0 0 0 9927 6738 6831
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
312 FBtr0111044 28 683 2138 0 0 0 17 714 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
313 FBtr0111045 28 683 2138 0 0 0 17 714 2138
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
314 FBtr0111046 7 166 642 0 0 0 5 304 642
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
315 FBtr0300796 0 0 0 56 1296 14475 0 0 0
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
316
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
317
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
318
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
319 EOF
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
320 exit(0);
5314e5d6f040 Imported from capsule None
bgruening
parents:
diff changeset
321 }