def blast(request, blast_form, template_init, template_result, blast_commandline, sample_fasta_path,<EOL>extra_context=None):
if request.method == '<STR_LIT:POST>':<EOL><INDENT>form = blast_form(request.POST)<EOL>if form.is_valid():<EOL><INDENT>query_file_object_tmp = form.cleaned_data['<STR_LIT>']<EOL>evalue = float(form.cleaned_data['<STR_LIT>'])<EOL>word_size = int(form.cleaned_data['<STR_LIT>'])<EOL>database_path = str(form.cleaned_data['<STR_LIT>'])<EOL>standard_opt_dic = {'<STR_LIT>': query_file_object_tmp, '<STR_LIT>': evalue, '<STR_LIT>': <NUM_LIT:5>, '<STR_LIT>': database_path,<EOL>'<STR_LIT>': word_size}<EOL>annotated = utils.get_annotation(database_path, BLAST_DB_NUCL_LIST)<EOL>try:<EOL><INDENT>matrix = str(form.cleaned_data['<STR_LIT>'])<EOL>standard_opt_dic["<STR_LIT>"] = matrix<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>sensitivity_opt_dic = ast.literal_eval(str(form.cleaned_data['<STR_LIT>']))<EOL>blast_records__file_xml = None<EOL>try:<EOL><INDENT>blast_records__file_xml, blast_error = utils.run_blast_commands(blast_commandline,<EOL>**dict(standard_opt_dic,<EOL>**sensitivity_opt_dic))<EOL>if len(blast_error) > <NUM_LIT:0>:<EOL><INDENT>return render(request=request, template_name=template_result,<EOL>context={"<STR_LIT>": '<STR_LIT>', blast_error: BLAST_CORRECT_PARAMS})<EOL><DEDENT>else:<EOL><INDENT>blast_records_in_object_and_list = utils.blast_records_to_object(<EOL>list(NCBIXML.parse(blast_records__file_xml)))<EOL>if extra_context is not None:<EOL><INDENT>blast_records_in_object_and_list = extra_context(blast_records_in_object_and_list)<EOL><DEDENT>return render(request=request, template_name=template_result,<EOL>context={'<STR_LIT>': blast_records_in_object_and_list[<NUM_LIT:0>].application,<EOL>'<STR_LIT:version>': blast_records_in_object_and_list[<NUM_LIT:0>].version,<EOL>'<STR_LIT>': blast_records_in_object_and_list,<EOL>'<STR_LIT>': annotated})<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if blast_records__file_xml is not None:<EOL><INDENT>os.remove(blast_records__file_xml.name)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>form = blast_form(initial={'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': EVALUE_BLAST_DEFAULT})<EOL><DEDENT>return render(request=request, template_name=template_init,<EOL>context={'<STR_LIT>': form, '<STR_LIT>': utils.get_sample_data(sample_fasta_path),<EOL>"<STR_LIT>": BLAST_MAX_NUMBER_SEQ_IN_INPUT, })<EOL>
Process blastn/tblastn (blast+) query or set up initial blast form.