in reply to sorting and other problems in hash
use strict; use warnings; my $fh; open $fh, '<', 'file2.txt' or die "cant open file2.txt: $!"; my %info; while (<$fh>) { if (/^>(.*)_left\s\w+=(\d+)/) { $info{$1}{left} = $2; } if (/^>(.*)_right\s\w+=(\d+)/) { $info{$1}{right} = $2; } } close $fh; # comparing with file 1 open $fh, '<', 'file1.txt' or die "cant open file1.txt: $!"; my $id; while (<$fh>) { if (/^>(\w+)/) { $id = $1; } else { my @nums = split; my $len = $info{$id}{left}; print ">${id}_left length=$len\n"; print "@nums[0..($len-1)]\n"; $len = $info{$id}{right}; print ">${id}_right length=$len\n"; print "@nums[($#nums-$len)..$#nums]\n"; } } __END__ >AAAT3R_left length=6 40 40 40 40 40 40 >AAAT3R_right length=62 40 40 40 40 40 40 38 38 37 39 36 36 40 36 35 35 35 38 40 35 35 33 35 3 +5 35 40 40 40 40 37 37 38 38 38 40 40 40 40 40 40 40 40 40 40 40 40 4 +0 40 40 40 37 36 36 31 22 22 22 20 20 20 20 20 14 >AAA2OJ_left length=14 18 18 18 21 35 35 35 32 32 32 33 35 38 39 >AAA2OJ_right length=14 37 37 37 37 37 37 33 32 32 30 20 17 17 17 0
|
|---|