Skip to content

Commit e33e85c

Browse files
authored
Merge pull request #103 from maxplanck-ie/fix_dir
improved organism2directory mapping
2 parents 647470b + ee4144d commit e33e85c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

BRB/PushButton.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
from BRB.logger import log
88
import stat
99
from pathlib import Path
10+
import re
11+
12+
def organism2Dir(organism):
13+
""" Convert organism name - such as
14+
M. Musculus (mm10 / GRCm39) -> M_Musculus_mm10_GRCm39
15+
The main goal is to have a simple directory name
16+
"""
17+
# Replace all spaces and special characters with underscores
18+
directory = re.sub(r'[^\w]', '_', organism)
19+
# Collapse multiple underscores into one
20+
directory = re.sub(r'_+', '_', directory)
21+
# Remove trailing underscores
22+
directory = re.sub(r'_+$', '', directory)
23+
return directory
24+
1025

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

0 commit comments

Comments
 (0)