Ejemplo n.º 1
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:
        form_dict = request.form.to_dict()
        variants_to_submit = get_submission_variants(
            form_dict)  # list of variants to be submitted
        variant_header = get_submission_header(form_dict, variants_to_submit,
                                               'variants')
        variant_lines = get_submission_lines(form_dict, variants_to_submit,
                                             variant_header)
        casedata_header = get_submission_header(form_dict, variants_to_submit,
                                                'casedata')
        casedata_lines = get_submission_lines(form_dict, variants_to_submit,
                                              casedata_header)
        variant_types = {}
        for var in variants_to_submit:
            variant_types[var] = form_dict['variant-type_' + str(var)]

        # create clinvar submission session object:
        session['clinvar_submission'] = create_clinvar_submission_dict(
            variant_header, variant_lines, casedata_header, casedata_lines,
            variant_types)
        data.update({
            'variant_header': variant_header,
            'variant_lines': variant_lines,
            'casedata_header': casedata_header,
            'casedata_lines': casedata_lines,
            'form': request.form,
        })
        return data
Ejemplo n.º 2
0
def test_clinvar_submission_parser():
    # GIVEN a clinvar form submission
    test_clinvar_form_dict = get_submission_dict()

    # call the parser to get a list of the variants IDs to be used in the submission
    test_clinvars = get_submission_variants(test_clinvar_form_dict)

    # assert that the form contains info for 2 variants
    assert len(
        test_clinvars
    ) == 2  # variant '3eecfca5efea445eec6c19a53299043b' and 'a3ec99657a128d14419563d77e1381bd'

    # call the parser to get the header (a mini version of it actually, because of the shortened test form) of the .Variants csv file for the submission
    test_variants_header = get_submission_header(test_clinvar_form_dict,
                                                 test_clinvars, 'variants')

    # assert that the file header contains all the unique variant-related control fields (taken both from snv and sv variants):
    variant_control_fields = [
        '##Local ID', 'Linking ID', 'Chromosome', 'Start', 'Stop',
        'Reference allele', 'Alternate allele', 'Variant type'
    ]
    assert test_variants_header == variant_control_fields

    # call the parser to get the lines of the .Variants csv file for the submission
    test_variants_lines = get_submission_lines(test_clinvar_form_dict,
                                               test_clinvars,
                                               test_variants_header)

    # assert that each variant (== each line of the file) contains the same number of elements specified in the file header
    for variant_line in test_variants_lines:
        assert len(variant_line) == len(test_variants_header)

    # call the parser to get the header of the .Casedata csv file for the submission
    test_casedata_header = get_submission_header(test_clinvar_form_dict,
                                                 test_clinvars, 'casedata')

    # call the parser to get the lines of the .Casedata csv file for the submission
    test_casedata_lines = get_submission_lines(test_clinvar_form_dict,
                                               test_clinvars,
                                               test_casedata_header)

    # assert that there is casedata for one sample only
    assert len(test_casedata_lines) == 1

    # assert that the casedata line for that sample has three fields ('Linking ID', 'Individual ID', 'Affected status')
    assert len(test_casedata_lines[0]) == 3

    test_variant_types = {
        '3eecfca5efea445eec6c19a53299043b': 'snv',
        'a3ec99657a128d14419563d77e1381bd': 'sv'
    }
    # transform the text files values into a dictionary list. Each dictionary item of this list is a variant submission onject that is saved to scout db.
    test_vars_dict_list = create_clinvar_submission_dict(
        test_variants_header, test_variants_lines, test_casedata_header,
        test_casedata_lines, test_variant_types)

    # assert that two variant objects were created
    assert len(test_vars_dict_list) == 2
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