Skip to content

Commit a0504f5

Browse files
Add MW.md to help agent follow project structure
1 parent 9f5f0b4 commit a0504f5

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

MW.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
MW Snakemake layout and conventions
2+
3+
Purpose
4+
5+
This document describes the conventions and organization used for Snakemake "mw-*" metaworkflows in this workspace so future agents and humans can find and modify workflow components reliably.
6+
7+
Overview
8+
9+
- Each workflow lives under an mw-<name> directory. Many projects include a local mw-lib/ and there is a shared top-level mw-lib/ used as the canonical metaworkflow entry point.
10+
- The canonical Snakemake entry points are Snakefile files (often at mw-lib/Snakefile or mw-<name>/.../Snakefile) that include smaller .smk/.rules/.snake fragments under src/snakemake.
11+
12+
Typical layout (per project)
13+
14+
mw-<name>/
15+
src/snakemake/
16+
rules/ # .smk or .rules rule fragments included by the top-level Snakefile
17+
functions/ # python/.snake helpers to map files/wildcards
18+
imports.py # python imports used by Snakefiles
19+
variables.py # lists of ids, parameters, sometimes variables.snake
20+
tables/ # TSVs (e.g. *ids.tsv) used to populate mwconf['ids']
21+
hooks/
22+
onstart/
23+
onsuccess/
24+
onerror/
25+
envs/ # conda/env YAMLs (R/Python) referenced by rules
26+
scripts/ # helper scripts called by rules (R/Python/SH)
27+
mw-lib/ # per-project library (optional)
28+
out/ # produced outputs (reports, aggregates) - workflow targets live here
29+
inp/ or data/ # (convention) input/raw data may be referenced here or provided via -data repo
30+
31+
Shared metaworkflow (mw-lib/Snakefile)
32+
33+
- The top-level Snakefile uses glob() to include components from ../mw*/src/snakemake: imports.py, wildcard_constraints.smk, variables.{py,snake}, functions/*, rules/*.smk, and tables/*ids.tsv.
34+
- It constructs an mwconf dict (mwconf['ids'], mwconf['targets']) used by rules and scripts; this avoids passing huge config objects into script: blocks.
35+
- Hooks (onstart/onsuccess/onerror) are discovered by glob and executed by the top-level Snakefile.
36+
- The top-level Snakefile assumes workflows and data are organized as sibling mw-* directories so relative globs (../mw*/...) resolve consistently.
37+
38+
inp / out folders: principle and usage
39+
40+
- Principle: separate raw inputs from generated outputs.
41+
- inp/ (or data/) contains raw inputs, imports, symlinks to data repos, or small reference files. It should not contain derived files.
42+
- out/ contains all generated outputs: intermediate files, final reports, aggregated tables, and rendered HTML (examples seen: out/aggregate_coverage_ratio/..., out/quarto/render/...).
43+
- Rules and the top-level rule all frequently reference out/... as final targets. Keeping outputs under out/ makes it easy to clean, snapshot, or publish results.
44+
- Recommended practice: do not write raw inputs into inp/ from workflows. Keep inp/ immutable for reproducibility; write everything generated to out/.
45+
- Many Snakefiles and rules assume these conventions; search for "out/" targets when adding or debugging rules.
46+
47+
Public mw-lib vs per-project mw-lib
48+
49+
- Public/shared mw-lib (repository-root mw-lib or top-level mw-lib/Snakefile) acts as the canonical metaworkflow driver that collects rule fragments and helper modules from all sibling mw-* projects. It is the usual entry point for running multi-project analyses.
50+
- Per-project mw-lib (mw-<name>/mw-lib/) holds reusable rules, scripts, and envs specific to that project. This allows project-level customization while keeping shared behavior centralized.
51+
- Logic: shared mw-lib holds the orchestration and includes fragments from per-project src/snakemake directories. Per-project modules expose rules, variables, and functions that the shared mw-lib can include via relative globs.
52+
53+
Data repos (mw-<name>-data) and symlink organization
54+
55+
- Common pattern: separate code and large data into sibling repositories/directories.
56+
- Code: mw-<name>
57+
- Data: mw-<name>-data
58+
- This separation keeps code repos small and avoids committing large binary/FASTQ/BAM files.
59+
60+
Symlink conventions and how they make workflows seamless
61+
62+
- To make the metaworkflow and per-project Snakefiles find data transparently, create sibling directories and symlinks so expected relative paths resolve. Typical setups:
63+
- Workspace contains: mw-foo/ and mw-foo-data/ as siblings. Inside mw-foo, create a symlink named inp or data pointing to ../mw-foo-data (e.g. mw-foo/inp -> ../mw-foo-data).
64+
- Alternatively, create explicit symlinks for specific subfolders (e.g. mw-foo/src/snakemake/tables -> ../mw-foo-data/tables).
65+
- Because the top-level Snakefile uses relative globs like ../mw*/src/snakemake, having mw-foo and mw-foo-data as siblings ensures includes and table-loading work without modifications.
66+
- ID mapping tables (src/snakemake/tables/*ids.tsv) commonly contain absolute or repository-relative paths that point into the -data repo. Keeping these paths consistent (or using symlinks) ensures mwconf['ids'] resolves correctly.
67+
68+
Practical recommendations
69+
70+
- Keep raw data in mw-<name>-data and commit only small index files or path tables (tables/*ids.tsv) into the code repo. Use tables/*ids.tsv to map logical ids to file paths in the data repo.
71+
- Create a simple script or README describing the symlink setup required for each code repo; e.g.: ln -s ../mw-foo-data mw-foo/inp
72+
- Ensure the working directory when running the top-level Snakefile matches expected relative paths (often repository root or mw-lib/ depending on invocation). Document the recommended run location in project README.
73+
- Use out/ for all generated files so downstream report consumers always know where to look and cleaning is straightforward: rm -rf out/
74+
75+
Troubleshooting
76+
77+
- If includes fail, check the relative glob patterns in mw-lib/Snakefile and confirm sibling mw-* directories exist and are accessible.
78+
- If an id in mwconf['ids'] points to a non-existing path, check tables/*ids.tsv and the symlink structure to the -data repo.
79+
- If rules try to write into inp/ or the -data repo, rework the rule to write into out/ instead to preserve immutability of inputs.
80+
81+
If anything in this structure changes, update this MW.md so agents can continue to rely on these conventions.

0 commit comments

Comments
 (0)