def get_goa_gene_sets(go_annotations):
go_term_genes = OrderedDict()<EOL>term_ids = {}<EOL>for ann in go_annotations:<EOL><INDENT>term_ids[ann.go_term.id] = ann.go_term<EOL>try:<EOL><INDENT>go_term_genes[ann.go_term.id].append(ann.db_symbol)<EOL><DEDENT>except KeyError:<EOL><INDENT>go_term_genes[ann.go_term.id] = [ann.db_symbol]<EOL><DEDENT><DEDENT>go_term_genes = OrderedDict(sorted(go_term_genes.items()))<EOL>gene_sets = []<EOL>for tid, genes in go_term_genes.items():<EOL><INDENT>go_term = term_ids[tid]<EOL>gs = GeneSet(id=tid, name=go_term.name, genes=genes,<EOL>source='<STR_LIT>',<EOL>collection=go_term.domain_short,<EOL>description=go_term.definition)<EOL>gene_sets.append(gs)<EOL><DEDENT>gene_sets = GeneSetCollection(gene_sets)<EOL>return gene_sets<EOL>
Generate a list of gene sets from a collection of GO annotations.

    Each gene set corresponds to all genes annotated with a certain GO term.