Mercurial > repos > devteam > cut_columns
annotate cutWrapper.pl @ 3:cec635fab700 draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
| author | devteam |
|---|---|
| date | Fri, 05 Aug 2016 16:38:13 -0400 |
| parents | 34c29e183ef7 |
| children |
| rev | line source |
|---|---|
| 0 | 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; | |
|
3
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
12 my $start = 0; |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
13 my $end = 0; |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
14 my $i = 0; |
| 0 | 15 |
| 16 # a wrapper for cut for use in galaxy | |
| 17 # cutWrapper.pl [filename] [columns] [delim] [output] | |
| 18 | |
| 19 die "Check arguments\n" unless @ARGV == 4; | |
| 20 | |
| 21 $ARGV[1] =~ s/\s+//g; | |
| 22 foreach ( split /,/, $ARGV[1] ) { | |
| 23 if (m/^c\d{1,}$/i) { | |
| 24 push (@columns, $_); | |
| 25 $columns[@columns-1] =~s/c//ig; | |
|
3
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
26 } elsif (m/^c\d{1,}-c\d{1,}$/i) { |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
27 ($start, $end) = split(/-/, $_); |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
28 $start =~ s/c//ig; |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
29 $end =~ s/c//ig; |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
30 for $i ($start .. $end) { |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
31 push (@columns, $i); |
|
cec635fab700
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents:
0
diff
changeset
|
32 } |
| 0 | 33 } |
| 34 } | |
| 35 | |
| 36 die "No columns specified, columns are not preceded with 'c', or commas are not used to separate column numbers: $ARGV[1]\n" if @columns == 0; | |
| 37 | |
| 38 my $column_delimiters_href = { | |
| 39 'T' => q{\t}, | |
| 40 'C' => ",", | |
| 41 'D' => "-", | |
| 42 'U' => "_", | |
| 43 'P' => q{\|}, | |
| 44 'Dt' => q{\.}, | |
| 45 'Sp' => q{\s+} | |
| 46 }; | |
| 47 | |
| 48 $del = $column_delimiters_href->{$ARGV[2]}; | |
| 49 | |
| 50 open (OUT, ">$ARGV[3]") or die "Cannot create $ARGV[2]:$!\n"; | |
| 51 open (IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n"; | |
| 52 | |
| 53 while (my $line=<IN>) { | |
| 54 if ($line =~ /^#/) { | |
| 55 #Ignore comment lines | |
| 56 } else { | |
| 57 chop($line); | |
| 58 @in = split(/$del/, $line); | |
| 59 foreach $field (@columns) { | |
| 60 if (defined($in[$field-1])) { | |
| 61 push(@out, $in[$field-1]); | |
| 62 } else { | |
| 63 push(@out, "."); | |
| 64 } | |
| 65 } | |
| 66 print OUT join("\t",@out), "\n"; | |
| 67 @out = (); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 #while (<IN>) { | |
| 72 # chop; | |
| 73 # @in = split /$del/; | |
| 74 # foreach $field (@columns) { | |
| 75 # if (defined($in[$field-1])) { | |
| 76 # push(@out, $in[$field-1]); | |
| 77 # } else { | |
| 78 # push(@out, "."); | |
| 79 # } | |
| 80 # } | |
| 81 # print OUT join("\t",@out), "\n"; | |
| 82 # @out = (); | |
| 83 #} | |
| 84 close IN; | |
| 85 | |
| 86 close OUT; | |
| 87 |
