def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"'%phrase, database='ChEMBL', limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        name = annotation['property:name']
                        if 'property:moleculeType' in annotation:
                            name += ' ({0})'.format(annotation['property:moleculeType'])
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(name, entry)

        if len(xhtml) > 0:
            xhtml = '<style>.formula {font-weight:bold; font-size: 1.2em;}</style>' + xhtml
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'ChEMBL'
            annotation['property:description'] = 'Related bioactive small molecules'
            annotation['property:sourceDatabase'] = 'chembl'
            annotation['property:sourceDescription'] = '<p><a href="https://www.ebi.ac.uk/chembl/">ChEMBL</a> is a database of bioactive drug-like small molecules.</p>'
            annotation['displayRelevance']='1000'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"'%phrase, database='UniProt', limit='30')

        xhtml = ''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations[:10]:
                for result in group.annotations[:10]:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    annotation['property:sourceDatabase'] = 'uniprot'
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format('UniProt entry %s' % annotation.get('property:mnemonic', '???'), entry)

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'UniProt sequences'
            annotation['property:description'] = 'Protein sequence information'
            annotation['property:sourceDatabase'] = 'uniprot'
            annotation['property:sourceDescription'] = '<p>The Universal Protein Resource (<a href="http://www.uniprot.org/">UniProt</a>) is a comprehensive resource for protein sequence and annotation data.</p>'
            annotation['displayRelevance']='700'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"'%phrase, database='PDB', limit='30')

        xhtml = ''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    annotation['property:sourceDatabase'] = 'pdb'
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(annotation['property:name'], entry)

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'Protein Data Bank structures'
            annotation['property:description'] = 'Biological macromolecular structures'
            annotation['property:sourceDatabase'] = 'pdb'
            annotation['property:sourceDescription'] = '<p>The <a href="http://www.rcsb.org/">Protein Data Bank</a> of the Research Collaboratory for Structural Bioinformatics (<a href="http://home.rcsb.org/">RCSB</a>).</p>'
            annotation['displayRelevance']='800'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"'%phrase, database='Glick', limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    annotation['property:sourceDatabase'] = 'glick'
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(annotation['property:name'], entry)

        if len(xhtml) > 0:
            xhtml += '<p><em>(Glick Glossary/Portland Press Ltd.)</em></p>'

            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'Glick glossary entries'
            annotation['property:description'] = 'Biomedical definitions'
            annotation['property:sourceDatabase'] = 'glick'
            annotation['property:sourceDescription'] = '<p>David M. Glick\'s <a href="http://www.portlandpress.com/pp/books/online/glick/search.htm">Glossary of Biochemistry and Molecular Biology</a>.</p><p>Made available by <a href="http://www.portlandpress.com/">Portland Press Limited</a>.</p>'
            annotation['displayRelevance']='1000'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"'%phrase, database='drugbank', limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        name = annotation['property:name']
                        if 'property:entryType' in annotation:
                            name += ' ({0})'.format(annotation['property:entryType'])
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(name, entry)

        if len(xhtml) > 0:
            xhtml = '<style>.formula {font-weight:bold; font-size: 1.2em;} .formula sub{font-size:xx-small; position:relative; bottom:-0.3em;}</style>' + xhtml
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'DrugBank'
            annotation['property:description'] = 'Related drugs and their targets'
            annotation['property:sourceDatabase'] = 'drugbank'
            annotation['property:sourceDescription'] = '<p><a href="http://www.drugbank.ca">DrugBank</a> is a database that combines detailed drug data with comprehensive drug target information.</p>'
            annotation['displayRelevance']='1000'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase.strip(),
                                    database='genecards',
                                    limit='30')

        xhtml = u''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations[:10]:
                for result in group.annotations[:10]:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    annotation['property:sourceDatabase'] = 'genecards'
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        symbol = annotation.get('property:geneSymbol', u'')
                        name = annotation.get('property:geneName', u'')
                        if name:
                            name = u'(%s)' % name

                        #print symbol
                        #print type(symbol)

                        #print name
                        #print type(name)

                        xhtml += u'<div class="expandable" title="Gene {0} {1}">{2}</div>'.format(
                            symbol, name, entry)

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'GeneCards'
            annotation['property:description'] = 'Human genomic information'
            annotation['property:sourceIcon'] = utopia.get_plugin_data_as_url(
                'images/genecards.png', 'image/png')
            annotation[
                'property:sourceDescription'] = '<p><a href="http://www.genecards.org">GeneCards</a> is a database of concise genomic related information on all known and predicted human genes.</p>'
            annotation['displayRelevance'] = '700'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase,
                                    database='drugbank',
                                    limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        name = annotation['property:name']
                        if 'property:entryType' in annotation:
                            name += ' ({0})'.format(
                                annotation['property:entryType'])
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(
                            name, entry)

        if len(xhtml) > 0:
            xhtml = '<style>.formula {font-weight:bold; font-size: 1.2em;} .formula sub{font-size:xx-small; position:relative; bottom:-0.3em;}</style>' + xhtml
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'DrugBank'
            annotation[
                'property:description'] = 'Related drugs and their targets'
            annotation['property:sourceDatabase'] = 'drugbank'
            annotation[
                'property:sourceDescription'] = '<p><a href="http://www.drugbank.ca">DrugBank</a> is a database that combines detailed drug data with comprehensive drug target information.</p>'
            annotation['displayRelevance'] = '1000'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase,
                                    database='ChEMBL',
                                    limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        name = annotation['property:name']
                        if 'property:moleculeType' in annotation:
                            name += ' ({0})'.format(
                                annotation['property:moleculeType'])
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(
                            name, entry)

        if len(xhtml) > 0:
            xhtml = '<style>.formula {font-weight:bold; font-size: 1.2em;}</style>' + xhtml
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'ChEMBL'
            annotation[
                'property:description'] = 'Related bioactive small molecules'
            annotation['property:sourceDatabase'] = 'chembl'
            annotation[
                'property:sourceDescription'] = '<p><a href="https://www.ebi.ac.uk/chembl/">ChEMBL</a> is a database of bioactive drug-like small molecules.</p>'
            annotation['displayRelevance'] = '1000'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase.strip(), database='genecards', limit='30')

        xhtml = u''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations[:10]:
                for result in group.annotations[:10]:
                    annotation=kend.converter.Annotation.kend2spineapi(result)
                    annotation['property:sourceDatabase'] = 'genecards'
                    entry = self.visualiser.visualisable(annotation) and self.visualiser.visualise(annotation) or ''
                    if len(entry) > 0:
                        symbol=annotation.get('property:geneSymbol', u'')
                        name=annotation.get('property:geneName', u'')
                        if name:
                            name=u'(%s)' % name

                        #print symbol
                        #print type(symbol)

                        #print name
                        #print type(name)

                        xhtml += u'<div class="expandable" title="Gene {0} {1}">{2}</div>'.format(symbol, name, entry)

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'GeneCards'
            annotation['property:description'] = 'Human genomic information'
            annotation['property:sourceIcon'] = utopia.get_plugin_data_as_url('images/genecards.png', 'image/png')
            annotation['property:sourceDescription'] = '<p><a href="http://www.genecards.org">GeneCards</a> is a database of concise genomic related information on all known and predicted human genes.</p>'
            annotation['displayRelevance']='700'
            annotation['displayRank']="%d" % -len(annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []
        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase,
                                    database='Glick',
                                    limit='30')

        xhtml = ''

        # Query to see if a page is returned
        # Extent information needs to be included FIXME
        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    annotation['property:sourceDatabase'] = 'glick'
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(
                            annotation['property:name'], entry)

        if len(xhtml) > 0:
            xhtml += '<p><em>(Glick Glossary/Portland Press Ltd.)</em></p>'

            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'Glick glossary entries'
            annotation['property:description'] = 'Biomedical definitions'
            annotation['property:sourceDatabase'] = 'glick'
            annotation[
                'property:sourceDescription'] = '<p>David M. Glick\'s <a href="http://www.portlandpress.com/pp/books/online/glick/search.htm">Glossary of Biochemistry and Molecular Biology</a>.</p><p>Made available by <a href="http://www.portlandpress.com/">Portland Press Limited</a>.</p>'
            annotation['displayRelevance'] = '1000'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase,
                                    database='UniProt',
                                    limit='30')

        xhtml = ''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations[:10]:
                for result in group.annotations[:10]:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    annotation['property:sourceDatabase'] = 'uniprot'
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        xhtml += u'<div class="expandable" title="{0}">{1}</div>'.format(
                            'UniProt entry %s' %
                            annotation.get('property:mnemonic', '???'), entry)

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'UniProt sequences'
            annotation['property:description'] = 'Protein sequence information'
            annotation['property:sourceDatabase'] = 'uniprot'
            annotation[
                'property:sourceDescription'] = '<p>The Universal Protein Resource (<a href="http://www.uniprot.org/">UniProt</a>) is a comprehensive resource for protein sequence and annotation data.</p>'
            annotation['displayRelevance'] = '700'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results
    def on_explore_event(self, phrase, document):
        results = []

        client = kend.client.Client()

        annotations = client.lookup(term='"%s"' % phrase,
                                    database='PDB',
                                    limit='30')

        xhtml = ''

        if annotations is not None and len(annotations) >= 1:
            for group in annotations:
                for result in group.annotations:
                    annotation = kend.converter.Annotation.kend2spineapi(
                        result)
                    annotation['property:sourceDatabase'] = 'pdb'
                    entry = self.visualiser.visualisable(
                        annotation) and self.visualiser.visualise(
                            annotation) or ''
                    if len(entry) > 0:
                        xhtml += entry

        if len(xhtml) > 0:
            annotation = spineapi.Annotation()
            annotation['concept'] = 'Collated'
            annotation['property:html'] = xhtml
            annotation['property:name'] = 'Protein Data Bank structures'
            annotation[
                'property:description'] = 'Biological macromolecular structures'
            annotation['property:sourceDatabase'] = 'pdb'
            annotation[
                'property:sourceDescription'] = '<p>The <a href="http://www.rcsb.org/">Protein Data Bank</a> of the Research Collaboratory for Structural Bioinformatics (<a href="http://home.rcsb.org/">RCSB</a>).</p>'
            annotation['displayRelevance'] = '800'
            annotation['displayRank'] = "%d" % -len(
                annotation['property:name'])
            results.append(annotation)

        return results