Skip to content

Commit 4e7ca7a

Browse files
committed
refactor: add repository QC, method registry, and shared utilities
1 parent 7c99a00 commit 4e7ca7a

10 files changed

Lines changed: 795 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Repository quality control
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
structural-checks:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Check out repository
16+
uses: actions/checkout@v7
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.12"
22+
23+
- name: Set up Ruby and website dependencies
24+
uses: ruby/setup-ruby@v1
25+
with:
26+
ruby-version: "3.3"
27+
bundler-cache: true
28+
working-directory: website
29+
30+
- name: Set up R
31+
uses: r-lib/actions/setup-r@v2
32+
with:
33+
r-version: "release"
34+
35+
- name: Check Python, paths, files, links, and registry
36+
run: |
37+
python scripts/check_repository.py
38+
python scripts/build_method_registry.py --check
39+
40+
- name: Check YAML and Quarto front matter
41+
run: ruby scripts/check_quarto_yaml.rb
42+
43+
- name: Check R syntax
44+
run: Rscript scripts/check_r_syntax.R
45+
46+
- name: Build the website
47+
working-directory: website
48+
run: |
49+
bundle exec ruby scripts/build_notebook_search.rb
50+
bundle exec ruby scripts/build_downloads.rb
51+
bundle exec jekyll build --baseurl "/Useful_code"
52+
53+
- name: Check generated website links
54+
run: python scripts/check_repository.py --site website/_site

CODE_MAP/method_registry.tsv

Lines changed: 38 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ reuse the useful parts.
3434
Useful code keeps readable analytical workflows together with the parameters,
3535
diagnostics, and implementation details that make them useful when reopened.
3636
The website groups the notebooks by analysis area and links back to the files.
37+
The generated registry in `CODE_MAP/method_registry.tsv` makes the active
38+
notebook collection searchable by script.
3739

3840
## Browse the methods
3941

@@ -60,12 +62,31 @@ Before reusing a notebook:
6062
4. Adapt paths and other dataset-specific assumptions.
6163
5. Validate the outputs on your own data and study design.
6264

65+
## Repository checks and registry
66+
67+
GitHub Actions runs lightweight checks on pushes and pull requests: YAML and
68+
Quarto front matter, Markdown links, Python and R syntax, reusable-template
69+
paths, large files, registry consistency, and the website build. It does not
70+
run the bioinformatics analyses.
71+
72+
Regenerate the notebook registry after changing the active catalog with:
73+
74+
```bash
75+
python3 scripts/build_method_registry.py
76+
```
77+
78+
Use `--check` in CI or before committing to confirm that the tracked TSV is
79+
current.
80+
6381
## Repository structure
6482

83+
functions/ small reusable R and Python implementation primitives
6584
templates/ reusable notebooks
6685
examples/ project-specific analyses and context
6786
cheatsheets/ compact references
6887
miscellaneous/ reporting prompts and reusable documentation material
88+
scripts/ repository maintenance and registry checks
89+
CODE_MAP/ searchable repository metadata
6990
website/ Jekyll catalog website
7091
docs/ architecture and refactor documentation
7192
archive/ superseded historical material

functions/R/zscore.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' Standardize a numeric vector using base R's scale behavior.
2+
#'
3+
#' @param x A numeric vector.
4+
#' @return A numeric vector with the scaled values.
5+
zscore <- function(x) {
6+
if (!is.numeric(x)) {
7+
stop("x must be numeric.", call. = FALSE)
8+
}
9+
10+
as.numeric(scale(x))
11+
}

functions/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Shared functions
2+
3+
`functions/` contains small, standalone implementation primitives that are
4+
useful across more than one notebook. The analytical notebooks remain
5+
self-contained where sourcing a repository-relative file would make copying
6+
them harder.
7+
8+
R:
9+
10+
```r
11+
source("functions/R/zscore.R")
12+
zscore(values)
13+
```
14+
15+
Python:
16+
17+
```python
18+
from functions.python.write_tsv import write_tsv
19+
20+
write_tsv(table, "output/table.tsv")
21+
```
22+
23+
These helpers do not replace the notebook workflows or package documentation.

functions/python/write_tsv.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Small helper for writing dataframe-like objects as TSV files."""
2+
3+
from pathlib import Path
4+
from typing import Any, Union
5+
6+
7+
def write_tsv(table: Any, path: Union[str, Path]) -> None:
8+
"""Write a dataframe-like object as a headered TSV.
9+
10+
The object must provide a pandas-compatible ``to_csv`` method. Parent
11+
directories are created, but table contents and output names stay with the
12+
caller.
13+
"""
14+
15+
if not hasattr(table, "to_csv"):
16+
raise TypeError("table must provide a to_csv method")
17+
18+
output_path = Path(path)
19+
if output_path.exists() and output_path.is_dir():
20+
raise IsADirectoryError(output_path)
21+
22+
output_path.parent.mkdir(parents=True, exist_ok=True)
23+
table.to_csv(output_path, sep="\t", index=False)

0 commit comments

Comments
 (0)