From 075b554cdde11f32e73981222a2cede3bb249151 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 21 Feb 2024 09:20:37 +0300 Subject: Check that samples/cases are consistent Ensure that **ALL** samples/cases/individuals mentioned in any of the pheno files actually exist in at least one of the geno files. --- r_qtl/r_qtl2.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'r_qtl/r_qtl2.py') diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index 1e28bc0..87491d0 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -368,27 +368,21 @@ def read_geno_file_data( replace_genotype_codes, genocodes=cdata.get("genotypes", {}))) -def load_samples( - zipfilepath: Union[str, Path], filetype: str) -> tuple[str, ...]: - """Load the samples/cases/individuals from file(s) of type 'filetype'.""" - cdata = read_control_file(zipfilepath) +def load_samples(zipfilepath: Union[str, Path], + member: str, + transposed: bool) -> tuple[str, ...]: + """Load the samples/cases/individuals from file 'member'.""" + filedata = read_geno_file_data(zipfilepath, member) samples: set[str] = set() - for afile in cdata.get(filetype, []): - filedata = read_geno_file_data(zipfilepath, afile) - if cdata.get(f"{filetype}_transposed", False): + if transposed: + samples.update( + item for item in next(filedata)[1:] if item is not None) + else: + try: + next(filedata)# Ignore first row. samples.update( - item for item in next(filedata)[1:] if item is not None) - else: - try: - next(filedata)# Ignore first row. - samples.update( - line[0] for line in filedata if line[0] is not None) - except StopIteration:# Empty file. - pass + line[0] for line in filedata if line[0] is not None) + except StopIteration:# Empty file. + pass return tuple(samples) - - -load_geno_samples = partial(load_samples, filetype="geno") -load_founder_geno_samples = partial(load_samples, filetype="founder_geno") -load_pheno_samples = partial(load_samples, filetype="pheno") -- cgit v1.2.3