#!/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 () { # 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=; while () { # 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=; while () { # 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]}); } }