def test_parse_case(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct case id assert case_data['case_id'] == '{0}-{1}'.format(scout_config['owner'], scout_config['family'])
def test_parse_case_date(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have an analysis_date assert isinstance(scout_config["analysis_date"], datetime) assert isinstance(case_data["analysis_date"], datetime)
def test_parse_case_rank_model_version(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same rank model version like the config assert case_data["rank_model_version"] == scout_config[ "rank_model_version"]
def test_parse_case_rank_threshold(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same panels like the config assert case_data["rank_score_threshold"] == scout_config[ "rank_score_threshold"]
def test_parse_case_delivery_report(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # then we should find the delivery report in the parsed data assert case_data['delivery_report'] == scout_config['delivery_report']
def test_parse_case_no_date(scout_config): # GIVEN a load config without a date scout_config.pop("analysis_date") # WHEN case is parsed case_data = parse_case(scout_config) # THEN the todays date should have been set assert "analysis_date" not in scout_config assert isinstance(case_data["analysis_date"], datetime)
def test_parse_case_wrong_date_string(scout_config): # GIVEN you load info thats not a date scout_config["analysis_date"] = "not a date" # WHEN case is parsed case_data = parse_case(scout_config) # THEN the todays date should have been set assert isinstance(scout_config["analysis_date"], str) assert isinstance(case_data["analysis_date"], datetime)
def test_parse_case_date_string(scout_config): # GIVEN a load config with date string # WHEN case is parsed scout_config["analysis_date"] = "2019-11-05" case_data = parse_case(scout_config) # THEN the case should have a datetime object assert isinstance(scout_config["analysis_date"], str) assert isinstance(case_data["analysis_date"], datetime)
def test_parse_case_delivery_report(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # then we should find the delivery report in the parsed data assert case_data['delivery_report'] == scout_config['delivery_report']
def test_parse_case_limsid(scout_config): """Test parsing a case with lims_id""" # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the lims ID should be the same as in config assert case_data["lims_id"] == scout_config["lims_id"]
def test_parse_case_vcf_files(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should the same vcf files as specified in the assert case_data['vcf_files']['vcf_snv'] == scout_config['vcf_snv'] assert case_data['vcf_files']['vcf_sv'] == scout_config['vcf_sv'] assert case_data['vcf_files']['vcf_snv_research'] == scout_config['vcf_snv_research'] assert case_data['vcf_files']['vcf_sv_research'] == scout_config['vcf_sv_research']
def test_parse_case_vcf_files(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should the same vcf files as specified in the assert case_data['vcf_files']['vcf_snv'] == scout_config['vcf_snv'] assert case_data['vcf_files']['vcf_sv'] == scout_config['vcf_sv'] assert case_data['vcf_files']['vcf_snv_research'] == scout_config['vcf_snv_research'] assert case_data['vcf_files']['vcf_sv_research'] == scout_config['vcf_sv_research']
def test_parse_case_alignment_path(scout_config): # GIVEN a load config with bam_file as key to bam/cram files bam_path = "a bam" for sample in scout_config["samples"]: sample["alignment_path"] = bam_path # WHEN case is parsed case_data = parse_case(scout_config) # THEN assert that bam files are added correct for ind in case_data["individuals"]: assert ind["bam_file"] == bam_path
def test_missing_optional_igv_param(scout_config): # WHEN a dict is missing optinal wig param (later passed to igv.js) # i.e. rhocall_wig scout_config.pop("rhocall_bed", "ignore_return") scout_config.pop("rhocall_wig", "ignore_return") scout_config.pop("upd_regions_bed", "ignore_return") scout_config.pop("upd_sites_bed", "ignore_return") scout_config.pop("tiddit_coverage_wig", "ignore_return") # THEN parsing the config will not raise an exception case_data = parse_case(scout_config) assert case_data
def load_scout(adapter, config, ped=None, update=False): """Load a new case from a Scout config. Args: adapter(MongoAdapter) config(dict): loading info ped(Iterable(str)): Pedigree ingformation update(bool): If existing case should be updated """ log.info("Check that the panels exists") if not check_panels(adapter, config.get('gene_panels', []), config.get('default_gene_panels')): raise ConfigError("Some panel(s) does not exist in the database") log.debug('parse case data from config and ped') case_data = parse_case(config, ped) log.debug('build case object from parsed case data') case_obj = build_case(case_data, adapter) log.info("Delete variants for case %s", case_obj['case_id']) delete_variants(adapter=adapter, case_obj=case_obj) log.info("Load clinical SNV variants for case %s", case_obj['case_id']) adapter.load_variants(case_obj=case_obj, variant_type='clinical', category='snv', rank_threshold=case_data['rank_score_threshold']) if config.get('vcf_sv'): log.info("Load SV variants for case %s", case_obj['case_id']) adapter.load_variants(case_obj=case_obj, variant_type='clinical', category='sv', rank_threshold=case_data['rank_score_threshold']) log.debug('load case object into database') load_case( adapter=adapter, case_obj=case_obj, update=update, )
def test_parse_optional_igv_param(scout_config): # GIVEN a dict contains optional igv params # i.e. rhocall_wig samples = scout_config["samples"] # WHEN optional parameters are added to config for sample in samples: sample["rhocall_bed"] = "path/to/rb" sample["rhocall_wig"] = "path/to/rw" sample["upd_regions_bed"] = "path/to/up" sample["upd_sites_bed"] = "path/to/us" sample["tiddit_coverage_wig"] = "path/to/tc" scout_config["samples"] = samples # THEN parsing the config will add those to case data case_data = parse_case(scout_config) case_list = [] config_list = [] for individual in case_data["individuals"]: case_list.append(( individual["rhocall_wig"], individual["rhocall_bed"], individual["upd_regions_bed"], individual["upd_sites_bed"], individual["tiddit_coverage_wig"], )) for sample in samples: config_list.append(( sample["rhocall_wig"], sample["rhocall_bed"], sample["upd_regions_bed"], sample["upd_sites_bed"], sample["tiddit_coverage_wig"], )) assert config_list == case_list
def test_parse_case_collaborators(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have a list with collaborators assert case_data['collaborators'] == [scout_config['owner']]
def test_parse_case_madeline(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct case id assert case_data['madeline_info']
def test_parse_case_minimal_config(minimal_config): # GIVEN a minimal config # WHEN parsing the config case_data = parse_case(minimal_config) # THEN assert is was parsed correct assert case_data
def test_parse_case(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct case id assert case_data["case_id"] == scout_config["family"]
def test_parse_case_madeline(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct case id assert case_data['madeline_info']
def parsed_case(request, scout_config): """Get the lines for a case""" case = parse_case(scout_config) return case
def test_parse_case_minimal_config(minimal_config): # GIVEN a minimal config # WHEN parsing the config case_data = parse_case(minimal_config) # THEN assert is was parsed correct assert case_data
def test_parse_case_default_panels(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same panels like the config assert case_data['default_panels'] == scout_config['default_gene_panels']
def test_parse_case_rank_threshold(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same panels like the config assert case_data['rank_score_threshold'] == scout_config['rank_score_threshold']
def test_parse_case_rank_model_version(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same rank model version like the config assert case_data['rank_model_version'] == scout_config['rank_model_version']
def test_parse_case(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have a owner assert case_data['owner'] == scout_config['owner']
def test_parse_case_madeline(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct chromograph_image_files assert case_data["chromograph_image_files"]
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 cancer_parsed_case(request, cancer_scout_config): """Get the lines for a cancer case""" case = parse_case(cancer_scout_config) return case
def test_parse_case_default_panels(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have the same panels like the config assert case_data['default_panels'] == scout_config['default_gene_panels']
def test_parse_case(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case a correct case id assert case_data['case_id'] == scout_config['family']
def test_parse_case_collaborators(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have a list with collaborators assert case_data['collaborators'] == [scout_config['owner']]
def test_parse_case(scout_config): # GIVEN you load sample information from a scout config # WHEN case is parsed case_data = parse_case(scout_config) # THEN the case should have a owner assert case_data['owner'] == scout_config['owner']
def load_case(self, config_data, update=False, keep_actions=True): """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 keep_actions(bool): Attempt transfer of existing case user actions to new vars 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) # This is to keep sanger order and validation status old_sanger_variants = self.case_sanger_variants(case_obj["_id"]) 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"]) old_evaluated_variants = ( None # acmg, manual rank, cancer tier, dismissed, mosaic, commented ) if existing_case and keep_actions: # collect all variants with user actions for this case old_evaluated_variants = list( self.evaluated_variants(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_cancer_sv", "variant_type": "clinical", "category": "cancer_sv", }, { "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", 5), ) except (IntegrityError, ValueError, ConfigError, KeyError) as error: LOG.warning(error) if existing_case: case_obj["rerun_requested"] = False if case_obj["status"] in ["active", "archived"]: case_obj["status"] = "inactive" self.update_case(case_obj) # update Sanger status for the new inserted variants self.update_case_sanger_variants(institute_obj, case_obj, old_sanger_variants) if keep_actions and old_evaluated_variants: self.update_variant_actions(institute_obj, case_obj, old_evaluated_variants) else: LOG.info("Loading case %s into database", case_obj["display_name"]) self._add_case(case_obj) return case_obj