#!/usr/bin/perl -w

system("mkdir One_Taxa");
system("mkdir Two_Taxa");
system("mkdir Three_Taxa");
system("mkdir Four_Taxa");
system("mkdir Five_Taxa");
while(defined($group=glob("*.faa"))) #formatdb cycle
{
	open(IN, "< $group") or die "cannot open $group:$!";
#	open(OUT, "> $group.fna") or die "cannot open $group.remove:$!";
	$count = 0;
	%taxa = ();
	while(defined($line=<IN>))
	{
		if ($line=~/^>/)
		{
			chomp($line);
			$line =~ s/\>//g;
			@Header1 = split(/\./,$line);
			$name = $Header1[-3];
			if(exists($taxa{$name}))
			{}				
			else
			{
				$taxa{$name} = 0;
				$count += 1;
			}
		}	
	}
	close(IN);
	if ($count == 1)
	{
		system("cp $group ./One_Taxa");
	}
	elsif ($count == 2)
	{
		system("cp $group ./Two_Taxa");
	}
	elsif ($count == 3)
	{
		system("cp $group ./Three_Taxa");
	}
	elsif ($count == 4)
	{
		system("cp $group ./Four_Taxa");
	}
	elsif ($count == 5)
	{
		system("cp $group ./Five_Taxa");
	}
	elsif ($count == 6)
	{
		print "OOPS!\t$group\tcount = $count\n";
	}
}