annotate tools/filters/fixedValueColumn.pl @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #! /usr/bin/perl -w
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 use strict;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 use warnings;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 # fixedValueColumn.pl $input $out_file1 "expression" "iterate [yes|no]"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 my ($input, $out_file1, $expression, $iterate) = @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 my $i = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 my $numeric = 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 die "Check arguments\n" unless @ARGV == 4;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 open (DATA, "<$input") or die "Cannot open $input:$!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 open (OUT, ">$out_file1") or die "Cannot create $out_file1:$!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 if ($expression =~ m/^\d+$/) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 $numeric = 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 $i = $expression;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 while (<DATA>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 chop;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 if ($iterate eq "no") {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 print OUT "$_\t$expression\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 } else {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 print OUT "$_\t$i\n" if $numeric == 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 print OUT "$_\t$expression-$i\n" if $numeric == 0;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 ++$i;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 close DATA;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 close OUT;