Commit 9c6fd8f6 authored by Mikaël Salson's avatar Mikaël Salson
Browse files Remove everything related to the form

The controller does not manage the form anymore. The controller is
now restricted to its minimum: returning a JSON with the results.

The sequences are sent by the request.
parent 3f68e148
......@@ -4,6 +4,7 @@ import tempfile
import shutil
import defs
from subprocess import Popen, PIPE, STDOUT, os
import gluon
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
......@@ -23,24 +24,33 @@ limit_max = 10 #max sequence per request
def index():
form = SQLFORM.factory(
Field('sequences', 'text'),
Field('file', 'upload', uploadfolder=os.path.join(request.folder,'uploads')))
form.element('textarea[name=sequences]')['_style'] = 'width:800px; height:200px;'
t_result = ""
if request.vars['sequences'] == None or request.vars['sequences'] == '':
return None
sequences = request.vars['sequences']
return segment_sequences(sequences)
def segment_sequences(sequences):
Segment the sequences given in parameter (FASTA format)
and return a JSON of the result
text_result = "{}"
if form.process(onvalidation=checkform_segmenter).accepted:
check = check_sequences(sequences)
if check is not None:
text_result = '{"error": "%s"}' % check
with TemporaryDirectory() as folder_path:
#store sequences in a tmp file
file_path = folder_path + "/sequences.txt"
file = open(file_path, 'w')
#store result in a tmp file
result_path = folder_path + "/result.txt"
result_path = folder_path + "/sequences.vidjil"
result = open(result_path, 'w')
## les chemins d'acces a vidjil / aux fichiers de sequences
......@@ -63,47 +73,20 @@ def index():
with open(result_path, 'r') as myfile:
text_result =
t_result = ''
for l in text_result.split('\n'):
pre, post = ('<span style="color: #090; font-weight:bold;">', '</span>') if l.startswith('>') else ('', '')
t_result += pre + l + post + '\n'
response.flash = file_path
elif form.errors:
response.flash = 'form has errors'
#form.errors.sequences = form.vars.sequences
return dict(form=form,
return response.json(gluon.contrib.simplejson.loads(text_result))
def checkform_segmenter(form):
#copy file content into form.vars.sequences
if hasattr(form.vars.file, 'file') :
with TemporaryDirectory() as folder_path:
with open(folder_path+"/sequences.txt", 'r') as myfile:
form.vars.sequences =
form.vars.sequences+= "\n"
def check_sequences(sequences):
#fasta format ?
if form.vars.sequences[0] is '>':
if len(form.vars.sequences.split('>')) > limit_max+1 :
form.errors.sequences = "too much sequences (limit : " + str(limit_max) + ")"
if sequences[0] is '>':
if len(sequences.split('>')) > limit_max+1 :
return "too many sequences (limit : " + str(limit_max) + ")"
#fastq format ?
elif form.vars.sequences[0] is '@':
if len(form.vars.sequences.split('\n')) > 4*(limit_max+1) :
form.errors.sequences = "too much sequences (limit : " + str(limit_max) + ")"
elif sequences[0] is '@':
if len(sequences.split('\n')) > 4*(limit_max+1) :
return "too many sequences (limit : " + str(limit_max) + ")"
#unknow format ?
else :
form.errors.sequences = "invalid sequences, please use fasta or fastq format"
return "invalid sequences, please use fasta or fastq format"
return None
{{extend 'simple_layout.html'}}
<h2>V(D)J designation tool</h2>
<p>This tool quickly checks the V(D)J designation of a small number of sequences with (possibly incomplete) V(D)J recombinations.
To analyze complete NGS RepSeq datasets, use the <a href="">full Vidjil platform</a>.
<p>Either enter up to 10 sequences in FASTA format or upload a FASTA file.</p>
{{if result != "":}}
<div class="text invalidinput" cols="40" name="result" rows="10" style="width: 100%; height: 2000px; font-family:monospace; white-space: pre;">{{=result}}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment