#ngmerge.pl #Yasuhiro Kondo # ver 1.1 # 20010320 use IO::File; $max ="\xffff"; sub extcut { @s = split(/\./,$_[0]); $s[0]; } sub min { my($min,$real_min, $test,$real_test,$hindo,$count,$out_num,$length,$out_hindo); $min = shift(@_); ($hindo,$real_min,$length) = split(/\t/,$min); $count = 0; $out_num = $count; $out_hindo = $hindo; foreach $test (@_) { $count++; ($hindo,$real_test,$length) = split(/\t/,$test); if ($real_test lt $real_min ) { $real_min = $real_test; $out_hindo = $hindo; $out_num = $count; } } ($real_min,$out_hindo,$out_num); } foreach (@ARGV) { push @handles, new IO::File($_); } foreach $handle(@handles){ my ($s); chomp($s = <$handle>); push(@line,$s); } $count = 0; while( $prev_min_str ne $max ){ $count++; ($min_str,$hindo,$number) = &min(@line); if ($prev_min_str eq $min_str){ for ($i = ($last_number + 1) ;$i <= $number ;$i++){ if ($i == $number){ $output = $output . &extcut($ARGV[$i]) . ":" . $hindo . " "; } else { $output = $output . &extcut($ARGV[$i]) . ":" . "0" . " "; } } $last_number = $number; } else { if (($prev_min_str ne $max) && ($count != 1)){ for ($i = ($last_number + 1) ;$i < @ARGV ;$i++){ $output = $output . &extcut($ARGV[$i]) . ":" . "0" . " "; } printf("%s)\n",$output); } $output = $min_str . "\t( " ; for ($i = 0;$i <= $number; $i++){ if ($i == $number){ $output = $output . &extcut($ARGV[$i]) . ":" . $hindo . " "; } else { $output = $output . &extcut($ARGV[$i]) . ":" . "0" . " "; } } $last_number = $number; $prev_min_str = $min_str; } $handle = $handles[$number]; if (!eof($handle)){ $line[$number] = <$handle>; chomp $line[$number]; } else { $line[$number] = "" . "\t" . $max . "\t" . ""; } } foreach $handle(@handles){ close($handle); }