my %bwa = (); my @splitstore=(); my @s1 = (); my @s2 = (); my @s3 = (); my @s4 = (); my @s5 = (); my $ssl=(0); my $splitstoreD=(0); my $splitstoreI=(0); 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[0,2,5,12,15,16,17,18,3]; #$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 #$bwa{$ID}[8] = $line[3]; # Starting position # These are not from my input, I made these so I can save some data for parsing the CIGAR ID. #$bwa{$ID}[10] = Total Number of Bases #$bwa{$ID}[11] = Deletion (0 if no) #$bwa{$ID}[12] = Insertion (0 if no) #$bwa{$ID}[13] = Number of bases until deletion #$bwa{$ID}[14] = Number of bases until insertion # Modifying CIGAR ID's to keep track of matches, deletions, insertions @splitstore = split /[A-Z]/, $bwa{$ID}[2]; if ($bwa{$ID}[2] =~ /[D]/) { $splitstoreD = 1; } else { $splitstoreD = 0 } if ($bwa{$ID}[2] =~ /[I]/) { $splitstoreI = 1; } else { $splitstoreI = 0 } #Storing Total Bases $ssl = scalar @splitstore; if($ssl>1){ if ($ssl>4){ #If there is both a deletion and insertion... $bwa{$ID}[10] = $splitstore[0]+$splitstore[2]+$splitstore[$ssl-1]; #add first, third and last nubmers to get total bases } else{ $bwa{$ID}[10] = $splitstore[0]+$splitstore[$ssl-1];} #add first and last numbers to get total bases } else { $bwa{$ID}[10] = $splitstore[0]; } #just the first number #Defining Deletions if($splitstoreD == 1) { $bwa{$ID}[11]="Del" } else { $bwa{$ID}[11]=0 } #Defining Insertions if($splitstoreI == 1) { $bwa{$ID}[12]="Ins" } else { $bwa{$ID}[12]=0 } #Defining Position of Deletion if ($bwa{$ID}[2] =~ /(\d*(?=D))/) { @s1 = split /(\d)/, $bwa{$ID}[2]; @s2 = split /(\d+M)/, @s1; @s3 = split /(\d+M)/, @s2; @s4 = split /(\d+I)/, @s3; @s5 = split /[D]/, @s4; $bwa{$ID}[13]=@s5; } print "@splitstore\t"; print "$splitstoreI\t"; print "$splitstoreD\t"; print "$bwa{$ID}[10]\n"; print "@s1\t"; print "@s2\t"; print "@s3\t"; print "@s4\t"; print "@s5\t"; print "$bwa{$ID}[13]\n"; @s1 = (); @s2 = (); @s3 = (); @s4 = (); @s5 = (); } } } close FILE1 || die "Failed to close $file1 : $!";