# clustdist2benzer.pl
# convert clustalw's distance matrix into jBenzer input format.
# N. Khiripet, NECTEC
# Bioquest Summer Workshop 2004
# usage: perl clustdist2benzer.pl infile threshold > outfile

if ($#ARGV+1 != 2) {
	print "usage: clusdist2benzer.pl infile threshold";
	exit;
}

$threshold = $ARGV[1];
@list;
open(FH,$ARGV[0]) or die "Cannot open ".$ARGV[0]."\n";
while (<FH>) {
	chomp;
	if (/(\S+)\s+\(\d+\)/) {
		$name = $1;
		@t=map(0+($_ < $threshold),($' =~ /(\S+)/g));
		push @list, join(',',@t).','.$name;
	}
}

#printing out the output
print "JBENZER\n";
print $#list+1,"\n";
print join("\n",@list),"\n";