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})
def browse(request): ''' GET: send user the form to make a browse query POST: validate browse query and REDIRECT to result if it is good. ''' if request.method == 'POST': # If the form has been submitted... form = BrowseForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass logging.debug(u'form.cleaned_data={}'.format(form.cleaned_data)) orthQuery = makeOrthQueryFromBrowseForm(form) logging.debug(u'orthQuery={}'.format(orthQuery)) # Process and add Browse Ids to the query # I would rather not have this complexity in here at all. There must be a simpler and more powerful way. browseId = form.cleaned_data.get('identifier') browseIdType = form.cleaned_data.get('identifier_type') logging.debug(u'browseId={}, browseIdType={}'.format(browseId, browseIdType)) if browseId and browseIdType == 'gene_name_type': genome = form.cleaned_data['primary_genome'] seqIds = roundup_db.getSeqIdsForGeneName( webconfig.CURRENT_RELEASE, geneName=browseId, genome=genome) if not seqIds: # no seq ids matching the gene name were found. oh no! message = u'In your Browse query, Roundup did not find any gene named "{}" in the genome "{}". Try searching for a gene name.'.format(browseId, GENOME_TO_NAME[genome]) # store result in cache, so can do a redirect/get. key = makeUniqueId() roundup_util.cacheSet(key, {'message': message, 'search_type': 'contains', 'query_string': browseId}) return django.shortcuts.redirect(django.core.urlresolvers.reverse(search_gene_names, kwargs={'key': key})) else: # remake orthQuery with seqIds form.cleaned_data['seq_ids'] = seqIds orthQuery = makeOrthQueryFromBrowseForm(form) elif browseId and browseIdType == 'seq_id_type': # remake orthQuery with seqIds form.cleaned_data['seq_ids'] = browseId.split() # split on whitespace orthQuery = makeOrthQueryFromBrowseForm(form) # cache the query and redirect to a page that will "get" the query result queryId = orthQueryHash(orthQuery) roundup_util.cacheSet(queryId, orthQuery) return django.shortcuts.redirect(django.core.urlresolvers.reverse(orth_query, kwargs={'queryId': queryId})) else: form = BrowseForm(initial={'primary_genome_filter': [value for value, name in CAT_CHOICES], 'secondary_genomes_filter': [value for value, name in CAT_CHOICES] }) # An unbound form # example = json.dumps({'primary_genome': '559292', 'identifier': 'Q03834', # 'identifier_type': 'seq_id_type', 'secondary_genomes': ['9606', '10090']}) example = json.dumps({'primary_genome': 'Drosophila melanogaster', 'identifier': 'Q9VVT2', 'identifier_type': 'seq_id_type', 'secondary_genomes': 'H**o sapiens\nMus musculus\n'}) # example = "{'primary_genome': 'MYCGE', 'secondary_genomes': ['MYCHH', 'MYCH1']}" # javascript # , 'include_gene_name': 'true', 'include_go_term': 'true'}" # javascript return django.shortcuts.render(request, 'browse.html', {'form': form, 'nav_id': 'browse', 'form_doc_id': 'browse', 'chosen_ids': ['id_primary_genome', 'id_secondary_genomes'], 'form_action': django.core.urlresolvers.reverse(browse), 'form_example': example, 'cat_genomes_json': json.dumps(CAT_GENOMES, indent=-1), })
def cluster(request): ''' GET: send user the form to make a cluster query POST: validate cluster query and REDIRECT to result if it is good. ''' if request.method == 'POST': # If the form has been submitted... form = ClusterForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass orthQuery = makeOrthQueryFromClusterForm(form) queryId = orthQueryHash(orthQuery) roundup_util.cacheSet(queryId, orthQuery) # cache the query and redirect to a page that will run the query return django.shortcuts.redirect(django.core.urlresolvers.reverse(orth_query, kwargs={'queryId': queryId})) else: form = ClusterForm(initial={'genomes_filter': [value for value, name in CAT_CHOICES]}) # An unbound form example = json.dumps({'genomes': 'H**o sapiens\nMus musculus\nDrosophila melanogaster\n'}) return django.shortcuts.render(request, 'cluster.html', {'form': form, 'nav_id': 'cluster', 'form_doc_id': 'cluster', 'chosen_ids': ['id_genomes'], 'form_action': django.core.urlresolvers.reverse(cluster), 'form_example': example, 'cat_genomes_json': json.dumps(CAT_GENOMES, indent=-1), })
def lookup(request): ''' get: render a form for user to lookup the sequence id for a fasta sequence from a genome. post: redirect to a page which will show the id. ''' raise django.http.Http404 if request.method == 'POST': # If the form has been submitted... form = LookupForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass logging.debug(form.cleaned_data) genome, fasta = form.cleaned_data['genome'], form.cleaned_data['fasta'] seqId = BioUtilities.findSeqIdWithFasta(fasta, roundup.dataset.getGenomeIndexPath(webconfig.CURRENT_DATASET, genome)) # store result in cache, so can do a redirect/get. key = makeUniqueId() roundup_util.cacheSet(key, {'genome': genome, 'fasta': fasta, 'seqId': seqId}) # redirect the post to a get. http://en.wikipedia.org/wiki/Post/Redirect/Get return django.shortcuts.redirect(django.core.urlresolvers.reverse(lookup_result, kwargs={'key': key})) else: form = LookupForm() # An unbound form example = "{'fasta': '>example_nameline\\nMNFLWKGRRFLIAGILPTFEGAADEIVDKENKTYKAFLASKPPEETGLERLKQMFTIDEF', 'genome': '7227'}" return django.shortcuts.render(request, 'lookup.html', {'form': form, 'nav_id': 'lookup', 'form_doc_id': 'lookup', 'form_action': django.core.urlresolvers.reverse(lookup), 'form_example': example})