go_acp = {};
apc_st4svm_ago = [];
apc_st4svm_agop = [];

for i=1:39
    fid=fopen(sprintf('gene-clus/genes-clus%02d.txt.amigo_results', i));
    go_amigo = textscan(fid, '%s %c %s %n %n %n %n %n %*s', 'Whitespace', '\t');
    fclose(fid);
    fprintf('Parsed %02d: %s', i, go_amigo{1}{1});
    if isempty(strmatch('GO', go_amigo{1}{1})),
        fprintf(' -> ERROR\n');
        continue;
    else
        fprintf('\n');
    end
    for j=1:length(go_amigo{1})
        if go_amigo{2}(j) == 'P',
            go_acpno = strmatch(go_amigo{1}{j}, {go_acp{:,1}});
            if isempty(go_acpno),
                go_acpno = size(go_acp, 1) + 1;
                go_acp{go_acpno,1} = go_amigo{1}{j};
                go_acp{go_acpno,2} = go_amigo{3}{j};
                apc_st4svm_ago = [apc_st4svm_ago; zeros(1,39)];
                apc_st4svm_agop = [apc_st4svm_agop; zeros(1,39)];
                % fprintf('Adding at %d to increase go_acp %d with %s -> size=%d\n', j, go_acpno, go_amigo{3}{j}, size(apc_st4svm_ago,1));
            end
            
            gohy_m = go_amigo{8}(j);
            gohy_n = go_amigo{6}(j);
            gohy_k = go_amigo{7}(j);
            gohy_x = go_amigo{5}(j);

            apc_st4svm_ago(go_acpno,i) = hygepdf(gohy_x, gohy_m, gohy_k,  gohy_n) / sum(hygepdf(gohy_x:gohy_k, gohy_m, gohy_k,  gohy_n)) * 100;
            apc_st4svm_agop(go_acpno,i) = gohy_x / gohy_n;
        end
    end
    %break;
end


for i=1:39,
    fprintf('Cluster %d: ', i);
    for j=1:length(go_acp),
        if apc_st4svm_ago(j,i) >= 90
            fprintf(' %s (%1.2f/%2.0f%%),', go_acp{j,2}, apc_st4svm_agop(j,i), apc_st4svm_ago(j,i));
        end
    end
    fprintf('\n\n');
end