scout/adapter/mongo/case.py
def load_case(self, config_data, update=False):
        """Load a case into the database

        Check if the owner and the institute exists.

        Args:
            config_data(dict): A dictionary with all the necessary information
            update(bool): If existing case should be updated

        Returns:
            case_obj(dict)
        """
        # Check that the owner exists in the database
        institute_obj = self.institute(config_data['owner'])
        if not institute_obj:
            raise IntegrityError("Institute '%s' does not exist in database" % config_data['owner'])

        # Parse the case information
        parsed_case = parse_case(config=config_data)
        # Build the case object
        case_obj = build_case(parsed_case, self)
        # Check if case exists with old case id
        old_caseid = '-'.join([case_obj['owner'], case_obj['display_name']])
        old_case = self.case(old_caseid)
        if old_case:
            LOG.info("Update case id for existing case: %s -> %s", old_caseid, case_obj['_id'])
            self.update_caseid(old_case, case_obj['_id'])
            update = True

        # Check if case exists in database
        existing_case = self.case(case_obj['_id'])
        if existing_case and not update:
            raise IntegrityError("Case %s already exists in database" % case_obj['_id'])

        files = [
            {'file_name': 'vcf_snv', 'variant_type': 'clinical', 'category': 'snv'},
            {'file_name': 'vcf_sv', 'variant_type': 'clinical', 'category': 'sv'},
            {'file_name': 'vcf_cancer', 'variant_type': 'clinical', 'category': 'cancer'},
            {'file_name': 'vcf_str', 'variant_type': 'clinical', 'category': 'str'}
        ]

        try:
            for vcf_file in files:
                # Check if file exists
                if not case_obj['vcf_files'].get(vcf_file['file_name']):
                    LOG.debug("didn't find {}, skipping".format(vcf_file['file_name']))
                    continue

                variant_type = vcf_file['variant_type']
                category = vcf_file['category']
                if update:
                    self.delete_variants(
                        case_id=case_obj['_id'],
                        variant_type=variant_type,
                        category=category
                    )
                self.load_variants(
                    case_obj=case_obj,
                    variant_type=variant_type,
                    category=category,
                    rank_threshold=case_obj.get('rank_score_threshold', 0),
                )

        except (IntegrityError, ValueError, ConfigError, KeyError) as error:
            LOG.warning(error)

        if existing_case and update:
            self.update_case(case_obj)
        else:
            LOG.info('Loading case %s into database', case_obj['display_name'])
            self._add_case(case_obj)

        return case_obj
def load_case(self, config_data, update=False):
        """Load a case into the database

        Check if the owner and the institute exists.

        Args:
            config_data(dict): A dictionary with all the necessary information
            update(bool): If existing case should be updated

        Returns:
            case_obj(dict)
        """
        # Check that the owner exists in the database
        institute_obj = self.institute(config_data['owner'])
        if not institute_obj:
            raise IntegrityError("Institute '%s' does not exist in database" % config_data['owner'])

        # Parse the case information
        parsed_case = parse_case(config=config_data)
        # Build the case object
        case_obj = build_case(parsed_case, self)
        # Check if case exists with old case id
        old_caseid = '-'.join([case_obj['owner'], case_obj['display_name']])
        old_case = self.case(old_caseid)
        if old_case:
            LOG.info("Update case id for existing case: %s -> %s", old_caseid, case_obj['_id'])
            self.update_caseid(old_case, case_obj['_id'])
            update = True

        # Check if case exists in database
        existing_case = self.case(case_obj['_id'])
        if existing_case and not update:
            raise IntegrityError("Case %s already exists in database" % case_obj['_id'])

        files = [
            {'file_name': 'vcf_snv', 'variant_type': 'clinical', 'category': 'snv'},
            {'file_name': 'vcf_sv', 'variant_type': 'clinical', 'category': 'sv'},
            {'file_name': 'vcf_cancer', 'variant_type': 'clinical', 'category': 'cancer'},
            {'file_name': 'vcf_str', 'variant_type': 'clinical', 'category': 'str'}
        ]

        try:
            for vcf_file in files:
                # Check if file exists
                if not case_obj['vcf_files'].get(vcf_file['file_name']):
                    LOG.debug("didn't find {}, skipping".format(vcf_file['file_name']))
                    continue

                variant_type = vcf_file['variant_type']
                category = vcf_file['category']
                if update:
                    self.delete_variants(
                        case_id=case_obj['_id'],
                        variant_type=variant_type,
                        category=category
                    )
                self.load_variants(
                    case_obj=case_obj,
                    variant_type=variant_type,
                    category=category,
                    rank_threshold=case_obj.get('rank_score_threshold', 0),
                )

        except (IntegrityError, ValueError, ConfigError, KeyError) as error:
            LOG.warning(error)

        if existing_case and update:
            self.update_case(case_obj)
        else:
            LOG.info('Loading case %s into database', case_obj['display_name'])
            self._add_case(case_obj)

        return case_obj
Load a case into the database

        Check if the owner and the institute exists.

        Args:
            config_data(dict): A dictionary with all the necessary information
            update(bool): If existing case should be updated

        Returns:
            case_obj(dict)