Skip to content

Commit e3bbf1d

Browse files
committed
change default, deletion safe by including subdir
1 parent 9dc90bd commit e3bbf1d

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

bioproject/cookiecutter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"full_name": "Ward Deboutte",
2+
"full_name": "WardDeb",
33
"email": "w@rddeboutte.com",
44
"python": ["3.11", "3.12", "3.13"],
55
"project_name": "another_project",

bioproject/{{ cookiecutter.project_slug }}/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ These has been kept to a minimum, but required are still:
1010

1111
- `WDIR`: The path to the actual working directory (where intermediate files will be stored).
1212
- `SMK_PROFILE`: Name of (or path to) a working [snakemake profile](https://snakemake.readthedocs.io/en/stable/executing/cli.html#profiles).
13-
- `RESULTSDIR`: Technically not needed (can be left as `./`). In case output files are defined (under RFS), these are kept in sync in this directory. Idea is to have a low-weight 'end result' directory. That can easily be shared.
13+
- `RESULTSDIR`: Technically not needed (can be left as `./`). In case output files are defined (under RFS), these are kept in sync in this directory. Idea is to have a low-weight 'end result' directory. That can easily be shared. Note that the actual results directory will be created inside RESULTSDIR and will be named `Results_{{ cookiecutter.project_slug }}`.
1414

1515

1616
# CONFIG

bioproject/{{ cookiecutter.project_slug }}/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
CONFIGFILE = Path(__file__).parents[0] / 'conf' / 'smk_config.yml'
88
SMK_PROFILE = 'slurmsnake8'
99
WDIR = './'
10-
RESULTSDIR = './'
10+
RESULTSDIR = Path(__file__).parents[0]
1111

1212
# TRACKDIC
1313
trackdic = {
@@ -24,4 +24,5 @@
2424
]
2525

2626
# Update results
27-
print(shipResults(RFS, WDIR, RESULTSDIR, trackdic))
27+
_enddir, filedic = shipResults(RFS, WDIR, RESULTSDIR, trackdic)
28+
print(f"Result in {str(_enddir)}:\n{filedic}")

bioproject/{{ cookiecutter.project_slug }}/scripts/workflow_functions.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def calcHash(filepath):
1111
open(filepath, 'rb').read()
1212
).hexdigest()
1313

14-
def shipResults(filetup, wdir, enddir, trackdic=None, delete=True):
14+
def shipResults(filetup, wdir, enddir, trackdic, delete=True):
1515
'''
1616
filetup is a tuple consisting of:
1717
(filepath, folder, fint)
@@ -28,6 +28,32 @@ def shipResults(filetup, wdir, enddir, trackdic=None, delete=True):
2828
2929
Note that filepath can be a pattern: 'RNA/*.txt' will take all txt files.
3030
'''
31+
enddir = Path(enddir).resolve() / ("Results_" + "{{ cookiecutter.project_slug }}")
32+
enddir.mkdir(parents=True, exist_ok=True)
33+
34+
# Book keeping
35+
with open(Path(enddir) / 'README.txt', 'w') as f:
36+
try:
37+
_commit = sp.check_output(['git', 'log', '-n', '1', '--pretty=format:"%H"']).decode().strip('"')
38+
except sp.CalledProcessError:
39+
_commit = 'unknown'
40+
try:
41+
_remote = sp.check_output(['git', 'config', '--get', 'remote.origin.url']).decode().strip('"').strip('\n')
42+
except sp.CalledProcessError:
43+
_remote = 'unknown'
44+
45+
if not _remote:
46+
_remote = 'unknown'
47+
48+
_lw = 25
49+
_author = trackdic.get('author', 'unknown')
50+
_repo = trackdic.get('repo', 'unknown')
51+
52+
f.write(f"{'Latest update on:':<{_lw}} {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
53+
f.write(f"{'Code created by:':<{_lw}} {_author}\n")
54+
f.write(f"{'Results created with:':<{_lw}} {_repo}\n")
55+
f.write(f"{'Repository code is at:':<{_lw}} {_remote}\n")
56+
f.write(f"{'Commit hash:':<{_lw}} {_commit}\n")
3157

3258
tdic = {
3359
'replaced': 0,
@@ -77,29 +103,8 @@ def shipResults(filetup, wdir, enddir, trackdic=None, delete=True):
77103
if ofile.is_dir() and not any(ofile.iterdir()):
78104
ofile.rmdir()
79105

80-
# Book keeping.
81-
if trackdic:
82-
with open(Path(enddir) / 'README.txt', 'w') as f:
83-
try:
84-
_commit = sp.check_output(['git', 'log', '-n', '1', '--pretty=format:"%H"']).decode().strip('"')
85-
except sp.CalledProcessError:
86-
_commit = 'unknown'
87-
try:
88-
_remote = sp.check_output(['git', 'config', '--get', 'remote.origin.url']).decode().strip('"').strip('\n')
89-
except sp.CalledProcessError:
90-
_remote = 'unknown'
91-
92-
if not _remote:
93-
_remote = 'unknown'
94-
95-
_lw = 25
96-
f.write(f"{'Latest update on:':<{_lw}} {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
97-
f.write(f"{'Code created by:':<{_lw}} {trackdic['author']}\n")
98-
f.write(f"{'Results created with:':<{_lw}} {trackdic['repo']}\n")
99-
f.write(f"{'Repository code is at:':<{_lw}} {_remote}\n")
100-
f.write(f"{'Commit hash:':<{_lw}} {_commit}\n")
101-
102-
return tdic
106+
107+
return (enddir, tdic)
103108

104109

105110
def runSmk(smk, configfile, wdir, profile):

0 commit comments

Comments
 (0)