comparison tools/filters/cutWrapper.pl @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9071e359b9a3
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 cut for use in galaxy
14 # cutWrapper.pl [filename] [columns] [delim] [output]
15
16 die "Check arguments\n" unless @ARGV == 4;
17
18 $ARGV[1] =~ s/\s+//g;
19 foreach ( split /,/, $ARGV[1] ) {
20 if (m/^c\d{1,}$/i) {
21 push (@columns, $_);
22 $columns[@columns-1] =~s/c//ig;
23 }
24 }
25
26 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;
27
28 my $column_delimiters_href = {
29 'T' => q{\t},
30 'C' => ",",
31 'D' => "-",
32 'U' => "_",
33 'P' => q{\|},
34 'Dt' => q{\.},
35 'Sp' => q{\s+}
36 };
37
38 $del = $column_delimiters_href->{$ARGV[2]};
39
40 open (OUT, ">$ARGV[3]") or die "Cannot create $ARGV[2]:$!\n";
41 open (IN, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n";
42
43 while (my $line=<IN>) {
44 if ($line =~ /^#/) {
45 #Ignore comment lines
46 } else {
47 chop($line);
48 @in = split(/$del/, $line);
49 foreach $field (@columns) {
50 if (defined($in[$field-1])) {
51 push(@out, $in[$field-1]);
52 } else {
53 push(@out, ".");
54 }
55 }
56 print OUT join("\t",@out), "\n";
57 @out = ();
58 }
59 }
60
61 #while (<IN>) {
62 # chop;
63 # @in = split /$del/;
64 # foreach $field (@columns) {
65 # if (defined($in[$field-1])) {
66 # push(@out, $in[$field-1]);
67 # } else {
68 # push(@out, ".");
69 # }
70 # }
71 # print OUT join("\t",@out), "\n";
72 # @out = ();
73 #}
74 close IN;
75
76 close OUT;
77