Exemplo n.º 1
0
def search_gene_names(request, key=None):
    '''
    get: render a form for user to search_gene_names the sequence id for a fasta sequence from a genome.
    post: redirect to a page which will show the id.
    key: used to pass a message (via the cache) 
    '''
    message = ''
    if request.method == 'POST': # If the form has been submitted...
        form = SearchGeneNamesForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            logging.debug(form.cleaned_data)
            search_type, query_string = form.cleaned_data['search_type'], form.cleaned_data['query_string']
            pairs = roundup_db.findGeneNameGenomePairsLike(
                webconfig.CURRENT_RELEASE, substring=query_string,
                searchType=search_type)
            # store result in cache, so can do a redirect/get. 
            key = makeUniqueId()
            roundup_util.cacheSet(key, {'search_type': search_type, 'query_string': query_string, 'pairs': pairs})
            # redirect the post to a get.  http://en.wikipedia.org/wiki/Post/Redirect/Get
            return django.shortcuts.redirect(django.core.urlresolvers.reverse(search_gene_names_result, kwargs={'key': key}))
    else:
        if key and roundup_util.cacheHasKey(key):
            # a message for the search page can be passed via the cache.
            kw = roundup_util.cacheGet(key)
            message = kw['message']
            form = SearchGeneNamesForm(kw) # A bound form
        else:        
            form = SearchGeneNamesForm() # An unbound form

    example = "{'search_type': 'contains', 'query_string': 'ata'}" # javascript
    return django.shortcuts.render(request, 'search_gene_names.html', {'message': message, 'form': form, 'nav_id': 'search_gene_names', 'form_doc_id': 'search_gene_names',
                                                            'form_action': django.core.urlresolvers.reverse(search_gene_names), 'form_example': example})
Exemplo n.º 2
0
def lookup_result(request, key):
    if roundup_util.cacheHasKey(key):
        kw = roundup_util.cacheGet(key)
        page = '<h2>Lookup a Sequence Id for a FASTA Sequence Result</h2>\n<h3>Query</h3>Genome: <pre>{}</pre>'.format(GENOME_TO_NAME[kw['genome']])
        page += 'FASTA Sequence: <pre>{}</pre>'.format(kw['fasta'])
        page += u'<h3>Result</h3>Sequence Id: {}'.format(kw['seqId'])
        return django.shortcuts.render(request, 'regular.html', {'html': page, 'nav_id': 'contact'})
    else:
        raise django.http.Http404
Exemplo n.º 3
0
def orth_query(request, queryId):
    '''
    run an orthology query to create a "result".
    GET: return a page which will get the result of the query.  either gets result from the cache or runs the query and stores the result in the cache.
    '''
    logging.debug('orth_query queryId={}'.format(queryId))

    if not roundup_util.cacheHasKey(queryId):
        raise django.http.Http404

    orthQuery = roundup_util.cacheGet(queryId)
    querySize = len(orthQuery['limit_genomes']) + len(orthQuery['genomes'])
    resultId = getResultId(queryId)
    resultPath = orthresult.getResultFilename(resultId)
    logging.debug(u'orth_query():\northQuery={}\nresultId={}\nqueryId={}\nresultPath={}'.format(orthQuery, resultId, queryId, resultPath))
    if USE_CACHE and roundup_util.cacheHasKey(resultId) and orthresult.resultExists(resultId):
        logging.debug('cache hit.')
        return django.shortcuts.redirect(django.core.urlresolvers.reverse(orth_result, kwargs={'resultId': resultId}))
    elif not webconfig.NO_LSF and lsf.isJobNameOn(resultId, retry=True, delay=0.2):
        logging.debug('cache miss. job is already running.  go to waiting page.')
        return django.shortcuts.redirect(django.core.urlresolvers.reverse(orth_wait, kwargs={'resultId': resultId}))
    elif webconfig.NO_LSF or querySize <= SYNC_QUERY_LIMIT:
        logging.debug('cache miss. run job sync.')
        # wait for query to run and store query
        roundup_util.do_orthology_query(cache_key=resultId,
                                        cache_file=resultPath,
                                        query_kws=orthQuery)
        return django.shortcuts.redirect(
            django.core.urlresolvers.reverse(orth_result,
                                             kwargs={'resultId': resultId}))
    else:
        logging.debug('cache miss. run job async.')
        # run on lsf and have result page poll for job completion
        roundup_util.bsub_orthology_query(cache_key=resultId,
                                          cache_file=resultPath,
                                          query_kws=orthQuery,
                                          job_name=resultId)
        return django.shortcuts.redirect(
            django.core.urlresolvers.reverse(orth_wait,
                                             kwargs={'resultId': resultId}))
Exemplo n.º 4
0
def search_gene_names_result(request, key):
    '''
    search_type: e.g. starts with, contains, etc.
    query: the substring to search for
    '''
    if roundup_util.cacheHasKey(key):
        kw = roundup_util.cacheGet(key)
        pairs = kw['pairs']
        page = '<h2>Gene Names Search Result</h2>\n'
        page += u'<p>Gene names that &quot;{}&quot; the query string &quot;{}&quot;:</p>\n'.format(displayName(kw['search_type']), django.utils.html.escape(kw['query_string']))
        page += u'<div>{} matching combination{} of gene name and genome found.  Try another <a href="{}">search</a>.</div>'.format(len(pairs), '' if len(pairs) == 1 else 's', django.core.urlresolvers.reverse(search_gene_names))
        page += "<table>\n"
        page += "<tr><td>Gene Name</td><td>Genome</td></tr>\n"
        for geneName, genome in pairs:
            page += u'<tr><td>{}</td><td>{}: {}</td></tr>\n'.format(geneName, genome, GENOME_TO_NAME[genome])
        page += "</table>\n"
        return django.shortcuts.render(request, 'regular.html', {'html': page, 'nav_id': 'search_gene_names'})
    else:
        raise django.http.Http404