gggg has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I am having two input files where I have to match columns 1,2,3 of one infile with columns 2,3,4 of second and i have to print for the matched lines the values in column 4 of second infile. I have made two separate arrays for each infile . Here is the script below :
use strict; use warnings; my $infile1 = $ARGV[0]; my $infile2 = $ARGV[1]; my $outfile = $ARGV[2]; unless (open( INFILE1, $infile1)) { die "Cannot open $infile1\n"; } my @array; my @slice; my @array1; my @slice1; my $element; while(<INFILE1>) { chomp; my @array = split ('\t', $_); my @slice = @array[0,1,2]; } open (INFILE2, "<", $infile2) || die "cannot open $infile2"; open (OFILE, ">", $outfile) || die "cannot open $outfile"; my $i = 0; while (<INFILE2>) { chomp; my @array1 = split ('\t', $_); my @slice1 = @array1[1,2,3,4]; $slice1[0] = s/chr//g; for ($i=0; $i < $#slice1; $i++) { foreach my $element (@slice) { print OFILE $slice1[3] ."\n"; } else { print OFILE "NA\n"; } } } }
Any help would be appreciated. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Matching columns between files
by toolic (Bishop) on Jun 25, 2011 at 20:50 UTC | |
by gggg (Initiate) on Jun 25, 2011 at 21:15 UTC | |
|
Re: Matching columns between files
by graff (Chancellor) on Jun 26, 2011 at 03:43 UTC | |
|
Re: Matching columns between files
by bluescreen (Friar) on Jun 25, 2011 at 23:04 UTC | |
by gggg (Initiate) on Jun 26, 2011 at 12:39 UTC | |
by Anonymous Monk on Jun 26, 2011 at 13:11 UTC | |
by gggg (Initiate) on Jun 26, 2011 at 14:07 UTC | |
by Anonymous Monk on Jun 26, 2011 at 14:32 UTC |