comparison tools/filters/joinWrapper.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 use File::Temp "tempfile";
6
7 my ($input1, $input2, $field1, $field2, $mode, $OOption, $out_file1) = @ARGV;
8
9 die "No arguments\n" unless @ARGV == 7;
10
11 my ($fh1, $file1) = tempfile();
12 my ($fh2, $file2) = tempfile();
13
14 `sort -k $field1 $input1 > $file1`;
15 `sort -k $field2 $input2 > $file2`;
16
17 my $option = "";
18 my @fields = ();
19 my $line = "";
20
21 if ($OOption eq "Y") {
22 if (defined($fh1)) {
23 $line = <$fh1>;
24 } else {
25 die "Failed to create file $file1\n";
26 }
27 @fields = split /\t/, $line;
28 die "The field you selected does not exist in the input file" if (@fields < $field1);
29 my @optionO = ();
30 my $i = 0;
31 foreach (@fields) {
32 ++$i;
33 push(@optionO, "1.$i");
34 }
35 $option = "-o " . join(",", @optionO);
36 } else {
37 $option = "";
38 }
39
40 $ENV{'LC_ALL'} = 'POSIX';
41
42 if ($mode eq "V") {
43 `join -v 1 $option -1 $field1 -2 $field2 $file1 $file2 | tr " " "\t" > $out_file1`;
44 } else {
45 `join $option -1 $field1 -2 $field2 $file1 $file2 | tr " " "\t" > $out_file1`;
46 }
47
48 `rm $file1 ; rm $file2`;
49
50
51