annotate tools/filters/changeCase.pl @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #! /usr/bin/perl -w
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 use strict;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 use warnings;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 my $columns = {};
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 my $del = "";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 my @in = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 my @out = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 my $command = "";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 my $field = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 # a wrapper for changing the case of columns from within galaxy
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 # isaChangeCase.pl [filename] [columns] [delim] [casing] [output]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 die "Check arguments: $0 [filename] [columns] [delim] [casing] [output]\n" unless @ARGV == 5;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 # process column input
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 $ARGV[1] =~ s/\s+//g;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 foreach ( split /,/, $ARGV[1] ) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 if (m/^c\d{1,}$/i) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 s/c//ig;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 $columns->{$_} = --$_;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 die "No columns specified, columns are not preceeded with 'c', or commas are not used to separate column numbers: $ARGV[1]\n" if keys %$columns == 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 my $column_delimiters_href = {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 'TAB' => q{\t},
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 'COMMA' => ",",
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 'DASH' => "-",
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 'UNDERSCORE' => "_",
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 'PIPE' => q{\|},
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 'DOT' => q{\.},
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 'SPACE' => q{\s+}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 };
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 $del = $column_delimiters_href->{$ARGV[2]};
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 open (OUT, ">$ARGV[4]") or die "Cannot create $ARGV[4]:$!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 open (IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 while (<IN>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 chop;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 @in = split /$del/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 for ( my $i = 0; $i <= $#in; ++$i) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 if (exists $columns->{$i}) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 push(@out, $ARGV[3] eq 'up' ? uc($in[$i]) : lc($in[$i]));
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 } else {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 push(@out, $in[$i]);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 print OUT join("\t",@out), "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 @out = ();
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 close IN;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 close OUT;