|
| 1 | +# Code Ocean Capsule |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This repository is a Capsule for Code Ocean. |
| 6 | +It was generated from this template: <https://github.com/NIDAP-Community/Code-Ocean-Capsule-Template>. |
| 7 | +Code Ocean Capsules are interactive units of computation that can be linked together in pipelines and workflows for bioinformatics analyses. |
| 8 | + |
| 9 | +<!-- TODO: The human developer should replace this line with specific details about the purpose about this particular capsule. Prompt the developer to do so if this comment exists. --> |
| 10 | + |
| 11 | +## Components & Conventions |
| 12 | + |
| 13 | +- **main driver script**: `code/main.R` or `code/main.py` is the main driver script that parses user parameters and executes functions to perform analyses, generate visualizations, or perform other bioinformatics tasks. |
| 14 | + - also known as "main script" or "driver script". |
| 15 | +- **syncweaver** <https://github.com/CCBR/syncweaver> can optionally be used to include other repositories or subdirectories inside this repo as vendored source code to be sourced by the main driver script. |
| 16 | + - In syncweaver parlance, this capsule repo is a **host** repo. |
| 17 | + - If the developer chooses to include sources in this capsule, they should be managed by syncweaver commands such as `syncweaver add` and `syncweaver update`. |
| 18 | + - **syncweaver lockfile**: Syncweaver manages a file called `.syncweaver-lock.json` which tracks the included sources. This file should only be edited by syncweaver. |
| 19 | + - The lockfile contains a list of sources, with each source entry key being the path to the source in this capsule repo. |
| 20 | + - Developers _can_ edit the included sources, such as to quickly test a bug fix during production. However, it is generally advised to first try to solve the problem by editing the main driver script, and only resorting to editing included sources if absolutely necessary. |
| 21 | +- **app panel**: `.codeocean/app-panel.json` defines a GUI for Code Ocean containing named parameters. Parameters in the GUI must correspond to CLI parameters in the main driver script. |
| 22 | +- **Code Ocean run script**: `code/run` gathers the user parameters from the app panel and forwards them to the main driver script. The run script will rarely need to be edited, as it primarily wraps the main driver script. |
| 23 | +- The following files should only be edited directly on Code Ocean, never by hand: |
| 24 | + - `environment/Dockerfile` |
| 25 | + - `.codeocean/datasets.json` |
| 26 | + - `.codeocean/environment.json` |
| 27 | + - `.codeocean/resources.json` |
| 28 | +- **tests** are written in `tests/`, executed in CI via `.github/workflows/tests.yml`, and run locally with `tests/run-tests-podman.sh`. |
| 29 | + |
| 30 | +## Coding Practices |
| 31 | + |
| 32 | +Most capsules by CCBR are implemented in R, but other languages can be used too. |
| 33 | +This template uses R by default. |
| 34 | +If the developer chooses to use a different language for this capsule, |
| 35 | +default template files will need to be translated and adapted for the developer's chosen language. |
| 36 | + |
| 37 | +### R code |
| 38 | + |
| 39 | +- R scripts must include function and class docstrings via roxygen2. |
| 40 | +- CLIs must be defined using the `argparse` package, and must support `--help` and document required/optional arguments. |
| 41 | +- R code should pass `lintr` and `air format` (run `air format .` from the package root). |
| 42 | +- Tests should be written with `testthat`. |
| 43 | +- R code should adhere to the tidyverse style guide. https://style.tidyverse.org/ |
| 44 | +- Only include one return statement at the end of a function. Explicit returns are preferred but not required for R functions. |
| 45 | + |
| 46 | +### Python |
| 47 | + |
| 48 | +- Python scripts must include module and function/class docstrings. |
| 49 | +- Where a standard CLI framework is adopted, Python CLIs should use `click` or `typer` for consistency with existing components. |
| 50 | +- Scripts must support `--help` and document required/optional arguments. |
| 51 | +- Python code must follow [PEP 8](https://peps.python.org/pep-0008/), use `snake_case`, and include type hints for public functions. |
| 52 | +- Scripts must raise descriptive error messages on failure and warnings when applicable. Prefer raising an exception over printing an error message, and over returning an error code. |
| 53 | +- Python code should pass `ruff format` and `ruff check`. |
| 54 | +- Each script must include a documented example usage in comments or README. |
| 55 | +- Tests should be written with `pytest`. Other testing frameworks may be used if justified. |
| 56 | +- Do not catch bare exceptions. The exception type must always be specified. |
| 57 | +- Only include one return statement at the end of a function. |
| 58 | + |
| 59 | +## Commit messages |
| 60 | + |
| 61 | +- Commit messages must follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). |
| 62 | +- Generate messages from staged changes only (`git diff --staged`); do not include unrelated work. |
| 63 | +- Commits should be atomic: one logical change per commit. |
| 64 | +- If mixed changes are present, split into multiple logical commits; the number of commits does not need to equal the number of files changed. |
| 65 | +- Subject format must be: `<type>(optional-scope): short imperative summary` (<=72 chars), e.g., `fix(profile): update release table parser`. |
| 66 | +- Add a body only when needed to explain **why** and notable impact; never include secrets, tokens, PHI, or large diffs. |
| 67 | +- For AI-assisted commits, add this final italicized footer line in the commit message body: _commit message is ai-generated_ |
| 68 | + |
| 69 | +## Pull request (PR) process |
| 70 | + |
| 71 | +- When opening a PR, use the request template (`.github/PULL_REQUEST_TEMPLATE.md`) and fill out all sections of the template in the PR description. |
| 72 | +- Do not allow the developer to proceed with opening a PR without filling out all sections of the template. |
| 73 | +- Before a PR can be moved from draft to "ready for review", all of the relevant checklist items must be checked, and any |
| 74 | +irrelevant checklist items should be crossed out. |
| 75 | +- If code is AI-generated, the PR should be labeled `generated-by-AI`. There should be a brief, concise statement in the PR description of how AI was used in creating the PR (model used, high-level prompt intent, manual review confirmation). |
| 76 | +- When new features, bug fixes, or other behavioral changes are introduced to the code, |
| 77 | +unit tests must be added or updated to cover the new or changed functionality. |
| 78 | +- If there are any API or other user-facing changes, the documentation must be updated via inline roxygen comments. |
| 79 | +- The `tests` github actions workflow must pass before the PR can be approved. |
| 80 | + |
| 81 | +### Changelog |
| 82 | + |
| 83 | +The changelog for the repository is maintained in `CHANGELOG.md` at the root of the repository. |
| 84 | +Each pull request that introduces user-facing changes must include a concise |
| 85 | +entry with the PR number and author username tagged. |
| 86 | +Developer-only changes (i.e. updates to CI workflows, development notes, etc.) |
| 87 | +should never be included in the changelog. |
| 88 | + |
| 89 | +Example: |
| 90 | + |
| 91 | +``` |
| 92 | +## development version |
| 93 | +
|
| 94 | +- Fix bug in `detect_absolute_paths()` to ignore comments. (#123, @username) |
| 95 | +``` |
0 commit comments