Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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(;;);


In reply to Re: Matching strings from three files (three hashes) by murugu
in thread Matching strings from three files (three hashes) by FluffyBunny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-25 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found