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 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()
def test_get_file_handle(vcf_path): vcf = get_file_handle(vcf_path) assert type(vcf) is VCF
def test_get_vcf_non_existing(): with pytest.raises(IOError): vcf = get_file_handle('hello')
def test_get_vcf_non_vcf(ped_path): with pytest.raises(IOError): vcf = get_file_handle(ped_path)
def test_get_zipped_file_handle(zipped_vcf_path): vcf = get_file_handle(zipped_vcf_path) assert type(vcf) is type(gzip.open(zipped_vcf_path, 'r'))
def test_get_file_handle(vcf_path): vcf = get_file_handle(vcf_path) assert type(vcf) is type(open(vcf_path, 'r'))