fasta_lake.lake_builder#
fasta_lake.lake_builder
#
Lake builder: merge multiple source FASTAs into one with provenance (v5.2).
Reads N input FASTAs (each tagged with a source label such as "SP", "TR",
"UH"), parses headers into SourceRecord objects, groups sequences by
SHA-256 hash (normalized sequence; see hashing.py), and for each group
emits a single merged representative in the output FASTA plus one JSONL line
in the provenance sidecar.
Priority-win mode (back-compat) picks one source and discards the others.
Merge mode (default in v5.2) combines annotations per the rules in
fasta_lake.lake_merge.
Header parser is deliberately conservative: it knows UniProt sp|/tr|, UHGP MGYP, GENCODE ENSP, and falls back to "UNKNOWN" for other formats.
parse_header
#
parse_header(header: str, tag_hint: str | None = None) -> SourceRecord
Parse a FASTA header line (without leading >).
tag_hint forces the source tag (e.g. "SP" or "UH"); otherwise the tag
is inferred from the header format.
Source code in fasta_lake/lake_builder.py
iter_fasta
#
iter_fasta(path: Path, tag: str) -> list[tuple[SourceRecord, str]]
Yield (SourceRecord, sequence) pairs from a FASTA, tagging every record with the given source label.
Source code in fasta_lake/lake_builder.py
build_lake
#
build_lake(sources: dict[str, Path], out_fasta: Path, out_provenance: Path, dedup_mode: str = 'merge', priority: tuple[str, ...] = DEFAULT_PRIORITY, embed_sources: bool = False, compress: bool = False) -> dict
Build a merged lake FASTA + provenance sidecar from multiple sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
dict[str, Path]
|
|
required |
out_fasta
|
Path
|
Output merged FASTA. |
required |
out_provenance
|
Path
|
Output provenance JSONL (optionally .gz). |
required |
dedup_mode
|
str
|
"merge" (default, v5.2) or "priority-win" (legacy). |
'merge'
|
priority
|
tuple[str, ...]
|
Tag priority tuple. Default: SP, TR, UH, GM, GENCODE, GNOMAD, NCBI. |
DEFAULT_PRIORITY
|
embed_sources
|
bool
|
If True, append |
False
|
compress
|
bool
|
If True, write sidecar as JSONL.gz. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Statistics of the merge: input, unique and per-source counts and timings. |
Source code in fasta_lake/lake_builder.py
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 | |