#!/usr/bin/perl -w use warnings; use strict; # 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]; $bwa{$ID}[0] = $line[0]; # seq ID $bwa{$ID}[1] = $line[2]; # Ref ID $bwa{$ID}[2] = $line[5]; # CIGAR ID for insertion #$bwa{$ID}[3] = @line[9]; # Processed seq (already C->T) $bwa{$ID}[3] = $line[12]; # Edit distance (edited area by # of base) : NM $bwa{$ID}[4] = $line[15]; # No. of mismatches in the alignment : XM $bwa{$ID}[5] = $line[16]; # No. of gap opens for insertion : XO $bwa{$ID}[6] = $line[17]; # No. of gap extensions for deletion :XG $bwa{$ID}[7] = $line[18]; # Mismatching positions / bases : MD } } } 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}[0] = $ID; $Amp{$ID}[1] = $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}[0] = $ID; $Input{$ID}[1] = $Seq; } close FILE3 || die "Failed to close $file3 : $!"; foreach my $ID (keys %bwa) { print "1"; if (exists $Input{$ID}[0] ){ print "2"; if ($bwa{$ID}[0] eq $Input{$ID}[0]){ print "3"; if ($bwa{$ID}[1] eq $Amp{$ID}[0]){ print "4"; if ($bwa{$ID}[3] eq "NM:i:0" && $bwa{$ID}[4] eq "XM:i:0" && $bwa{$ID}[5] eq "XO:i:0" && $bwa{$ID}[6] eq "XG:1:0") { print "$Amp{$ID}[1]\n$Input{$ID}[1]"; } else {print "4out";} } else {print "3out";} } else {print "2out";} } else {print "1out";} } exit;