annotate cutWrapper.pl @ 1:f848742a0c1a 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:37:57 -0400
parents aa367513335f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
1 #!/usr/bin/perl -w
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
2
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
3 use strict;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
4 use warnings;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
5
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
6 my @columns = ();
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
7 my $del = "";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
8 my @in = ();
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
9 my @out = ();
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
10 my $command = "";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
11 my $field = 0;
1
f848742a0c1a 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;
f848742a0c1a 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;
f848742a0c1a 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
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
15
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
16 # a wrapper for cut for use in galaxy
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
17 # cutWrapper.pl [filename] [columns] [delim] [output]
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
18
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
19 die "Check arguments\n" unless @ARGV == 4;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
20
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
21 $ARGV[1] =~ s/\s+//g;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
22 foreach ( split /,/, $ARGV[1] ) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
23 if (m/^c\d{1,}$/i) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
24 push (@columns, $_);
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
25 $columns[@columns-1] =~s/c//ig;
1
f848742a0c1a 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) {
f848742a0c1a 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(/-/, $_);
f848742a0c1a 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;
f848742a0c1a 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;
f848742a0c1a 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) {
f848742a0c1a 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);
f848742a0c1a planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit e3d5231ad1ca93ad49117e9804266f371d863e82
devteam
parents: 0
diff changeset
32 }
0
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
33 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
34 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
35
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
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;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
37
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
38 my $column_delimiters_href = {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
39 'T' => q{\t},
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
40 'C' => ",",
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
41 'D' => "-",
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
42 'U' => "_",
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
43 'P' => q{\|},
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
44 'Dt' => q{\.},
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
45 'Sp' => q{\s+}
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
46 };
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
47
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
48 $del = $column_delimiters_href->{$ARGV[2]};
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
49
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
50 open (OUT, ">$ARGV[3]") or die "Cannot create $ARGV[2]:$!\n";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
51 open (IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
52
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
53 while (my $line=<IN>) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
54 if ($line =~ /^#/) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
55 #Ignore comment lines
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
56 } else {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
57 chop($line);
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
58 @in = split(/$del/, $line);
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
59 foreach $field (@columns) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
60 if (defined($in[$field-1])) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
61 push(@out, $in[$field-1]);
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
62 } else {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
63 push(@out, ".");
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
64 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
65 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
66 print OUT join("\t",@out), "\n";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
67 @out = ();
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
68 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
69 }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
70
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
71 #while (<IN>) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
72 # chop;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
73 # @in = split /$del/;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
74 # foreach $field (@columns) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
75 # if (defined($in[$field-1])) {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
76 # push(@out, $in[$field-1]);
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
77 # } else {
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
78 # push(@out, ".");
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
79 # }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
80 # }
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
81 # print OUT join("\t",@out), "\n";
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
82 # @out = ();
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
83 #}
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
84 close IN;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
85
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
86 close OUT;
aa367513335f planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cut_columns commit 5a4e0ca9992af3a6e5ed2b533f04bb82ce761e0b
devteam
parents:
diff changeset
87