ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/gclib/scripts/trcol.pl
Revision: 24
Committed: Tue Jul 26 21:46:39 2011 UTC (13 years, 1 month ago) by gpertea
File size: 1269 byte(s)
Log Message:
Line User Rev File contents
1 gpertea 23 #!/usr/bin/perl
2     use strict;
3     use Getopt::Std;
4     #use FindBin;use lib $FindBin::Bin;
5    
6     my $usage = q/Usage:
7    
8     cat tab_delim_file | trcol.pl [-c <col#>] [-G] <map_file>
9    
10     Replaces (translates) column <col#> (default 1) from tab delimited
11     input with the corresponding string according to the word
12     translation table in <map_file>, which is a simple space delimited,
13     two column mapping table of the format:
14    
15     <string_to_find> <replacement>
16    
17     Use -G option if the input is GFF3 format and to only output the
18     replaced column and the value of the ID field for the mRNA
19     features only.
20    
21    
22     /;
23     umask 0002;
24     getopts('Gc:') || die($usage."\n");
25     my $replcol=$Getopt::Std::opt_c || 1; #column to replace
26     my $gffmap=$Getopt::Std::opt_G;
27     $replcol--;
28     die("$usage\n") if $replcol<0;
29     my $xtable=$ARGV[0];
30     die ("$usage\n") unless $xtable && -f $xtable;
31     my %xw;
32     open(XTBL, $xtable) || die ("Error opening file $xtable!\n");
33     while (<XTBL>) {
34     chomp;
35     next unless $_;
36     my @t=split;
37     $xw{$t[0]}=$t[1];
38     }
39     while (<STDIN>) {
40     chomp;
41     my @t=split(/\t/);
42     my $tx=$xw{$t[$replcol]};
43     $t[$replcol]=$tx if $tx;
44     if ($gffmap) {
45     next unless m/ID=([^;]+)/;
46     my $id=$1;
47     $id=~s/\.\w+\d$//;
48     print $t[$replcol]."\t$id\n";
49     }
50     else {
51     print join("\t",@t)."\n";
52     }
53     }

Properties

Name Value
svn:executable *