root/galaxy-central/tools/filters/changeCase.pl

リビジョン 2, 1.3 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5
6my $columns = {};
7my $del = "";
8my @in = ();
9my @out = ();
10my $command = "";
11my $field = 0;
12
13# a wrapper for changing the case of columns from within galaxy
14# isaChangeCase.pl [filename] [columns] [delim] [casing] [output]
15
16die "Check arguments: $0 [filename] [columns] [delim] [casing] [output]\n" unless @ARGV == 5;
17
18# process column input
19$ARGV[1] =~ s/\s+//g;
20foreach ( split /,/, $ARGV[1] ) {
21  if (m/^c\d{1,}$/i) {
22    s/c//ig;
23    $columns->{$_} = --$_;
24  }
25}
26
27die "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
29my $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
41open (OUT, ">$ARGV[4]") or die "Cannot create $ARGV[4]:$!\n";
42open (IN,  "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n";
43while (<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}
56close IN;
57
58close OUT;
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。