
use strict;
use warnings;

my $file = shift;

my @species = @ARGV;

foreach my $s (@species) { 
    
    my $ortho_id = 0;

    open(my $F, "<", $file) || die "Can't open $file";

    my $output_file = $file.".".$s;
    open(my $G, ">", $output_file) || die "Can't open $output_file";

    while (<$F>) { # $_
	chomp();
	$ortho_id++;
	my @ids = split /\t/;
	
	my @match_ids = ();
	foreach my $id (@ids) { 
	    if ($id =~ /\|$s\_/i) {
		push @match_ids, $id;
	    }
	}
	
	if (@match_ids) { 
	    print $G (join "\t", ($ortho_id, scalar(@ids), @match_ids));
	    print $G "\n";
	}
    }
    close($F);
    close($G);
}


    

    
