def clinvar_header(submission_objs, csv_type): """Call clinvar parser to extract required fields to include in csv header from clinvar submission objects Args: submission_objs(list) csv_type(str) Returns: clinvar_header_obj(dict) # custom csv header (dict based on constants CLINVAR_HEADER and CASEDATA_HEADER, but with required fields only) """ clinvar_header_obj = clinvar_submission_header(submission_objs, csv_type) return clinvar_header_obj
def test_add_remove_subm_objects(adapter, institute_obj, case_obj): """Test adding variant and casedata objects to a submission""" # Get the ID of an existing submission submission_obj = adapter.get_open_clinvar_submission( institute_id=institute_obj["_id"]) # Given a test variant and its associated casedata variant_data = [get_test_submission_variant(case_obj) ] # a list of 1 dictionary element case_data = [get_test_submission_case(case_obj) ] # a list of 1 dictionary element subm_objs = (variant_data, case_data) # assert that clinvar collection in database is empty submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 0 # Add objects to submission updated_subm = adapter.add_to_submission(submission_obj["_id"], subm_objs) # Assert that 'variant_data' value of submission is updated assert updated_subm["variant_data"] == [variant_data[0].get("_id")] # Assert that 'case_data' value of submission is updated assert updated_subm["case_data"] == [case_data[0].get("_id")] # assert that clinvar collection in database has now 2 elements submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 2 # check if it is possible to create CSV files header for variant and casedata objects variants_file_header = clinvar_submission_header(submission_objects, "variant_data") assert len(variants_file_header.keys()) > 0 casedata_file_header = clinvar_submission_header(submission_objects, "case_data") assert len(casedata_file_header.keys()) > 0 # check if it is possible to create CSV files lines for variant and casedata objects variants_file_lines = clinvar_submission_lines(submission_objects, variants_file_header) assert len(variants_file_lines[0].split(",")) == len( variants_file_header.keys() ) # variant file header and line have the same number of columns casedata_file_lines = clinvar_submission_lines(submission_objects, casedata_file_header) assert len(casedata_file_lines[0].split(",")) == len( casedata_file_header.keys() ) # casedata file header and line have the same number of columns # assert that one of these objects is the variant object assert variant_data == adapter.clinvar_objs(submission_obj["_id"], "variant_data") # assert that one of these objects is the case data object assert case_data == adapter.clinvar_objs(submission_obj["_id"], "case_data") # assert that a variant is present for test case assert adapter.case_to_clinVars(case_obj["_id"]) == { variant_data[0]["local_id"]: variant_data[0] } # Removal of clinvar objects from submission and from clinvar collection in database # remove case_data object updated_submission = adapter.delete_clinvar_object( object_id=case_data[0]["_id"], object_type="case_data", submission_id=submission_obj["_id"], ) assert updated_submission["case_data"] == [] # remove variant object updated_submission = adapter.delete_clinvar_object( object_id=variant_data[0]["_id"], object_type="variant_data", submission_id=submission_obj["_id"], ) assert updated_submission["variant_data"] == [] # assert that there are no objects left in clinvar collection submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 0
def clinvar_header(submission_objs, csv_type): """ Call clinvar parser to extract required fields to include in csv header from clinvar submission objects""" clinvar_header_obj = clinvar_submission_header(submission_objs, csv_type) return clinvar_header_obj
def test_add_remove_subm_objects(adapter, user_obj, institute_obj): """Test adding variant and casedata objects to a submission""" # Get the ID of an existing submission submission_obj = adapter.get_open_clinvar_submission( user_id=user_obj['_id'], institute_id=institute_obj['_id']) # Given a test variant and its associated casedata variant_data = [ get_test_submission_variant() ] # a list of 1 dictionary element case_data = [ get_test_submission_case() ] # a list of 1 dictionary element subm_objs = (variant_data, case_data) # assert that clinvar collection in database is empty submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 0 # Add objects to submission updated_subm = adapter.add_to_submission( submission_obj['_id'], subm_objs) # Assert that 'variant_data' value of submission is updated assert updated_subm['variant_data'] == [variant_data[0].get('_id')] # Assert that 'case_data' value of submission is updated assert updated_subm['case_data'] == [case_data[0].get('_id')] # assert that clinvar collection in database has now 2 elements submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 2 # check if it is possible to create CSV files header for variant and casedata objects variants_file_header = clinvar_submission_header(submission_objects, 'variant_data') assert len(variants_file_header.keys()) > 0 casedata_file_header = clinvar_submission_header(submission_objects, 'case_data') assert len(casedata_file_header.keys()) > 0 # check if it is possible to create CSV files lines for variant and casedata objects variants_file_lines = clinvar_submission_lines(submission_objects, variants_file_header) assert len(variants_file_lines[0].split(',')) == len(variants_file_header.keys()) # variant file header and line have the same number of columns casedata_file_lines = clinvar_submission_lines(submission_objects, casedata_file_header) assert len(casedata_file_lines[0].split(',')) == len(casedata_file_header.keys()) # casedata file header and line have the same number of columns # assert that one of these objects is the variant object assert variant_data == adapter.clinvar_objs(submission_obj['_id'], 'variant_data') # assert that one of these objects is the case data object assert case_data == adapter.clinvar_objs(submission_obj['_id'], 'case_data') # assert that a variant is present for case 'case1' assert adapter.case_to_clinVars('case1') == {variant_data[0]['local_id'] : variant_data[0]} # Removal of clinvar objects from submission and from clinvar collection in database # remove case_data object updated_submission = adapter.delete_clinvar_object(object_id=case_data[0]['_id'], object_type='case_data', submission_id=submission_obj['_id']) assert updated_submission['case_data'] == [] # remove variant object updated_submission = adapter.delete_clinvar_object(object_id=variant_data[0]['_id'], object_type='variant_data', submission_id=submission_obj['_id']) assert updated_submission['variant_data'] == [] # assert that there are no objects left in clinvar collection submission_objects = list(adapter.clinvar_collection.find()) assert len(submission_objects) == 0