scout/commands/update/case.py
def case(context, case_id, case_name, institute, collaborator, vcf, vcf_sv,
         vcf_cancer, vcf_research, vcf_sv_research, vcf_cancer_research, peddy_ped,
         reupload_sv, rankscore_treshold, rankmodel_version):
    """
    Update a case in the database
    """
    adapter = context.obj['adapter']
    if not case_id:
        if not (case_name and institute):
            LOG.info("Please specify which case to update.")
            context.abort
        case_id = "{0}-{1}".format(institute, case_name)
    # Check if the case exists
    case_obj = adapter.case(case_id)
    
    if not case_obj:
        LOG.warning("Case %s could not be found", case_id)
        context.abort()
    
    case_changed = False
    if collaborator:
        if not adapter.institute(collaborator):
            LOG.warning("Institute %s could not be found", collaborator)
            context.abort()
        if not collaborator in case_obj['collaborators']:
            case_changed = True
            case_obj['collaborators'].append(collaborator)
            LOG.info("Adding collaborator %s", collaborator)
    
    if vcf:
        LOG.info("Updating 'vcf_snv' to %s", vcf)
        case_obj['vcf_files']['vcf_snv'] = vcf
        case_changed = True
    if vcf_sv:
        LOG.info("Updating 'vcf_sv' to %s", vcf_sv)
        case_obj['vcf_files']['vcf_sv'] = vcf_sv
        case_changed = True
    if vcf_cancer:
        LOG.info("Updating 'vcf_cancer' to %s", vcf_cancer)
        case_obj['vcf_files']['vcf_cancer'] = vcf_cancer
        case_changed = True
    if vcf_research:
        LOG.info("Updating 'vcf_research' to %s", vcf_research)
        case_obj['vcf_files']['vcf_research'] = vcf_research
        case_changed = True
    if vcf_sv_research:
        LOG.info("Updating 'vcf_sv_research' to %s", vcf_sv_research)
        case_obj['vcf_files']['vcf_sv_research'] = vcf_sv_research
        case_changed = True
    if vcf_cancer_research:
        LOG.info("Updating 'vcf_cancer_research' to %s", vcf_cancer_research)
        case_obj['vcf_files']['vcf_cancer_research'] = vcf_cancer_research
        case_changed = True
    
    if case_changed:
        adapter.update_case(case_obj)
    
    if reupload_sv:
        LOG.info("Set needs_check to True for case %s", case_id)
        updates = {'needs_check': True}
        if rankscore_treshold:
            updates['sv_rank_model_version'] = rankmodel_version
        if vcf_sv:
            updates['vcf_files.vcf_sv'] = vcf_sv
        if vcf_sv:
            updates['vcf_files.vcf_sv_research'] = vcf_sv_research
            
        updated_case = adapter.case_collection.find_one_and_update(
            {'_id':case_id}, 
            {'$set': updates
            },
            return_document=pymongo.ReturnDocument.AFTER
        )
        rankscore_treshold = rankscore_treshold or updated_case.get("rank_score_threshold", 5)
        # Delete and reload the clinical SV variants
        if updated_case['vcf_files'].get('vcf_sv'):
            adapter.delete_variants(case_id, variant_type='clinical', category='sv')
            adapter.load_variants(updated_case, variant_type='clinical', 
                                  category='sv', rank_threshold=rankscore_treshold)
        # Delete and reload research SV variants
        if updated_case['vcf_files'].get('vcf_sv_research'):
            adapter.delete_variants(case_id, variant_type='research', category='sv')
            if updated_case.get('is_research'):
                adapter.load_variants(updated_case, variant_type='research', 
                                      category='sv', rank_threshold=rankscore_treshold)
def case(context, case_id, case_name, institute, collaborator, vcf, vcf_sv,
         vcf_cancer, vcf_research, vcf_sv_research, vcf_cancer_research, peddy_ped,
         reupload_sv, rankscore_treshold, rankmodel_version):
    """
    Update a case in the database
    """
    adapter = context.obj['adapter']
    if not case_id:
        if not (case_name and institute):
            LOG.info("Please specify which case to update.")
            context.abort
        case_id = "{0}-{1}".format(institute, case_name)
    # Check if the case exists
    case_obj = adapter.case(case_id)
    
    if not case_obj:
        LOG.warning("Case %s could not be found", case_id)
        context.abort()
    
    case_changed = False
    if collaborator:
        if not adapter.institute(collaborator):
            LOG.warning("Institute %s could not be found", collaborator)
            context.abort()
        if not collaborator in case_obj['collaborators']:
            case_changed = True
            case_obj['collaborators'].append(collaborator)
            LOG.info("Adding collaborator %s", collaborator)
    
    if vcf:
        LOG.info("Updating 'vcf_snv' to %s", vcf)
        case_obj['vcf_files']['vcf_snv'] = vcf
        case_changed = True
    if vcf_sv:
        LOG.info("Updating 'vcf_sv' to %s", vcf_sv)
        case_obj['vcf_files']['vcf_sv'] = vcf_sv
        case_changed = True
    if vcf_cancer:
        LOG.info("Updating 'vcf_cancer' to %s", vcf_cancer)
        case_obj['vcf_files']['vcf_cancer'] = vcf_cancer
        case_changed = True
    if vcf_research:
        LOG.info("Updating 'vcf_research' to %s", vcf_research)
        case_obj['vcf_files']['vcf_research'] = vcf_research
        case_changed = True
    if vcf_sv_research:
        LOG.info("Updating 'vcf_sv_research' to %s", vcf_sv_research)
        case_obj['vcf_files']['vcf_sv_research'] = vcf_sv_research
        case_changed = True
    if vcf_cancer_research:
        LOG.info("Updating 'vcf_cancer_research' to %s", vcf_cancer_research)
        case_obj['vcf_files']['vcf_cancer_research'] = vcf_cancer_research
        case_changed = True
    
    if case_changed:
        adapter.update_case(case_obj)
    
    if reupload_sv:
        LOG.info("Set needs_check to True for case %s", case_id)
        updates = {'needs_check': True}
        if rankscore_treshold:
            updates['sv_rank_model_version'] = rankmodel_version
        if vcf_sv:
            updates['vcf_files.vcf_sv'] = vcf_sv
        if vcf_sv:
            updates['vcf_files.vcf_sv_research'] = vcf_sv_research
            
        updated_case = adapter.case_collection.find_one_and_update(
            {'_id':case_id}, 
            {'$set': updates
            },
            return_document=pymongo.ReturnDocument.AFTER
        )
        rankscore_treshold = rankscore_treshold or updated_case.get("rank_score_threshold", 5)
        # Delete and reload the clinical SV variants
        if updated_case['vcf_files'].get('vcf_sv'):
            adapter.delete_variants(case_id, variant_type='clinical', category='sv')
            adapter.load_variants(updated_case, variant_type='clinical', 
                                  category='sv', rank_threshold=rankscore_treshold)
        # Delete and reload research SV variants
        if updated_case['vcf_files'].get('vcf_sv_research'):
            adapter.delete_variants(case_id, variant_type='research', category='sv')
            if updated_case.get('is_research'):
                adapter.load_variants(updated_case, variant_type='research', 
                                      category='sv', rank_threshold=rankscore_treshold)
Update a case in the database