Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse file format from extension (ignore compression) #41

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions snakemake_wrapper_utils/snakemake.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def get_mem(snakemake, out_unit="MiB"):
"""
Obtain requested memory (from resources) and return in given units.
If no memory resources found, return a value equivalent to 205 .
If no memory resources found, return a value equivalent to 205.
"""

# Store memory in MiB
Expand All @@ -22,8 +22,26 @@ def get_mem(snakemake, out_unit="MiB"):


def is_arg(arg, cmd):
"""Check command for the presence of argument"""
if arg in cmd.replace("=", " ").split(" "):
return True
"""Check command for the presence of argument."""
return arg in cmd.replace("=", " ").split(" ")

return False

def get_format(path):
from pathlib import Path
"""Get file format from extension, ignoring common compressions."""
if not path:
raise ValueError("Path cannot be empty")
exts = Path(path).suffixes
if not exts:
raise ValueError("Path must have an extension")
if exts[-1] in (".gz", ".bgz", ".bz2"):
ext = exts[-2]
else:
ext = exts[-1]

if ext in (".fq", ".fastq"):
return "fastq"
elif ext in (".fa", ".fas", ".fna", ".fasta"):
return "fasta"
else:
return ext.lstrip(".").lower()