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

improved organism2directory mapping #103

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
20 changes: 18 additions & 2 deletions BRB/PushButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
from BRB.logger import log
import stat
from pathlib import Path
import re

def organism2Dir(organism):
""" Convert organism name - such as
M. Musculus (mm10 / GRCm39) -> M_Musculus_mm10_GRCm39
The main goal is to have a simple directory name
"""
# Replace all spaces and special characters with underscores
directory = re.sub(r'[^\w]', '_', organism)
# Collapse multiple underscores into one
directory = re.sub(r'_+', '_', directory)
# Remove trailing underscores
directory = re.sub(r'_+$', '', directory)
return directory


def createPath(config, group, project, organism, libraryType, tuples):
"""Ensures that the output path exists, creates it otherwise, and return where it is"""
Expand All @@ -22,8 +37,9 @@ def createPath(config, group, project, organism, libraryType, tuples):
BRB.misc.pacifier(project))
os.makedirs(baseDir, mode=0o700, exist_ok=True)
#org = organism.split(' ')[0].lower() # splitting bad idea for "M. musculus" etc.
org = organism2Org(config, organism)
oDir = os.path.join(baseDir, "{}_{}".format(BRB.misc.pacifier(libraryType), org))
#org = organism2Org(config, organism) # bad when organism is a dir/dir/file.yaml
analysis_dir = organism2Dir(organism)
oDir = os.path.join(baseDir, "{}_{}".format(BRB.misc.pacifier(libraryType), analysis_dir))
os.makedirs(oDir, mode=0o700, exist_ok=True)
return oDir

Expand Down