def geneseekr_query(request): form = GeneSeekrForm() if request.method == 'POST': form = GeneSeekrForm(request.POST, request.FILES) if form.is_valid(): seqids, query_sequence, name = form.cleaned_data geneseekr_request = GeneSeekrRequest.objects.create( user=request.user, seqids=seqids) # Use query sequence if entered. Otherwise, read in the FASTA file provided. if query_sequence != '': geneseekr_request.query_sequence = query_sequence else: input_sequence_file = request.FILES['query_file'] # Pointer is at end of file in request, so move back to beginning before doing the read. input_sequence_file.seek(0) input_sequence = input_sequence_file.read().decode('utf-8') geneseekr_request.query_sequence = input_sequence geneseekr_request.status = 'Processing' if (name): geneseekr_request.name = name geneseekr_request.save() run_geneseekr.apply_async(queue='geneseekr', args=(geneseekr_request.pk, ), countdown=10) return redirect('geneseekr:geneseekr_processing', geneseekr_request_pk=geneseekr_request.pk) return render(request, 'geneseekr/geneseekr_query.html', { 'form': form, })
def test_invalid_form_no_sequences_in_exclude_genus(self): form = GeneSeekrForm({ 'genus': 'Listeria', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA', 'everything_but': True, }) self.assertFalse(form.is_valid())
def geneseekr_query(request): form = GeneSeekrForm() if request.method == 'POST': form = GeneSeekrForm(request.POST, request.FILES) if form.is_valid(): # seqid_input = form.cleaned_data.get('seqids') # seqids = seqid_input.split() seqids, query_sequence = form.cleaned_data geneseekr_request = GeneSeekrRequest.objects.create( user=request.user, seqids=seqids) # Use query sequence if entered. Otherwise, read in the FASTA file provided. if query_sequence != '': geneseekr_request.query_sequence = query_sequence else: input_sequence_file = request.FILES['query_file'] # Pointer is at end of file in request, so move back to beginning before doing the read. input_sequence_file.seek(0) input_sequence = input_sequence_file.read() geneseekr_request.query_sequence = input_sequence geneseekr_request.status = 'Processing' geneseekr_request.save() run_geneseekr(geneseekr_request_pk=geneseekr_request.pk) return redirect('geneseekr:geneseekr_processing', geneseekr_request_pk=geneseekr_request.pk) return render(request, 'geneseekr/geneseekr_query.html', {'form': form})
def test_invalid_form_bad_fasta_file(self): with open('olc_webportalv2/geneseekr/tests/bad_fasta.fasta', 'rb') as upload_file: form = GeneSeekrForm({'seqids': '2015-SEQ-0711 2015-SEQ-0712'}, { 'query_file': SimpleUploadedFile(upload_file.name, upload_file.read()) }) self.assertFalse(form.is_valid())
def test_invalid_form_fasta_too_long(self): form = GeneSeekrForm({ 'seqids': '2015-SEQ-0711 2015-SEQ-0712', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA' + 'A' * 10000 }) self.assertFalse(form.is_valid())
def test_valid_geneseekr_form_genus_input_fasta_text(self): form = GeneSeekrForm({ 'genus': 'Listeria', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA' }) self.assertTrue(form.is_valid()) seqid_list, query_sequence = form.cleaned_data self.assertEqual(seqid_list, ['2015-SEQ-0711', '2015-SEQ-0712']) self.assertEqual(query_sequence, '>fasta_name\nATCGACTGACTAGTCA')
def test_valid_form_exclude_genus(self): form = GeneSeekrForm({ 'genus': 'Salmonella', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA', 'everything_but': True, }) self.assertTrue(form.is_valid()) seqid_list, query_sequence = form.cleaned_data self.assertEqual(seqid_list, ['2015-SEQ-0711', '2015-SEQ-0712']) self.assertEqual(query_sequence, '>fasta_name\nATCGACTGACTAGTCA')
def test_valid_geneseekr_form_genus_input_fasta_file(self): with open('olc_webportalv2/geneseekr/tests/good_fasta.fasta', 'rb') as upload_file: form = GeneSeekrForm({'genus': 'Listeria'}, { 'query_file': SimpleUploadedFile(upload_file.name, upload_file.read()) }) self.assertTrue(form.is_valid()) seqid_list, query_sequence = form.cleaned_data self.assertEqual(seqid_list, ['2015-SEQ-0711', '2015-SEQ-0712'])
def tree_rename(request, tree_request_pk): tree_request = get_object_or_404(Tree, pk=tree_request_pk) name = {'name': tree_request.name} form = GeneSeekrForm(initial=name) if request.method == "POST": tree_request.name = request.POST["name"] tree_request.save() return redirect('geneseekr:tree_home') return render(request, 'rename.html', { 'tree_request': tree_request, 'form': form })
def geneseekr_rename(request, geneseekr_request_pk): geneseekr_request = get_object_or_404(GeneSeekrRequest, pk=geneseekr_request_pk) name = {'name': geneseekr_request.name} form = GeneSeekrForm(initial=name) if request.method == "POST": geneseekr_request.name = request.POST["name"] geneseekr_request.save() return redirect('geneseekr:geneseekr_home') return render(request, 'rename.html', { 'geneseekr_request': geneseekr_request, 'form': form })
def test_invalid_form_no_sequences_in_genus(self): form = GeneSeekrForm({ 'genus': 'TotallyFakeGenus', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA' }) self.assertFalse(form.is_valid())
def test_invalid_form_missing_seqid(self): form = GeneSeekrForm({ 'seqids': '2222-SEQ-0711 2015-SEQ-0712', 'query_sequence': '>fasta_name\nATCGACTGACTAGTCA' }) self.assertFalse(form.is_valid())