Example #1
0
def clinvar(institute_id, case_name, variant_id):
    """Build a clinVar submission form for a variant."""
    data = clinvar_export(store, institute_id, case_name, variant_id)
    if request.method == "GET":
        return data
    # POST
    form_dict = {}
    # flatten up HPO and OMIM terms lists into string of keys separated by semicolon
    for key, value in request.form.items():
        if key.startswith("conditions@") or key.startswith("clin_features@"):
            conditions = request.form.getlist(
                key)  # can be HPO or OMIM conditions
            if conditions:
                variant_id = key.split("@")[1]
                cond_types = []
                cond_values = []

                for condition in conditions:
                    cond_types.append(
                        condition.split("_")[0])  # 'HPO' or 'OMIM'
                    cond_values.append(
                        condition.split("_")[1])  # HPO id or OMIM ID

                if key.startswith(
                        "conditions@"
                ):  # Filling in 'condition_id_type' and 'condition_id_value' in variant data
                    form_dict["@".join(["condition_id_type",
                                        variant_id])] = ";".join(
                                            cond_types)  # Flattened list
                    form_dict["@".join(["condition_id_value",
                                        variant_id])] = ";".join(
                                            cond_values)  # Flattened list
                elif key.startswith(
                        "clin_features@"
                ):  # Filling in 'clin_features' in casedata
                    form_dict["@".join(["clin_features",
                                        variant_id])] = ";".join(
                                            cond_values)  # Flattened list

        else:
            form_dict[key] = value

    # A tuple of submission objects (variants and casedata objects):
    submission_objects = set_submission_objects(form_dict)

    # Add submission data to an open clinvar submission object,
    # or create a new if no open submission is found in database
    open_submission = store.get_open_clinvar_submission(institute_id)
    updated_submission = store.add_to_submission(open_submission["_id"],
                                                 submission_objects)

    # Redirect to clinvar submissions handling page, and pass it the updated_submission_object
    return redirect(
        url_for("cases.clinvar_submissions", institute_id=institute_id))
def test_parse_clinvar_form():
    """Test create list of submission objects (variants and casedata) from clinvar page form"""

    # Given a filled in form
    form_fields_dict = get_submission_dict()

    # Retrieve the IDs of variants in the form
    variant_ids = get_submission_variants(form_fields_dict)
    assert len(variant_ids) == 2

    # obtain variant and casedata objects to include in submission
    subm_objs = set_submission_objects(form_fields_dict)
    assert len(subm_objs[0]) == 2 # one snv and one sv variant
    assert len(subm_objs[1]) ==1 # one case data object
Example #3
0
def clinvar(institute_id, case_name, variant_id):
    """Build a clinVar submission form for a variant."""
    data = controllers.clinvar_export(store, institute_id, case_name, variant_id)
    if request.method == 'GET':
        return data
    else: #POST
        form_dict = request.form.to_dict()
        submission_objects = set_submission_objects(form_dict) # A tuple of submission objects (variants and casedata objects)

        # Add submission data to an open clinvar submission object,
        # or create a new if no open submission is found in database
        open_submission = store.get_open_clinvar_submission(current_user.email, institute_id)
        updated_submission = store.add_to_submission(open_submission['_id'], submission_objects)

        # Redirect to clinvar submissions handling page, and pass it the updated_submission_object
        return redirect(url_for('cases.clinvar_submissions', institute_id=institute_id))
Example #4
0
def clinvar(institute_id, case_name, variant_id):
    """Build a clinVar submission form for a variant."""
    data = controllers.clinvar_export(store, institute_id, case_name, variant_id)
    if request.method == 'GET':
        return data
    else: #POST
        form_dict = request.form.to_dict()
        submission_objects = set_submission_objects(form_dict) # A tuple of submission objects (variants and casedata objects)

        # Add submission data to an open clinvar submission object,
        # or create a new if no open submission is found in database
        open_submission = store.get_open_clinvar_submission(current_user.email, institute_id)
        updated_submission = store.add_to_submission(open_submission['_id'], submission_objects)

        # Redirect to clinvar submissions handling page, and pass it the updated_submission_object
        return redirect(url_for('cases.clinvar_submissions', institute_id=institute_id))
Example #5
0
def build_clinvar_submission(store, request, institute_id, case_name, variant_id):
    """Add some variants to a ClinVar submission object or create a new ClinVar submission

    Args:
        store(scout.adapter.MongoAdapter)
        request(flask.Request)
        institute_id(str): institute_obj['_id']
        case_name(str): case_obj['display_name']
        variant_id(str): variant_obj['document_id']
    """
    form_dict = {}

    # flatten up HPO and OMIM terms lists into string of keys separated by semicolon
    for key, value in request.form.items():
        if "@" in key:
            variant_id = key.split("@")[1]

        if key.startswith("hpo_terms") and f"omim_terms@{variant_id}" not in request.form:
            form_dict["@".join(["condition_id_type", variant_id])] = "HPO"
            form_dict["@".join(["condition_id_value", variant_id])] = ";".join(
                request.form.getlist(key)
            )

        elif key.startswith("omim_terms"):
            form_dict["@".join(["condition_id_type", variant_id])] = "OMIM"
            form_dict["@".join(["condition_id_value", variant_id])] = ";".join(
                request.form.getlist(key)
            )

        elif key.startswith("clin_features"):
            form_dict[key] = ";".join(request.form.getlist(key))

        else:
            form_dict[key] = value

    # A tuple of submission objects (variants and casedata objects):
    submission_objects = set_submission_objects(form_dict)

    # Add submission data to an open clinvar submission object,
    # or create a new if no open submission is found in database
    open_submission = store.get_open_clinvar_submission(institute_id)
    updated_submission = store.add_to_submission(open_submission["_id"], submission_objects)