Esempio n. 1
0
def clinvar_delete_object(submission, object_type):
    """Delete a single object (variant_data or case_data) associated with a clinvar submission"""

    store.delete_clinvar_object(
        object_id=request.form.get("delete_object"),
        object_type=object_type,
        submission_id=submission,
    )
    return redirect(request.referrer)
Esempio n. 2
0
def clinvar_submissions(institute_id):

    def generate_csv(header, lines):
        yield header + '\n'
        for line in lines: # lines have already quoted fields
            yield line + '\n'

    if request.method == 'POST':
        submission_id = request.form.get('submission_id')
        if request.form.get('update_submission'):
            if request.form.get('update_submission') == 'close': # close a submission
                store.update_clinvar_submission_status(current_user.email, submission_id, 'closed')
            elif request.form.get('update_submission') == 'open':
                store.update_clinvar_submission_status(current_user.email, submission_id, 'open') # open a submission
            elif request.form.get('update_submission') == 'register_id' and request.form.get('clinvar_id'): # provide an official clinvar submission ID
                result = store.update_clinvar_id(clinvar_id = request.form.get('clinvar_id'), submission_id = submission_id)
            elif request.form.get('update_submission') == 'delete': # delete a submission
                deleted_objects, deleted_submissions = store.delete_submission(submission_id = submission_id)
                flash("Removed {} objects and {} submission from database".format(deleted_objects, deleted_submissions), 'info')
        elif request.form.get('delete_variant'): # delete a variant from a submission
            store.delete_clinvar_object(object_id = request.form.get('delete_variant'), object_type='variant_data', submission_id = submission_id) # remove variant and associated_casedata
        elif request.form.get('delete_casedata'): # delete a case from a submission
            store.delete_clinvar_object(object_id = request.form.get('delete_casedata'), object_type='case_data', submission_id = submission_id) # remove just the casedata associated to a variant
        else: # Download submission CSV files (for variants or casedata)

            clinvar_subm_id = request.form.get('clinvar_id')
            if clinvar_subm_id =='':
                flash('In order to download a submission CSV file you should register a Clinvar submission Name first!','warning')
                return redirect(request.referrer)

            csv_type = ''
            csv_type = request.form.get('csv_type')

            submission_objs = store.clinvar_objs(submission_id=submission_id, key_id=csv_type) # a list of clinvar submission objects (variants or casedata)
            if submission_objs:
                csv_header_obj = controllers.clinvar_header(submission_objs, csv_type) # custom csv header (dict as in constants CLINVAR_HEADER and CASEDATA_HEADER, but with required fields only)
                csv_lines = controllers.clinvar_lines(submission_objs, csv_header_obj) # csv lines (one for each variant/casedata to be submitted)
                csv_header = list(csv_header_obj.values())
                csv_header = ['"'+str(x)+'"' for x in csv_header] # quote columns in header for csv rendering

                headers = Headers()
                headers.add('Content-Disposition','attachment', filename=clinvar_subm_id+'_'+str(datetime.datetime.now().strftime("%Y-%m-%d"))+'.csv')
                return Response(generate_csv(','.join(csv_header), csv_lines), mimetype='text/csv', headers=headers)
            else:
                flash('There are no submission objects of type "{}" to include in the csv file!'.format(csv_type),'warning')

    data = {
        'submissions' : controllers.clinvar_submissions(store, current_user.email, institute_id),
        'institute_id' : institute_id,
        'variant_header_fields' : CLINVAR_HEADER ,
        'casedata_header_fields' : CASEDATA_HEADER
    }
    return data
Esempio n. 3
0
def clinvar_submissions(institute_id):
    def generate_csv(header, lines):
        yield header + "\n"
        for line in lines:  # lines have already quoted fields
            yield line + "\n"

    if request.method == "POST":
        submission_id = request.form.get("submission_id")
        if request.form.get("update_submission"):
            if request.form.get(
                    "update_submission") == "close":  # close a submission
                store.update_clinvar_submission_status(institute_id,
                                                       submission_id, "closed")
            elif request.form.get("update_submission") == "open":
                store.update_clinvar_submission_status(
                    institute_id, submission_id, "open")  # open a submission
            elif request.form.get(
                    "update_submission") == "register_id" and request.form.get(
                        "clinvar_id"
                    ):  # provide an official clinvar submission ID
                result = store.update_clinvar_id(
                    clinvar_id=request.form.get("clinvar_id"),
                    submission_id=submission_id,
                )
            elif (request.form.get("update_submission") == "delete"
                  ):  # delete a submission
                deleted_objects, deleted_submissions = store.delete_submission(
                    submission_id=submission_id)
                flash(
                    "Removed {} objects and {} submission from database".
                    format(deleted_objects, deleted_submissions),
                    "info",
                )
        elif request.form.get(
                "delete_variant"):  # delete a variant from a submission
            store.delete_clinvar_object(
                object_id=request.form.get("delete_variant"),
                object_type="variant_data",
                submission_id=submission_id,
            )  # remove variant and associated_casedata
        elif request.form.get(
                "delete_casedata"):  # delete a case from a submission
            store.delete_clinvar_object(
                object_id=request.form.get("delete_casedata"),
                object_type="case_data",
                submission_id=submission_id,
            )  # remove just the casedata associated to a variant
        else:  # Download submission CSV files (for variants or casedata)

            clinvar_subm_id = request.form.get("clinvar_id")
            if clinvar_subm_id == "":
                flash(
                    "In order to download a submission CSV file you should register a Clinvar submission Name first!",
                    "warning",
                )
                return redirect(request.referrer)

            csv_type = request.form.get("csv_type", "")

            submission_objs = store.clinvar_objs(
                submission_id=submission_id, key_id=csv_type
            )  # a list of clinvar submission objects (variants or casedata)
            if submission_objs:
                csv_header_obj = controllers.clinvar_header(
                    submission_objs, csv_type
                )  # custom csv header (dict as in constants CLINVAR_HEADER and CASEDATA_HEADER, but with required fields only)
                csv_lines = controllers.clinvar_lines(
                    submission_objs, csv_header_obj
                )  # csv lines (one for each variant/casedata to be submitted)
                csv_header = list(csv_header_obj.values())
                csv_header = ['"' + str(x) + '"' for x in csv_header
                              ]  # quote columns in header for csv rendering
                download_day = str(
                    datetime.datetime.now().strftime("%Y-%m-%d"))
                headers = Headers()
                headers.add(
                    "Content-Disposition",
                    "attachment",
                    filename=f"{clinvar_subm_id}_{csv_type}_{download_day}.csv",
                )
                return Response(
                    generate_csv(",".join(csv_header), csv_lines),
                    mimetype="text/csv",
                    headers=headers,
                )
            else:
                flash(
                    'There are no submission objects of type "{}" to include in the csv file!'
                    .format(csv_type),
                    "warning",
                )

    institute_obj = institute_and_case(store, institute_id)

    data = {
        "submissions": controllers.clinvar_submissions(store, institute_id),
        "institute": institute_obj,
        "variant_header_fields": CLINVAR_HEADER,
        "casedata_header_fields": CASEDATA_HEADER,
    }
    return data
Esempio n. 4
0
def clinvar_submissions(institute_id):
    def generate_csv(header, lines):
        yield header + '\n'
        for line in lines:  # lines have already quoted fields
            yield line + '\n'

    if request.method == 'POST':
        submission_id = request.form.get('submission_id')
        if request.form.get('update_submission'):
            if request.form.get(
                    'update_submission') == 'close':  # close a submission
                store.update_clinvar_submission_status(current_user.email,
                                                       submission_id, 'closed')
            elif request.form.get('update_submission') == 'open':
                store.update_clinvar_submission_status(
                    current_user.email, submission_id,
                    'open')  # open a submission
            elif request.form.get(
                    'update_submission') == 'register_id' and request.form.get(
                        'clinvar_id'
                    ):  # provide an official clinvar submission ID
                result = store.update_clinvar_id(
                    clinvar_id=request.form.get('clinvar_id'),
                    submission_id=submission_id)
            elif request.form.get(
                    'update_submission') == 'delete':  # delete a submission
                deleted_objects, deleted_submissions = store.delete_submission(
                    submission_id=submission_id)
                flash(
                    "Removed {} objects and {} submission from database".
                    format(deleted_objects, deleted_submissions), 'info')
        elif request.form.get(
                'delete_variant'):  # delete a variant from a submission
            store.delete_clinvar_object(
                object_id=request.form.get('delete_variant'),
                object_type='variant_data',
                submission_id=submission_id
            )  # remove variant and associated_casedata
        elif request.form.get(
                'delete_casedata'):  # delete a case from a submission
            store.delete_clinvar_object(
                object_id=request.form.get('delete_casedata'),
                object_type='case_data',
                submission_id=submission_id
            )  # remove just the casedata associated to a variant
        else:  # Download submission CSV files (for variants or casedata)

            clinvar_subm_id = request.form.get('clinvar_id')
            if clinvar_subm_id == '':
                flash(
                    'In order to download a submission CSV file you should register a Clinvar submission Name first!',
                    'warning')
                return redirect(request.referrer)

            csv_type = ''
            csv_type = request.form.get('csv_type')

            submission_objs = store.clinvar_objs(
                submission_id=submission_id, key_id=csv_type
            )  # a list of clinvar submission objects (variants or casedata)
            if submission_objs:
                csv_header_obj = controllers.clinvar_header(
                    submission_objs, csv_type
                )  # custom csv header (dict as in constants CLINVAR_HEADER and CASEDATA_HEADER, but with required fields only)
                csv_lines = controllers.clinvar_lines(
                    submission_objs, csv_header_obj
                )  # csv lines (one for each variant/casedata to be submitted)
                csv_header = list(csv_header_obj.values())
                csv_header = ['"' + str(x) + '"' for x in csv_header
                              ]  # quote columns in header for csv rendering

                headers = Headers()
                headers.add('Content-Disposition',
                            'attachment',
                            filename=clinvar_subm_id + '_' +
                            str(datetime.datetime.now().strftime("%Y-%m-%d")) +
                            '.csv')
                return Response(generate_csv(','.join(csv_header), csv_lines),
                                mimetype='text/csv',
                                headers=headers)
            else:
                flash(
                    'There are no submission objects of type "{}" to include in the csv file!'
                    .format(csv_type), 'warning')

    data = {
        'submissions':
        controllers.clinvar_submissions(store, current_user.email,
                                        institute_id),
        'institute_id':
        institute_id,
        'variant_header_fields':
        CLINVAR_HEADER,
        'casedata_header_fields':
        CASEDATA_HEADER
    }
    return data