annotate changeCase.pl @ 3:ecf91530d461 draft default tip

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