Skill Tracer
Skills › Scientific Agent Skills › polars-bio › configuration.md

configuration.md

88 lines · skills/polars-bio/references/configuration.md at 5f2bc03

Open on GitHub
1# Configuration and metadata (0.36.0)
2
3The [release context implementation](https://github.com/biodatageeks/polars-bio/blob/0.36.0/polars_bio/context.py)
4is the authority for defaults; some function docstrings incorrectly call
5coordinate checking strict by default.
6
7| Option | Actual default | Effect |
8|---|---|---|
9| `datafusion.execution.target_partitions` | `"1"` | DataFusion execution partition target |
10| `datafusion.bio.coordinate_system_zero_based` | `"false"` | Readers default to 1-based closed output |
11| `datafusion.bio.coordinate_system_check` | `"false"` | Missing metadata warns and falls back to session convention |
12| `bio.interval_join_algorithm` | `"coitrees"` | Default interval join backend |
14```python
15import polars_bio as pb
17pb.set_option("datafusion.bio.coordinate_system_zero_based", True)
18pb.set_option("datafusion.bio.coordinate_system_check", True)
19pb.set_option("datafusion.execution.target_partitions", 4)
20assert pb.get_option("datafusion.execution.target_partitions") == "4"
21```
23`set_option` accepts boolean/numeric values and converts them to backend strings;
24`get_option` returns a string (or None). Options affect a shared process context:
25set them deliberately before constructing scans/registered tables, record them,
26and restore previous values when a reusable workflow finishes. Four partitions
27is an example, not a performance recommendation for every dataset. Each
28partition and object-store fetch can increase memory consumption.

Configuration and metadata (0.36.0)

The release context implementation is the authority for defaults; some function docstrings incorrectly call coordinate checking strict by default.

OptionActual defaultEffect
datafusion.execution.target_partitions"1"DataFusion execution partition target
datafusion.bio.coordinate_system_zero_based"false"Readers default to 1-based closed output
datafusion.bio.coordinate_system_check"false"Missing metadata warns and falls back to session convention
bio.interval_join_algorithm"coitrees"Default interval join backend
import polars_bio as pb

pb.set_option("datafusion.bio.coordinate_system_zero_based", True)
pb.set_option("datafusion.bio.coordinate_system_check", True)
pb.set_option("datafusion.execution.target_partitions", 4)
assert pb.get_option("datafusion.execution.target_partitions") == "4"

set_option accepts boolean/numeric values and converts them to backend strings; get_option returns a string (or None). Options affect a shared process context: set them deliberately before constructing scans/registered tables, record them, and restore previous values when a reusable workflow finishes. Four partitions is an example, not a performance recommendation for every dataset. Each partition and object-store fetch can increase memory consumption.

Raw lines 1 to 29
30## Metadata versus coordinate conversion
32I/O functions that expose `use_zero_based` convert their output coordinates and
33set metadata. Explicit reader arguments override the global default. Native
34BED is 0-based half-open; VCF/GFF/GTF and SAM text are 1-based. BAM's internal
35stored position is 0-based. Read all files into one chosen convention.
37```python
38import polars as pl
39import polars_bio as pb
41closed = pl.DataFrame({"chrom": ["chr1"], "start": [1], "end": [10]})
42closed.config_meta.set(coordinate_system_zero_based=False)
43half_open = closed.with_columns((pl.col("start") - 1).alias("start"))
44half_open.config_meta.set(coordinate_system_zero_based=True)
45assert half_open.select("start", "end").row(0) == (0, 10)
46```
48`config_meta.set()` labels the existing values, never shifts them. Subtracting
49one from an unsigned zero risks underflow: validate the source convention before
50conversion, and use signed arithmetic when deriving lengths/differences.
51Changing a global option does not convert or relabel existing frames.
53Two-input interval operations reject disagreeing coordinate metadata. Strict
54checking rejects absent metadata; lenient checking may hide an accidental
55coordinate mismatch. Strict checking still does not validate genome assembly,
56strand meaning, reference contig lengths or every biological interval rule.

Metadata versus coordinate conversion

I/O functions that expose use_zero_based convert their output coordinates and set metadata. Explicit reader arguments override the global default. Native BED is 0-based half-open; VCF/GFF/GTF and SAM text are 1-based. BAM's internal stored position is 0-based. Read all files into one chosen convention.

import polars as pl
import polars_bio as pb

closed = pl.DataFrame({"chrom": ["chr1"], "start": [1], "end": [10]})
closed.config_meta.set(coordinate_system_zero_based=False)
half_open = closed.with_columns((pl.col("start") - 1).alias("start"))
half_open.config_meta.set(coordinate_system_zero_based=True)
assert half_open.select("start", "end").row(0) == (0, 10)

config_meta.set() labels the existing values, never shifts them. Subtracting one from an unsigned zero risks underflow: validate the source convention before conversion, and use signed arithmetic when deriving lengths/differences. Changing a global option does not convert or relabel existing frames.

Two-input interval operations reject disagreeing coordinate metadata. Strict checking rejects absent metadata; lenient checking may hide an accidental coordinate mismatch. Strict checking still does not validate genome assembly, strand meaning, reference contig lengths or every biological interval rule.

Raw lines 30 to 57
58## Inspect and retain metadata
60```python
61# Template: df is a frame returned by a genomic reader.
62metadata = pb.get_metadata(df)
63pb.print_metadata_summary(df)
64pb.print_metadata_json(df)
65assert metadata["coordinate_system_zero_based"] is True
66```
68`pb.set_source_metadata(df, format="bed", path="regions.bed")` records provenance;
69it is not a coordinate converter or a substitute for explicit coordinate
70metadata. Readers also retain headers needed for writing VCF/BAM/CRAM. Confirm
71metadata after select/rename/concat, SQL, conversion to pandas, or saving and
72reloading an intermediate format. Do not assume arbitrary SQL expressions or
73Parquet round trips preserve this Python metadata.

Inspect and retain metadata

# Template: df is a frame returned by a genomic reader.
metadata = pb.get_metadata(df)
pb.print_metadata_summary(df)
pb.print_metadata_json(df)
assert metadata["coordinate_system_zero_based"] is True

pb.set_source_metadata(df, format="bed", path="regions.bed") records provenance; it is not a coordinate converter or a substitute for explicit coordinate metadata. Readers also retain headers needed for writing VCF/BAM/CRAM. Confirm metadata after select/rename/concat, SQL, conversion to pandas, or saving and reloading an intermediate format. Do not assume arbitrary SQL expressions or Parquet round trips preserve this Python metadata.

Raw lines 58 to 74
75## Streaming and logging
77`scan_*` builds lazy readers, and supported sources deliver batches from
78DataFusion to Polars. `lf.collect(engine="streaming")` selects Polars' streaming
79engine for the plan but still returns a materialized DataFrame. Joins may build
80an in-memory index; sorting, merge/cluster and dense pileup can need substantial
81working memory. Use sinks when output size itself is large. Indexes and reader
82pushdown support vary by format; do not equate lazy input with indexed access.
84Call `pb.set_loglevel("info")` immediately after import if needed. Accepted levels
85are `debug`, `info`, `warn` and `warning`. The upstream logging implementation
86restricts later verbosity changes; start a new Python process if changing the
87level does not take effect. For ordinary analysis leave logging at its default.
88See [official auxiliary API](https://biodatageeks.org/polars-bio/api/auxiliary/).

Streaming and logging

scan_* builds lazy readers, and supported sources deliver batches from DataFusion to Polars. lf.collect(engine="streaming") selects Polars' streaming engine for the plan but still returns a materialized DataFrame. Joins may build an in-memory index; sorting, merge/cluster and dense pileup can need substantial working memory. Use sinks when output size itself is large. Indexes and reader pushdown support vary by format; do not equate lazy input with indexed access.

Call pb.set_loglevel("info") immediately after import if needed. Accepted levels are debug, info, warn and warning. The upstream logging implementation restricts later verbosity changes; start a new Python process if changing the level does not take effect. For ordinary analysis leave logging at its default. See official auxiliary API.

Raw lines 75 to 88