1.	#!/usr/bin/perl -w
2.	use strict;
3.	use SAPserver;
4.	use COserver;
5.	use SeedUtils;
6.	
7.	my $sapObject = SAPserver->new();
8.	
9.	my $genomeHash = $sapObject->all_genomes(-complete => 1);
10.	for my $genome (keys %$genomeHash) {
11.	    my $genomeName = $genomeHash->{$genome};
12.	    my $geneHash = $sapObject->feature_assignments(-genome => $genome,
13.	                                                   -type => 'peg');
14.	    my @hypotheticalGenes = grep { &SeedUtils::hypo($geneHash->{$_}) } sort keys %$geneHash;
15.	    my $couplingHash = $sapObject->conserved_in_neighborhood(-ids => \@hypotheticalGenes,
16.	                                                             -hash => 1);
17.	    for my $gene (@hypotheticalGenes) {
18.	        my $couplingList = $couplingHash->{$gene};
19.	        if (defined $couplingList) {
20.	            my $subHash = $sapObject->ids_to_subsystems(-ids => [ map { $_->[1]} @$couplingList ]);
21.	            my ($bestCoupler, $bestScore, $bestFunction) = (undef, 0, '');
22.	            for my $coupling (@$couplingList) {
23.	                my ($score, $coupler, $function) = @$coupling;
24.	                if ($subHash->{$coupler} && $score > $bestScore) {
25.	                    $bestCoupler = $coupler;
26.	                    $bestScore = $score;
27.	                    $bestFunction = $function;
28.	                }
29.	            }
30.	            if (defined $bestCoupler) {
31.	                print join("\t", $gene, $geneHash->{$gene}, $genome, $genomeName,
32.	                                 $bestCoupler, $bestScore, $bestFunction) . "\n";
33.	            }
34.	        }
35.	    }
36.	}