def test_delete_case_and_variants(vcf_path, ped_path, mongo_adapter, case_id): db = mongo_adapter.db load_database( adapter=mongo_adapter, variant_file=vcf_path, family_file=ped_path, family_type='ped', ) mongo_case = db.case.find_one() assert mongo_case['case_id'] == case_id delete( adapter=mongo_adapter, variant_file=vcf_path, family_file=ped_path, family_type='ped', ) mongo_case = db.case.find_one() assert mongo_case == None mongo_variant = db.case.find_one() assert mongo_variant == None
def test_load_database_wrong_ped(vcf_path, funny_ped_path, mongo_adapter): db = mongo_adapter.db with pytest.raises(CaseError): load_database( adapter=mongo_adapter, variant_file=vcf_path, family_file=funny_ped_path, family_type='ped', )
def test_load_database_wrong_ped(vcf_path, funny_ped_path, mongo_adapter): ## GIVEN a vcf and ped file with wrong individuals ## WHEN loading the information ## THEN Error should be raised since individuals is not in vcf with pytest.raises(CaseError): load_database( adapter=mongo_adapter, variant_file=vcf_path, family_file=funny_ped_path, family_type='ped', )
def test_load_database_alternative_ped(vcf_path, ped_path, mongo_adapter, case_id): db = mongo_adapter.db load_database(adapter=mongo_adapter, variant_file=vcf_path, family_file=ped_path, family_type='ped', case_id='alternative') mongo_case = db.case.find_one() mongo_variant = db.variant.find_one() assert mongo_case['case_id'] == 'alternative' assert mongo_variant['families'] == ['alternative']
def load(self, family_id: str, ped_path: str, vcf_path: str) -> dict: """Add observations from a VCF.""" variant_handle = get_file_handle(vcf_path) nr_variants = check_vcf(variant_handle) load_database( adapter=self, variant_file=vcf_path, family_file=ped_path, family_type='ped', case_id=family_id, gq_treshold=20, nr_variants=nr_variants, ) self.check_indexes() return dict(variants=nr_variants)
def test_load_database_alternative_ped(vcf_path, ped_path, mongo_adapter, case_id): db = mongo_adapter.db load_database( adapter=mongo_adapter, variant_file=vcf_path, family_file=ped_path, family_type='ped', case_id='alternative' ) mongo_case = db.case.find_one() mongo_variant = db.variant.find_one() assert mongo_case['case_id'] == 'alternative' assert mongo_variant['families'] == ['alternative']
def load(ctx, variant_file, family_file, family_type, skip_case_id, gq_treshold, case_id): """Load the variants of a case The loading is based on if the variant is seen in a ny affected individual in the family. """ if not family_file: logger.warning("Please provide a family file") ctx.abort() variant_path = os.path.abspath(variant_file) adapter = ctx.obj['adapter'] try: variant_handle = get_file_handle(variant_path) nr_variants = check_vcf(variant_handle) except VcfError as error: logger.warning(error) ctx.abort() logger.info("Vcf file looks fine") logger.info("Nr of variants in vcf: {0}".format(nr_variants)) start_inserting = datetime.now() try: nr_inserted = load_database( adapter=adapter, variant_file=variant_path, family_file=family_file, family_type=family_type, skip_case_id=skip_case_id, case_id=case_id, gq_treshold=gq_treshold, nr_variants=nr_variants, ) except (SyntaxError, CaseError, IOError) as error: logger.warning(error) ctx.abort() logger.info("Time to insert variants: {0}".format( datetime.now() - start_inserting))
def load(ctx, variant_file, family_file, family_type, skip_case_id, gq_treshold, case_id): """Load the variants of a case The loading is based on if the variant is seen in a ny affected individual in the family. """ if not family_file: logger.warning("Please provide a family file") ctx.abort() variant_path = os.path.abspath(variant_file) adapter = ctx.obj['adapter'] try: variant_handle = get_file_handle(variant_path) nr_variants = check_vcf(variant_handle) except VcfError as error: logger.warning(error) ctx.abort() logger.info("Vcf file looks fine") logger.info("Nr of variants in vcf: {0}".format(nr_variants)) start_inserting = datetime.now() try: nr_inserted = load_database( adapter=adapter, variant_file=variant_path, family_file=family_file, family_type=family_type, skip_case_id=skip_case_id, case_id=case_id, gq_treshold=gq_treshold, nr_variants=nr_variants, ) except (SyntaxError, CaseError, IOError) as error: logger.warning(error) ctx.abort() logger.info("Time to insert variants: {0}".format(datetime.now() - start_inserting)) adapter.check_indexes()