Exemplo n.º 1
0
def test_delete_variants(mongo_adapter, het_variant, case_obj, ind_positions):
    """docstring for test_load_variants"""
    db = mongo_adapter.db

    vcf = []
    vcf.append(het_variant)

    family_id = case_obj.family_id
    individuals = case_obj.individuals

    load_variants(
        adapter=mongo_adapter,
        family_id=family_id,
        individuals=individuals,
        ind_positions=ind_positions,
        vcf=vcf,
        gq_treshold=20,
    )

    mongo_variant = db.variant.find_one()

    assert mongo_variant['families'] == [family_id]

    delete_variants(adapter=mongo_adapter,
                    family_id=family_id,
                    ind_positions=ind_positions,
                    individuals=individuals,
                    vcf=vcf)

    mongo_variant = db.variant.find_one()

    assert mongo_variant == None
Exemplo n.º 2
0
def test_delete_variants(mongo_adapter, het_variant, case_obj):
    """docstring for test_load_variants"""
    db = mongo_adapter.db
    
    vcf = []
    vcf.append(het_variant)
    
    family_id = case_obj.family_id
    individuals = case_obj.individuals
    
    load_variants(
        adapter=mongo_adapter,
        family_id=family_id, 
        individuals=individuals, 
        vcf=vcf,
        gq_treshold=20,
    )
    
    mongo_variant = db.variant.find_one()
    
    assert mongo_variant['families'] == [family_id]

    delete_variants(
        adapter=mongo_adapter,
        family_id=family_id, 
        individuals=individuals, 
        vcf=vcf
    )

    mongo_variant = db.variant.find_one()

    assert mongo_variant == None
Exemplo n.º 3
0
def delete(ctx, variant_file, family_file, family_type, family_id):
    """Delete the variants of a case."""
    if not family_file or family_id:
        logger.error("Please provide a family file or a case id")
        logger.info("Exiting")
        ctx.abort()

    family = get_family(
        family_lines=family_file,
        family_type=family_type
    )

    family_id = family.family_id
    affected_individuals = family.affected_individuals
    adapter = ctx.obj['adapter']

    if variant_file == '-':
        logger.info("Start parsing variants from stdin")
        variant_stream = get_vcf_handle(fsock=sys.stdin)
    else:
        logger.info("Start parsing variants from stdin")
        variant_stream = get_vcf_handle(infile=variant_file)

    start_deleting = datetime.now()
    try:
        count = delete_variants(adapter, variant_stream, family_id,
                                affected_individuals)
    except CaseError as error:
        logger.warning(error.message)
        ctx.abort()

    logger.info("Nr of variants deleted: {0}".format(count))
    logger.info("Time to delete variants: {0}"
                .format(datetime.now() - start_deleting))
Exemplo n.º 4
0
def frequency(context, bulk, remove):
    """Upload or remove variants to/from frequency database."""
    loqusdb_auth = context.obj.get("loqusdb", {})
    adapter = LoqusdbAdapter()
    adapter.connect(**loqusdb_auth)

    mip_case = context.obj["case"]
    if mip_case.is_old:
        logger.warn("unsupported MIP version for frequency: %s", mip_case.version)
    else:
        vcf_path = mip_case.research_vcf
        case_group_id = group_id(mip_case)
        # we only care about "rare" variants
        ped_path = mip_case.configs.pedigree

        try:
            affected_inds = affected_individuals(ped_path)
        except FrequencyError as error:
            logger.warn("LOQUSDB: {}".format(error.message))

        if "affected_inds" in locals():
            with open(vcf_path, "r") as vcf_stream:
                try:
                    if remove:
                        count = delete_variants(adapter, vcf_stream, case_group_id, affected_inds)
                        logger.info("removed {} variants".format(count))
                    else:
                        load_variants(
                            adapter, case_group_id, affected_inds, vcf_stream, bulk_insert=bulk, vcf_path=vcf_path
                        )
                except CaseError as error:
                    logger.warn("LOQUSDB: {}".format(error.message))
Exemplo n.º 5
0
def test_delete_non_existing_variant(mongo_adapter, het_variant, case_obj):
    """docstring for test_load_variants"""
    db = mongo_adapter.db

    vcf = []
    vcf.append(het_variant)
    family_id = case_obj.family_id
    individuals = case_obj.individuals

    delete_variants(adapter=mongo_adapter,
                    family_id=family_id,
                    individuals=individuals,
                    vcf=vcf)

    mongo_variant = db.variant.find_one()

    assert mongo_variant == None
Exemplo n.º 6
0
def test_delete_variant(mongo_adapter, het_variant, case_obj):
    """docstring for test_load_variants"""
    db = mongo_adapter.db

    vcf = []
    vcf.append(het_variant)

    family_id_1 = case_obj.family_id
    individuals = case_obj.individuals

    load_variants(
        adapter=mongo_adapter,
        family_id=family_id_1,
        individuals=individuals,
        vcf=vcf,
        gq_treshold=20,
    )

    mongo_variant = db.variant.find_one()

    assert mongo_variant['families'] == [family_id_1]

    family_id_2 = '2'

    load_variants(
        adapter=mongo_adapter,
        family_id=family_id_2,
        individuals=individuals,
        vcf=vcf,
        gq_treshold=20,
    )

    mongo_variant = db.variant.find_one()

    assert mongo_variant['families'] == [family_id_1, family_id_2]
    assert mongo_variant['observations'] == 2

    delete_variants(adapter=mongo_adapter,
                    family_id=family_id_2,
                    individuals=individuals,
                    vcf=vcf)

    mongo_variant = db.variant.find_one()

    assert mongo_variant['families'] == [family_id_1]
    assert mongo_variant['observations'] == 1
Exemplo n.º 7
0
def test_delete_non_existing_variant(mongo_adapter, het_variant, case_obj):
    """docstring for test_load_variants"""
    db = mongo_adapter.db

    vcf = []
    vcf.append(het_variant)
    family_id = case_obj.family_id
    individuals = case_obj.individuals

    delete_variants(
        adapter=mongo_adapter,
        family_id=family_id,
        individuals=individuals,
        vcf=vcf
    )

    mongo_variant = db.variant.find_one()

    assert mongo_variant == None
Exemplo n.º 8
0
def upload(adapter, vcf_path, affected, case_id, force=False, bulk=True):
    with open(vcf_path, 'r') as vcf_stream:
        try:
            if force:
                count = delete_variants(adapter, vcf_stream,
                                        case_id, affected)
                logger.info("removed {} variants".format(count))

            load_variants(adapter, case_id, affected, vcf_stream,
                          bulk_insert=bulk, vcf_path=vcf_path)
        except CaseError as error:
            logger.warn("LOQUSDB: {}".format(error.message))
Exemplo n.º 9
0
def delete(ctx, variant_file, family_file, family_type, case_id):
    """Delete the variants of a case."""
    if not family_file:
        logger.error("Please provide a family file")
        ctx.abort()

    adapter = ctx.obj['adapter']

    start_deleting = datetime.now()
    try:
        delete_variants(adapter=adapter,
                        variant_file=variant_file,
                        family_file=family_file,
                        family_type=family_type,
                        case_id=case_id)
    except (CaseError, IOError) as error:
        logger.warning(error)
        ctx.abort()

    logger.info("Time to delete variants: {0}".format(datetime.now() -
                                                      start_deleting))
Exemplo n.º 10
0
def delete(ctx, variant_file, family_file, family_type, case_id):
    """Delete the variants of a case."""
    if not family_file:
        logger.error("Please provide a family file")
        ctx.abort()
    
    adapter = ctx.obj['adapter']

    start_deleting = datetime.now()
    try:
        delete_variants(
            adapter=adapter, 
            variant_file=variant_file, 
            family_file=family_file, 
            family_type=family_type,
            case_id=case_id
        )
    except (CaseError, IOError) as error:
        logger.warning(error)
        ctx.abort()

    logger.info("Time to delete variants: {0}"
                .format(datetime.now() - start_deleting))