use strict;
use warnings;

open(FILEH, "<", $ARGV[0]);
my $no_orths = $ARGV[1];

my $orth_capture = 0;
my ($locus, @orths, $orth);
while (my $line = <FILEH>){
    if($line =~ /\/locus_tag=\"(.+)\"/){
	if(scalar @orths == $no_orths){
	    print "$locus\t";
	    foreach my $o (@orths){
		print "$o\t";
	    }
	    print "\n";
	}
	$locus = $1;
	@orths = ();
    }
    if ($orth_capture){
	if($line =~ /FT\s+(.+)\"/){
	    my $x = $1;
	    chomp $x;
	    $orth .= $x;
	    $orth_capture = 0;
	    $orth =~ /tmp:(.+);/;
	    push(@orths, $1);
	}
	else{
	    $line =~ /FT\s+(.+)/;
	    chomp $1;
	    $orth .= $1;
	}
    }
    if ($line =~ /\/ortholog=\"(.+)/){
	$orth = $1;
	chomp $orth;
	$orth_capture = 1;
    }
    
}
