Python API¶
tinymapper is a command line first: tinymapper and
tinymapper-report. These modules are what
scripts use: a run's specification and its runner, and the report of a run,
written or read back.
from tinymapper.models import JobSpec
from tinymapper.runner import TinyMapperRunner
from tinymapper.report import read_report
spec = JobSpec(
mode="ChIP", sample="reads/JS001", genome="genomes/R64-1-1/R64-1-1", output="results"
)
TinyMapperRunner(spec).run() # 0 when the run went to its end
sections, tables = read_report("results/JS001.report.txt")
sections["reads"]["kept_pct"] # '50.74': values are text
tinymapper.models¶
Typed job specification for tinyMapper.
All parameters map 1-to-1 to tinyMapper.sh CLI flags.
TinyMapperMode ¶
Bases: str, Enum
Supported mapping modes (matches tinyMapper.sh case-sensitive values).
Source code in src/tinymapper/models.py
JobSpec ¶
Bases: BaseModel
Complete specification for a single tinyMapper run.
All field names and defaults mirror tinyMapper.sh variables.
Source code in src/tinymapper/models.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
remove_duplicates_flag
property
¶
samtools markdup -r flag (empty string when keeping dups).
exclude_duplicates_flag
property
¶
deepTools option skipping reads flagged as duplicates (empty when keeping dups).
Replaces --ignoreDuplicates, which deepTools 4.0 removed. Every BAM
reaching a track step has been through samtools markdup first:
paired-end BAMs have their duplicates removed (so this is a no-op),
single-end and RNA BAMs have them flagged (0x400) and this skips them.
hic_base_rez
property
¶
Lowest resolution bin for HiC (first value in comma-separated list).
normalise_mode
classmethod
¶
Accept case-insensitive mode names (chip → ChIP, hic → HiC, etc.).
to_cli_args ¶
Return the equivalent tinyMapper.sh long-form argument list.
Source code in src/tinymapper/models.py
tinymapper.runner¶
TinyMapperRunner — validates inputs and dispatches to mode modules.
TinyMapperRunner ¶
Orchestrates validation, directory setup and mode dispatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
JobSpec
|
The run. |
required |
command
|
str
|
The command line that started it, which the log's header writes; by
default, the one |
None
|
Source code in src/tinymapper/runner.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
run ¶
Execute the full pipeline. Returns 0 on success, 1 on failure.
Source code in src/tinymapper/runner.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
header_parameters ¶
The run's parameters, as its log's header writes them: the run's hash, then each option of the command line, by its long name, as given or by default.
Source code in src/tinymapper/runner.py
tinymapper.report¶
The report of a run: its numbers, its MultiQC row and its page.
The report of one run of tinymapper, for one sample (CONVENTIONS.md § 12), in the run's output directory, named after the sample:
<sample>.report.txt: every number of the report, for scripts, which :func:read_reportreads back;<sample>.report_mqc.yaml: the run's row of MultiQC's General Statistics table;<sample>.report.html: a page to read the run with.
:func:collect gathers it from what the run left in its output directory, and
never runs a program: its log's header (the run's parameters), the statistics
it keeps in stats/<sample>/ (samtools flagstat, stats and markdup, STAR's
log, tinymapper's counts), its peaks and its spike-in counts. A Hi-C run takes
its numbers from hicstuff's report, which tinymapper writes under the sample's
name in matrices/<sample>/, and links to it. chromokit's report kit
(tinymapper._report) writes the files. A run writes its report at its end,
and tinymapper-report writes it again from the run's directory.
The report's format is :data:FORMAT_VERSION: a key, a column, a unit or a
MultiQC column that changes or goes raises it; one that comes does not.
docs/formats.md documents every key.
Run
dataclass
¶
A run, as its log describes it.
Attributes:
| Name | Type | Description |
|---|---|---|
outdir |
Path
|
The run's output directory. |
log |
Path
|
Its log, |
header |
dict
|
The log's header: the version, the date, the command line and each parameter, as text. |
spec |
JobSpec
|
The run's parameters, its output directory being outdir. |
duration_s |
int or None
|
How long it took, from its log's last line. |
Source code in src/tinymapper/report.py
Collected
dataclass
¶
The report of a run, and what its page takes besides.
Attributes:
| Name | Type | Description |
|---|---|---|
report |
Report
|
The report: its sections. |
figures |
dict
|
The page's plots, by the id of their place in it. |
inputs |
dict
|
What the page's header names: the reads, the genome, the input and the spike-in genome. |
links |
dict
|
The run's outputs that the page links to: links["files"], and for a Hi-C run links["hicstuff"], hicstuff's page. |
Source code in src/tinymapper/report.py
tool ¶
tinymapper, as its reports name it: its version, the report's format, its MultiQC columns and its page's template.
Source code in src/tinymapper/report.py
read_report ¶
Read a report.txt back: its sections, by name, each its keys and their values as text, and its tables, as pandas.DataFrame of text; None where a value is NA. Needs pandas.
Source code in src/tinymapper/report.py
report_paths ¶
The files of the report of sample in outdir: its report.txt, its page and its report_mqc.yaml, in that order.
Source code in src/tinymapper/report.py
spec_from_header ¶
The run's parameters, from its log's header, its output directory being outdir (the header's may be relative to where the run started).
Source code in src/tinymapper/report.py
read_run ¶
The run of log, whose outputs are in outdir.
Raises:
| Type | Description |
|---|---|
ValueError
|
If log is not a tinymapper log, or the log of a dry run. |
Source code in src/tinymapper/report.py
find_runs ¶
The runs whose report is written: the run of log; or else the newest run of each sample (of sample alone, if given) that went to its end, by the date in its log's name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outdir
|
Path
|
The runs' output directory, whose |
required |
sample
|
str
|
A sample's name, or the path prefix given to |
None
|
log
|
Path
|
A run's log. |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If outdir holds no log of a run that went to its end (of sample). |
ValueError
|
If log is not the newest run of its sample in outdir that went to
its end: |
Source code in src/tinymapper/report.py
read_flagstat ¶
samtools flagstat's counts, by their description ("primary",
"primary mapped", "paired in sequencing"…): the reads that passed QC and
those that failed it, together. Empty if path does not exist.
Source code in src/tinymapper/report.py
read_samtools_stats ¶
samtools stats' summary numbers (its SN lines), by their name
without the colon ("reads mapped"…), and its insert sizes (IS lines):
(size, pairs). Empty if path does not exist.
Source code in src/tinymapper/report.py
read_markdup ¶
samtools markdup -f's counts, by their name ("EXAMINED",
"DUPLICATE PRIMARY TOTAL"…). Empty if path does not exist.
Source code in src/tinymapper/report.py
read_star_log ¶
STAR's Log.final.out, its numbers by their label ("Number of input
reads"…). Empty if path does not exist.
Source code in src/tinymapper/report.py
read_counts ¶
tinymapper's counts (<sample>.counts.txt): a name and a number per
line. Empty if path does not exist.
Source code in src/tinymapper/report.py
read_sections ¶
The sections of a report.txt (chromokit's format: hicstuff's report), each its keys and their values as text, None for NA; its tables are left out. Empty if path does not exist. Needs no pandas, as read_txt does.
Source code in src/tinymapper/report.py
run_section ¶
The run's parameters, as its log's header gives them, and how long it took.
Source code in src/tinymapper/report.py
reads_section ¶
The reads of the sample (or of the input) and where they went: mapped,
kept and duplicated, from the statistics in stats/<name>/.
Source code in src/tinymapper/report.py
hicstuff_report_paths ¶
hicstuff's report of a Hi-C run, which tinymapper writes under the
sample's name in matrices/<sample>/.
hic_sections ¶
A Hi-C run's reads (as reads_section counts them: a pair is two reads) and its hicstuff section, from hicstuff's report: its read pairs, the share mapped, the duplicates, the pairs kept and the trans ratio.
Source code in src/tinymapper/report.py
calibration_section ¶
The spike-in calibration of a ChIP-seq run: the reads of the sample and of the input on each genome, filtered, the occupancy ratio and the scaling factor of the scaled track, from the run's counts file.
Source code in src/tinymapper/report.py
peaks_section ¶
The peaks MACS3 called, and the share of the kept reads in them (FRiP).
Source code in src/tinymapper/report.py
fragments_section ¶
The sizes of the kept fragments (paired-end runs), from samtools
stats: their median, mean and spread, and for MNase-seq the share in
the run's size window (--MNaseSizes). Also the sizes, for the plot.
Source code in src/tinymapper/report.py
strands_section ¶
The kept reads of an RNA-seq run on each strand, as the stranded tracks split them (deepTools' --filterRNAstrand, for dUTP libraries).
Source code in src/tinymapper/report.py
files_section ¶
The run's main outputs, relative to its output directory: its log, its BAM, its peaks, its contact maps and hicstuff's report, each None if the run has none.
Source code in src/tinymapper/report.py
collect ¶
Gather the report of a run, from what it left in its directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
Run
|
The run (see find_runs). |
required |
duration_s
|
int
|
How long the run took, in seconds, for the run's own report, written before its log's last line; by default, from that line. |
None
|
report_dir
|
Path
|
Where the page will be, which its links start from; by default, the run's directory. |
None
|
Returns:
| Type | Description |
|---|---|
Collected
|
The report (see the module's docstring), the page's plots, the inputs its header names and the outputs it links to. |
Source code in src/tinymapper/report.py
figures ¶
The plots of the page, as Plotly figures (data and layout), by the id of their place: where the reads went (plot-reads), and the fragments' sizes (plot-fragments), each left out when the run gives nothing to draw. A colour left out follows the page's palette.
Source code in src/tinymapper/report.py
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | |
write_report ¶
write_report(outdir: Path, *, log: Path | None = None, sample: str | None = None, report_dir: Path | None = None, force: bool = False, duration_s: int | None = None) -> list[str]
Write the report of a run, from its output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outdir
|
Path
|
The run's output directory. It is only read. |
required |
log
|
Path
|
The run's log; by default, the newest log of sample's runs that went
to their end, in |
None
|
sample
|
str
|
The sample, when log is not given; by default, the only sample of outdir. |
None
|
report_dir
|
Path
|
The report's directory, made if missing; by default, outdir. |
None
|
force
|
bool
|
Replace the report of the same sample in report_dir; without it, an existing one is refused before anything is read. |
False
|
duration_s
|
int
|
How long the run took, in seconds (see collect). |
None
|
Returns:
| Type | Description |
|---|---|
list of str
|
The report's files: its report.txt, its page and its report_mqc.yaml. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If outdir holds no log of a run (of sample) that went to its end. |
FileExistsError
|
If a file of the report exists and force is not set. |
ValueError
|
If outdir holds the runs of several samples and none is named, or log is not a tinymapper log. |
Source code in src/tinymapper/report.py
write_reports ¶
write_reports(outdir: Path, *, sample: str | None = None, log: Path | None = None, report_dir: Path | None = None, force: bool = False) -> list[str]
Write the report of each run that find_runs finds in outdir: the run of log, or the newest of each sample (of sample alone, if given). Without force, an existing report refuses them all, before any is written.
Returns:
| Type | Description |
|---|---|
list of str
|
The files of the reports, three per run. |