scout/commands/load/variants.py
def variants(context, case_id, institute, force, cancer, cancer_research, sv, 
             sv_research, snv, snv_research, str_clinical, chrom, start, end, hgnc_id, 
             hgnc_symbol, rank_treshold):
    """Upload variants to a case

        Note that the files has to be linked with the case, 
        if they are not use 'scout update case'.
    """
    LOG.info("Running scout load variants")
    adapter = context.obj['adapter']
    
    if institute:
        case_id = "{0}-{1}".format(institute, case_id)
    else:
        institute = case_id.split('-')[0]
    case_obj = adapter.case(case_id=case_id)
    if case_obj is None:
        LOG.info("No matching case found")
        context.abort()

    files = [
        {'category': 'cancer', 'variant_type': 'clinical', 'upload': cancer},
        {'category': 'cancer', 'variant_type': 'research', 'upload': cancer_research},
        {'category': 'sv', 'variant_type': 'clinical', 'upload': sv},
        {'category': 'sv', 'variant_type': 'research', 'upload': sv_research},
        {'category': 'snv', 'variant_type': 'clinical', 'upload': snv},
        {'category': 'snv', 'variant_type': 'research', 'upload': snv_research},
        {'category': 'str', 'variant_type': 'clinical', 'upload': str_clinical},
    ]
    
    gene_obj = None
    if (hgnc_id or hgnc_symbol):
        if hgnc_id:
            gene_obj = adapter.hgnc_gene(hgnc_id)
        if hgnc_symbol:
            for res in adapter.gene_by_alias(hgnc_symbol):
                gene_obj = res
        if not gene_obj:
            LOG.warning("The gene could not be found")
            context.abort()
        
    i = 0
    for file_type in files:
        variant_type = file_type['variant_type']
        category = file_type['category']
        
        if file_type['upload']:
            i += 1
            if variant_type == 'research':
                if not (force or case_obj['research_requested']):
                    LOG.warn("research not requested, use '--force'")
                    context.abort()
            
            LOG.info("Delete {0} {1} variants for case {2}".format(
                         variant_type, category, case_id))
            adapter.delete_variants(case_id=case_obj['_id'], 
                                    variant_type=variant_type,
                                    category=category)
            
            LOG.info("Load {0} {1} variants for case {2}".format(
                         variant_type, category, case_id))
            
            try:
                adapter.load_variants(
                    case_obj=case_obj, 
                    variant_type=variant_type, 
                    category=category,
                    rank_threshold=rank_treshold, 
                    chrom=chrom, 
                    start=start, 
                    end=end,
                    gene_obj=gene_obj
                )
            except Exception as e:
                LOG.warning(e)
                context.abort()
    if i == 0:
        LOG.info("No files where specified to upload variants from")
def variants(context, case_id, institute, force, cancer, cancer_research, sv, 
             sv_research, snv, snv_research, str_clinical, chrom, start, end, hgnc_id, 
             hgnc_symbol, rank_treshold):
    """Upload variants to a case

        Note that the files has to be linked with the case, 
        if they are not use 'scout update case'.
    """
    LOG.info("Running scout load variants")
    adapter = context.obj['adapter']
    
    if institute:
        case_id = "{0}-{1}".format(institute, case_id)
    else:
        institute = case_id.split('-')[0]
    case_obj = adapter.case(case_id=case_id)
    if case_obj is None:
        LOG.info("No matching case found")
        context.abort()

    files = [
        {'category': 'cancer', 'variant_type': 'clinical', 'upload': cancer},
        {'category': 'cancer', 'variant_type': 'research', 'upload': cancer_research},
        {'category': 'sv', 'variant_type': 'clinical', 'upload': sv},
        {'category': 'sv', 'variant_type': 'research', 'upload': sv_research},
        {'category': 'snv', 'variant_type': 'clinical', 'upload': snv},
        {'category': 'snv', 'variant_type': 'research', 'upload': snv_research},
        {'category': 'str', 'variant_type': 'clinical', 'upload': str_clinical},
    ]
    
    gene_obj = None
    if (hgnc_id or hgnc_symbol):
        if hgnc_id:
            gene_obj = adapter.hgnc_gene(hgnc_id)
        if hgnc_symbol:
            for res in adapter.gene_by_alias(hgnc_symbol):
                gene_obj = res
        if not gene_obj:
            LOG.warning("The gene could not be found")
            context.abort()
        
    i = 0
    for file_type in files:
        variant_type = file_type['variant_type']
        category = file_type['category']
        
        if file_type['upload']:
            i += 1
            if variant_type == 'research':
                if not (force or case_obj['research_requested']):
                    LOG.warn("research not requested, use '--force'")
                    context.abort()
            
            LOG.info("Delete {0} {1} variants for case {2}".format(
                         variant_type, category, case_id))
            adapter.delete_variants(case_id=case_obj['_id'], 
                                    variant_type=variant_type,
                                    category=category)
            
            LOG.info("Load {0} {1} variants for case {2}".format(
                         variant_type, category, case_id))
            
            try:
                adapter.load_variants(
                    case_obj=case_obj, 
                    variant_type=variant_type, 
                    category=category,
                    rank_threshold=rank_treshold, 
                    chrom=chrom, 
                    start=start, 
                    end=end,
                    gene_obj=gene_obj
                )
            except Exception as e:
                LOG.warning(e)
                context.abort()
    if i == 0:
        LOG.info("No files where specified to upload variants from")
Upload variants to a case

        Note that the files has to be linked with the case, 
        if they are not use 'scout update case'.