
%goHash = ();
%baseHash = ();
while( <BASE> ) {
    chomp;
    @vals = split /\t/;
    if($vals[2] ne "NA"){
        if(exists $baseHash{$vals[2]}){
	    $baseHash{$vals[2]} =  $baseHash{$vals[2]} . ";" . $vals[0]; 
        }else{
            $baseHash{$vals[2]} = $vals[0];
    	}
    }
}
close BASE;

$/ = ">>";
while( <DATA> ) {
    $locusid = "NA";
    $keep = 0;
    @lines = split("\n");

    foreach $x (@lines) {
	if( $x =~ /^LOCUSID/ ) {
    	    @temp = split/\s+/, $x;
	    if(exists $baseHash{$temp[1]}){
		$locusid = $temp[1];
		$keep = 1;
	    }
	    next;
	}
	if($keep == 1){
	    if( $x =~ /^GO/ ) {
	    @temp = split/\|/, $x;
	    if(exists $goHash{$temp[3]}){
		$goHash{$temp[3]} = $goHash{$temp[3]} . 
			";" . $baseHash{$locusid};
	    }else{
	        $goHash{$temp[3]} = $baseHash{$locusid};
	    }
	    next;
	    }
	}
    }
}

for $x(keys %goHash ){
    @temp = split/,/, $goHash{$x};
    print OUT $x, "\t", $goHash{$x},"\t",($#temp +1),"\n";
}
close DATA;


