diff options
author | Frederick Muriuki Muriithi | 2024-08-08 15:31:40 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-08-08 15:31:40 -0500 |
commit | 72f64a5a916221e079f2e06f85c50828dd41bf59 (patch) | |
tree | db0b2303e7478ff41122a0a9d59fd772075053aa /r_qtl/r_qtl2.py | |
parent | c5fd5ac4e1048889f45aa61ee9603c684c2ea909 (diff) | |
download | gn-uploader-72f64a5a916221e079f2e06f85c50828dd41bf59.tar.gz |
Add utility function to extract R/qtl2 zip bundles
Diffstat (limited to 'r_qtl/r_qtl2.py')
-rw-r--r-- | r_qtl/r_qtl2.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py index 0a96e7c..a34caac 100644 --- a/r_qtl/r_qtl2.py +++ b/r_qtl/r_qtl2.py @@ -30,6 +30,26 @@ def __special_file__(filename): return (is_macosx_special_file or is_nix_hidden_file) +def extract(zfile: ZipFile, outputdir: Path) -> tuple[Path, ...]: + """Extract a ZipFile + + This function will extract a zipfile `zfile` to the directory `outputdir`. + + Parameters + ---------- + zfile: zipfile.ZipFile object - the zipfile to extract. + outputdir: Optional pathlib.Path object - where the extracted files go. + + Returns + ------- + A tuple of Path objects, each pointing to a member in the zipfile. + """ + outputdir.mkdir(parents=True, exist_ok=True) + return tuple(Path(zfile.extract(member, outputdir)) + for member in zfile.namelist() + if not __special_file__(member)) + + def control_data(zfile: ZipFile) -> dict: """Retrieve the control file from the zip file info.""" files = tuple(filename |