Ejemplo n.º 1
0
def orth_result(request, resultId):
    '''
    GET: return an orthology result page
    '''
    logging.debug('orth_result resultId={}'.format(resultId))
    if orthresult.resultExists(resultId):
        resultType = request.GET.get('rt', orthresult.ORTH_RESULT)
        templateType = request.GET.get('tt', orthresult.WIDE_TEMPLATE)
        def urlFunc(resultId):
            return django.core.urlresolvers.reverse(orth_result, kwargs={'resultId': resultId})
        page = orthresult.renderResult(resultId, urlFunc, resultType=resultType, otherParams=request.GET)
        # page = orthresult.resultToAllGenesView(resultId)
        if templateType == orthresult.WIDE_TEMPLATE:
            return django.shortcuts.render(request, 'wide.html', {'html': page, 'nav_id': 'browse'})
        elif templateType == orthresult.DOWNLOAD_TEMPLATE:
            response = django.http.HttpResponse(page, content_type='text/plain')
            full_filename = 'roundup-{}-gene_clusters_for_result_{}.txt'.format(webconfig.CURRENT_RELEASE, resultId)
            response['Content-Disposition'] = 'attachment; filename={}'.format(full_filename)
            return response
        elif templateType == orthresult.DOWNLOAD_XML_TEMPLATE:
            response = django.http.HttpResponse(page, content_type='text/xml')
            full_filename = 'roundup-{}-gene_clusters_for_result_{}.xml'.format(webconfig.CURRENT_RELEASE, resultId)
            response['Content-Disposition'] = 'attachment; filename={}'.format(full_filename)
            return response
        else:
            raise django.http.Http404
    else:
        raise django.http.Http404
Ejemplo n.º 2
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}))