index_ops
pykmhelpers.pipeline.index_ops
Build and merge k-mer indexes from index definitions or span registries.
IndexOps is the entry point; the other modules are its components.
IndexOps
Orchestrates k-mer index build and merge operations against a kmindex registry.
Loads an index definition or a span registry (see sources), builds
the missing sub-indexes, merges partial indexes into their target and
deletes the merged parts. In plan/dry-run modes, commands are only
generated and can be exported as a shell script via write_script().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
IndexOpsConfig
|
Runtime configuration governing paths, build parameters,
filtering, and execution behaviour. See |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
config |
IndexOpsConfig
|
The resolved configuration (paths are converted to absolute paths on construction). |
work_dir |
str
|
Absolute path to the working directory. |
asset_dir |
str
|
|
log_dir |
str
|
|
kmindex_registry_dir |
str
|
Path to the kmindex registry directory. |
kmindex_data_dir |
str
|
Path to the folder that holds index data. |
timestamp |
str
|
|
Source code in pykmhelpers/pipeline/index_ops/ops.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 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 | |
write_script()
Write the commands collected by the last run() to asset_dir.
One script per group of parts (<db>_g<span>_<session>.sh: builds,
merge, then cleanup), plus kmhelpers_apply.sh running them in
order. With config.session_assets, they go to
asset_dir/<session>/ and asset_dir/kmhelpers_apply.sh runs
that session. Existing files are backed up with a .bak suffix.
Source code in pykmhelpers/pipeline/index_ops/ops.py
run(path, mode, fail_on_error=False)
Apply an index definition or span registry file to the kmindex registry.
Builds every selected sub-index missing from the registry, then performs the merges declared by a span registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to a YAML or JSON file containing either an
|
required |
mode
|
ApplyMode
|
Execution mode - controls whether to dry-run, plan, or apply. |
required |
fail_on_error
|
bool
|
Abort this run on the first build or merge error
instead of continuing and returning |
False
|
Returns:
| Type | Description |
|---|---|
ApplyResult
|
An |
ApplyResult
|
dict. Status is |
ApplyResult
|
error, |
ApplyResult
|
|
Source code in pykmhelpers/pipeline/index_ops/ops.py
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 | |
BuildParams
dataclass
Resolved kmindex build parameters for one index.
partitions and minim_size are index invariants: indexes are only
mergeable when they share them, so they come from the layout once
resolved. chunk_size is set when the open-files ceiling can't fit
every sample in one kmtricks build; the build is then split into chunks
of at most that many samples, which are merged.
Source code in pykmhelpers/pipeline/index_ops/sizing.py
ApplyInputType
Bases: str, Enum
Type of the input file passed to an apply operation.
Values
UNKNOWN: File type could not be determined. SPAN_REGISTRY: Input is a span registry file describing how partial indexes should be merged. INDEX_DEFINITION: Input is an index definition file describing one or more sub-indexes to build. NONE: No input file has been inspected yet.
Source code in pykmhelpers/pipeline/index_ops/types.py
ApplyMode
Bases: int, Enum
Source code in pykmhelpers/pipeline/index_ops/types.py
executes
property
True when commands are actually run (not just planned).
checks_files
property
True when sample files must exist on this machine.
ApplyResult
dataclass
Result of an apply operation.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
ApplyStatus
|
Overall outcome of the operation. |
input_type |
ApplyInputType
|
Detected type of the input file that was processed. |
details |
dict
|
Per-index outcome strings keyed by index name, plus an
|
Source code in pykmhelpers/pipeline/index_ops/types.py
ApplyStatus
IndexOpsConfig
dataclass
Configuration for an IndexOps instance.
Attributes:
| Name | Type | Description |
|---|---|---|
workdir |
str
|
Root working directory. Created automatically if absent. |
index_data_folder |
str
|
Directory that holds the raw index data files. |
registry_dir |
str
|
Path to the kmindex registry used to track sub-indexes. |
minimizer_length |
int
|
K-mer minimizer size passed to the builder.
Defaults to |
sample_rootpath |
Optional[str]
|
Optional prefix prepended to every sample file path in an index definition. Useful when paths are stored relative to a root that differs from the current working directory. |
kmindex_threads |
Optional[int]
|
Number of threads passed to kmindex build commands.
|
kmindex_skip_compression |
bool
|
When |
kmindex_build_from |
Optional[str]
|
Override the parent index for all build operations, replacing the value declared in each index definition. |
filter_spans |
Optional[list[int]]
|
If set, only process index definitions whose span value is in this list. |
filter_names |
Optional[list[str]]
|
If set, only process index definitions whose name is in this list. |
on_existing |
str
|
Behaviour when a sub-index folder already exists on disk but is not registered.
Passed directly to the builder (e.g. |
limits |
Optional[str]
|
JSON line of resource limits ( |
safety_margin |
float
|
Fraction of a detected system limit to use for any
key missing from |
max_chunks |
int
|
Cap on the number of chunks a single index is split into.
A bigger chunk needs more open files in the merge stage, so the
cap is paid for with threads. |
session_assets |
bool
|
When |
Source code in pykmhelpers/pipeline/index_ops/types.py
clamp_partitions(count)
Apply the kmtricks partition floor; 0 (auto) is left untouched.