################################################################ # Read the first file, break the first col to its components # # Expand the last two last numbers e.g. (591_592) plus/minus 8 # # Make a hash of multiple value for each key # # Print the numner of lines read and put into a variable # ################################################################ my %file1=(); while(){ chomp; (my $id, my $number) = split("\t", $_); if ($id=~ m/^(CLS_S3_Contig[0-9]+)([-]?)([0-9]+)([_]?)([0-9]+)$/i) { my $matched_id=$id; # breaks the CLS_Contig1000_200-202 to its componenents # and expands the second col plus minus 8 for (my $i=$3-8;$i<$5+8;$i++){ print join ("\t", $1, $i), "\n"; push (@{$file1{$1}}, $i); #make a hash of array } } } # Count the numnber of lines minus header line my $counter_1 = `wc -l < $ARGV[0]`; die "wc failed: $?" if $?; chomp($counter_1); my $counter = $counter_1 -1; #First file has a header row print "$counter lines read from $ARGV[0] file\n"; close(INPUT1); ########################################################### # Reading the Second file # ########################################################### print "Reading the 2nd file\n"; print "It may take a while, please wait...\n"; print "-----------------------------------\n"; while(){ chomp; my @current_line = split /\t/; foreach my $key (sort keys %file1){ foreach my $position1 (@{$file1{$key}}){ if ($current_line[0] eq $key) { if ($current_line[1] == $position1) { if ($current_line[2] ==1) { if ($current_line[3] >= 3) { print join ("\t", $current_line[0],$current_line[1],$current_line[2],$current_line[3], "***",$key, $position1), "\n"; } } } } } } } close (INPUT2);