Beispiel #1
0
def update_analysis_append_samples(request, analysis_id):

    if request.method == 'POST':

        form = webforms.DataUploadForm(request.POST, request.FILES)

        if form.is_valid():
            time_stamp = helper_functions.get_time_stamp()
            data_file_path = helper_functions.save_uploaded_file(form.cleaned_data['data_file'], time_stamp, output_file_name = constants.data_file_name)

            data_file_sha1sum = helper_functions.get_sha1sum(data_file_path)

            # just send the data file
            server_request = {'request': 'append_samples_to_analysis',
                              'analysis_id': analysis_id,
                              'data_file_path': data_file_path}

            server_response = server(server_request)

            if server_response['response'] == 'OK':
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "Your request is being processed."})))
            else:
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "something happened. has no clue. seriously :("})))
        else:
            return HttpResponse(get_template("error.tmpl").render(Context({'content': "Form wasn't valid :( Please click 'back' button of your browser and re-submit the form."})))

    else:
        form = webforms.DataUploadForm()
        tmpl = "data_upload_form.tmpl"

        return HttpResponse(get_template(tmpl).render(Context({'form': form, 'analysis_id': analysis_id})))
Beispiel #2
0
def exec_env(request):
    if request.method == 'POST':
        form = webforms.EnvUploadForm(request.POST, request.FILES)
        if form.is_valid():
            job_description = form.cleaned_data['job_description']
            time_stamp = helper_functions.get_time_stamp()
            data_file_path = helper_functions.save_uploaded_file(form.cleaned_data['env_file'], time_stamp, output_file_name = constants.data_file_name)

            data_file_sha1sum = helper_functions.get_sha1sum(data_file_path)

            server_request = {'request': 'status'}
            server_response = server(server_request)

            if data_file_sha1sum in server_response['running_analyses']:
                #error we already have it lan
                tmpl = get_template("simple.tmpl")
                return HttpResponse(tmpl.render(Context({'content': "Your ENV file is still being analyzed"})))
            elif data_file_sha1sum in server_response['done_analyses']:
                tmpl = get_template("simple.tmpl")
                return HttpResponse(tmpl.render(Context({'content': "It seems we already have this ENV file analyzed"})))
            # TODO: check validity of the file here..

            server_request = {'request': 'exec_env',
                              'job_description': job_description,
                              'data_file_path': data_file_path,
                              'data_file_sha1sum': data_file_sha1sum}

            server_response = server(server_request)

            if server_response['response'] == 'OK':
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "Your ENV file is being processed. This is your process id: %s" % server_response['process_id']})))
            else:
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "something happened"})))
    else:
        form = webforms.EnvUploadForm()

    return HttpResponse(get_template("env_upload_form.tmpl").render(Context({'form': form})))
Beispiel #3
0
def new_analysis(request, analysis_type):
    if request.method == 'POST':

        #import pdb; pdb.set_trace()
        if analysis_type == "rdp":
            form = webforms.FastaUploadForm(request.POST, request.FILES)
        if analysis_type == "qpcr":
            form = webforms.QpcrUploadForm(request.POST, request.FILES)
        if analysis_type == "env":
            form = webforms.EnvUploadForm(request.POST, request.FILES)
        if analysis_type == "blast":
            form = webforms.BlastUploadForm(request.POST, request.FILES)
        if analysis_type == "vamps":
            form = webforms.VampsUploadForm(request.POST, request.FILES)

        if form.is_valid():
            job_description = form.cleaned_data['job_description']
            time_stamp = helper_functions.get_time_stamp()
            if len(request.FILES) == 1:
                data_file_path = helper_functions.save_uploaded_file(
                    form.cleaned_data['data_file'],
                    time_stamp, output_file_name = constants.data_file_name)
            elif len(request.FILES) > 1:
                files = [request.FILES[f] for f in request.FILES.keys() if
                         f.startswith("data_file")]
                data_file_path = cat(files)

            data_file_sha1sum = helper_functions.get_sha1sum(data_file_path)

            server_request = {'request': 'status'}
            server_response = server(server_request)

            if data_file_sha1sum in server_response['running_analyses']:
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "This data file is still being analyzed"})))
            elif data_file_sha1sum in server_response['done_analyses']:
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "This data file has already been analyzed. The analysis id is "+str(data_file_sha1sum)})))

            # TODO: check validity of the file here..

            #standard request dict for all analyses.
            server_request = {'request': 'exec_analysis',
                              'analysis_type': analysis_type,
                              'job_description': job_description,
                              'data_file_path': data_file_path,
                              'data_file_sha1sum': data_file_sha1sum}

            #update server request with special options for certain analysis types
            #if your module needs information not contained in a standard request,
            #(say phase of the moon or something), add it here in a tuple of
            #(name, function) where name is the name attribute in the form, and
            #the function converts the raw value or cleaned_data into
            #whatever it needs to be
            special_options = [("seperator",str),
                               ("qa_mode", int),
                               ("db_name",str),
                               ("threshold",float),
                               ("codes_primers",list),
                               ("homopolymer_length",int),
                               ("threshold_dict",dict)]
            for opt in special_options:
                if form.cleaned_data.get(opt[0]):
                    server_request[opt[0]] = opt[1](form.cleaned_data[opt[0]])
                    
             

            server_response = server(server_request)

            if server_response['response'] == 'OK':
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "Your request is being processed. This is your process id: %s" % server_response['process_id']})))
            else:
                return HttpResponse(get_template("simple.tmpl").render(Context({'content': "Server error:"+str(server_response.get("exception"))})))
        else:
            return HttpResponse(get_template(templates[analysis_type]).render(
                Context({"form":form})))
    else:
        if analysis_type == "rdp":
            form = webforms.FastaUploadForm()
            tmpl = "fasta_upload_form.tmpl"
        elif analysis_type == "qpcr":
            form = webforms.QpcrUploadForm()
            tmpl = "qpcr_upload_form.tmpl"
        elif analysis_type == "env":
            form = webforms.EnvUploadForm()
            tmpl = "env_upload_form.tmpl"
        elif analysis_type == 'blast':
            form = webforms.BlastUploadForm()
            tmpl = "blast_upload_form.tmpl"
        elif analysis_type == "vamps":
            form = webforms.EnvUploadForm()
            tmpl = "vamps_upload_form.tmpl"

        return HttpResponse(get_template(tmpl).render(Context({'form': form})))