http://qs321.pair.com?node_id=855397


in reply to Matching strings from three files (three hashes)

FluffyBunny,

I think you are populating bwa hash with different values and you are comparing different values of bwa has with 0. As others suggested, use debugger or Dumper module to know what is in the populated hash.

I have tweaked in some of your code. Check out whether is this what you need. I am not able to understand your requirement correctly. You can modify the below code according to your requirement.

#!/usr/bin/perl -w use warnings; use strict; use Data::Dumper; # BWA alignment output (.sam) my %bwa = (); my $file1 = shift; open (FILE1, "$file1") || die "Failed to open $file1 for reading : $!" +; # Open second file while (<FILE1>) { # Reading second hash if ($_ =~ /^[^@]/s) { chomp; my @line = split /\s+/, $_; my $ID; if ($line[2] =~ /[^*]/) { $ID = $line[0]; push @{$bwa{$ID}}, @line[2,5,12,15,16,17,18]; } } } close FILE1 || die "Failed to close $file1 : $!"; # ORIGINAL Reference Amplicon File (.fa) my %Amp = (); my $file2 = shift; open (FILE2, "$file2")|| die "Failed to open $file2 for reading : $!"; + # Open first file local $/= ">"; my $first=<FILE2>; while (<FILE2>) { # Reading first hash chomp; my ($ID, $Seq) = split("\n"); $Amp{$ID} = $Seq } close FILE2 || die "Failed to close $file2 : $!"; # ORIGINAL Input FASTQ Sequencing File (.fq) my %Input = (); my $file3 = shift; open (FILE3, "$file3")|| die "Failed to open $file3 for reading : $!"; + # Open first file local $/= "@"; $first=<FILE3>; while (<FILE3>) { # Reading first hash chomp; my ($ID, $Seq,undef,undef) = split("\n"); $Input{$ID} = $Seq; } close FILE3 || die "Failed to close $file3 : $!"; foreach my $ID (keys %bwa) { if (exists $Input{$ID}){ print "Key : $ID\t AMP:\t$Amp{$bwa{$ID}[0]}\nInput\t$Input +{$ID}" if (exists $Amp{$bwa{$ID}[0]}); } }

Regards,
Murugesan Kandasamy
use perl for(;;);