Mercurial > repos > devteam > change_case
comparison changeCase.pl @ 0:e6f966602870 draft
Uploaded change_case tarball.
author | devteam |
---|---|
date | Tue, 04 Dec 2012 10:49:46 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e6f966602870 |
---|---|
1 #! /usr/bin/perl -w | |
2 | |
3 use strict; | |
4 use warnings; | |
5 | |
6 my $columns = {}; | |
7 my $del = ""; | |
8 my @in = (); | |
9 my @out = (); | |
10 my $command = ""; | |
11 my $field = 0; | |
12 | |
13 # a wrapper for changing the case of columns from within galaxy | |
14 # isaChangeCase.pl [filename] [columns] [delim] [casing] [output] | |
15 | |
16 die "Check arguments: $0 [filename] [columns] [delim] [casing] [output]\n" unless @ARGV == 5; | |
17 | |
18 # process column input | |
19 $ARGV[1] =~ s/\s+//g; | |
20 foreach ( split /,/, $ARGV[1] ) { | |
21 if (m/^c\d{1,}$/i) { | |
22 s/c//ig; | |
23 $columns->{$_} = --$_; | |
24 } | |
25 } | |
26 | |
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; | |
28 | |
29 my $column_delimiters_href = { | |
30 'TAB' => q{\t}, | |
31 'COMMA' => ",", | |
32 'DASH' => "-", | |
33 'UNDERSCORE' => "_", | |
34 'PIPE' => q{\|}, | |
35 'DOT' => q{\.}, | |
36 'SPACE' => q{\s+} | |
37 }; | |
38 | |
39 $del = $column_delimiters_href->{$ARGV[2]}; | |
40 | |
41 open (OUT, ">$ARGV[4]") or die "Cannot create $ARGV[4]:$!\n"; | |
42 open (IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n"; | |
43 while (<IN>) { | |
44 chop; | |
45 @in = split /$del/; | |
46 for ( my $i = 0; $i <= $#in; ++$i) { | |
47 if (exists $columns->{$i}) { | |
48 push(@out, $ARGV[3] eq 'up' ? uc($in[$i]) : lc($in[$i])); | |
49 } else { | |
50 push(@out, $in[$i]); | |
51 } | |
52 } | |
53 print OUT join("\t",@out), "\n"; | |
54 @out = (); | |
55 } | |
56 close IN; | |
57 | |
58 close OUT; |