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

リビジョン 2, 1.1 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 cut for use in galaxy
14# cutWrapper.pl [filename] [columns] [delim] [output]
15
16die "Check arguments\n" unless @ARGV == 4;
17
18$ARGV[1] =~ s/\s+//g;
19foreach ( split /,/, $ARGV[1] ) {
20  if (m/^c\d{1,}$/i) {
21    push (@columns, $_);
22    $columns[@columns-1] =~s/c//ig;
23  }
24}
25
26die "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
28my $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
40open (OUT, ">$ARGV[3]") or die "Cannot create $ARGV[2]:$!\n";
41open (IN,  "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n";
42while (<IN>) {
43  chop;
44  @in = split /$del/;
45  foreach $field (@columns) {
46    if (defined($in[$field-1])) {
47      push(@out, $in[$field-1]);
48    } else {
49      push(@out, ".");
50    }
51  }
52  print OUT join("\t",@out), "\n";
53  @out = ();
54}
55close IN;
56
57close OUT;
58   
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。