Tracks I/O¶
Load tracks from BED, narrowPeak, WIG, and BigWig files. Export tracks as BED or WIG. Gzip-compressed files are auto-detected.
from seqchain.io.tracks import load_bed, load_bigwig, load_track, write_bed
# Auto-dispatch by extension
track = load_track("peaks.narrowPeak")
# Explicit loaders
bed = load_bed("intervals.bed")
signal = load_bigwig("coverage.bw")
# Export
write_bed(bed, "output.bed")
Auto-dispatch¶
load_track
¶
load_track(path: str | Path, name: str | None = None) -> Union[IntervalTrack, SignalTrack, TableTrack]
Auto-detect file format and load as the appropriate Track type.
Dispatches based on file extension:
.json→load_json().bed,.bed.gz→load_bed().narrowPeak,.narrowPeak.gz→load_narrowpeak().wig,.wig.gz→load_wig().bw,.bigwig,.bigWig→load_bigwig()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a track file. |
required |
name
|
str | None
|
Track name. Defaults to format-specific default. |
None
|
Returns:
| Type | Description |
|---|---|
Union[IntervalTrack, SignalTrack, TableTrack]
|
An |
Union[IntervalTrack, SignalTrack, TableTrack]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file extension is not recognized. |
Examples:
Source code in src/seqchain/io/tracks.py
Loaders¶
BED¶
load_bed
¶
Parse a BED file into an IntervalTrack.
Reads BED3 through BED12. Columns beyond the first three are
optional and populate Region fields:
- Column 4 →
name - Column 5 →
score - Column 6 →
strand
Columns 7–12 (thickStart, thickEnd, itemRgb, blockCount,
blockSizes, blockStarts) are stored in tags if present.
Lines starting with #, track, or browser are skipped.
Supports gzip-compressed files (.gz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a BED file. |
required |
name
|
str | None
|
Track name. Defaults to the filename stem. |
None
|
Returns:
| Type | Description |
|---|---|
IntervalTrack
|
An |
Examples:
Source code in src/seqchain/io/tracks.py
narrowPeak¶
load_narrowpeak
¶
Parse a narrowPeak file into an IntervalTrack.
NarrowPeak is BED6+4 (10 columns):
- chrom, 2. start, 3. end, 4. name, 5. score, 6. strand,
- signalValue, 8. pValue, 9. qValue, 10. peak (summit offset).
Extra narrowPeak columns are stored in tags:
signal_value, p_value, q_value, summit_offset.
Lines starting with #, track, or browser are skipped.
Supports gzip-compressed files (.gz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a narrowPeak file. |
required |
name
|
str | None
|
Track name. Defaults to the filename stem. |
None
|
Returns:
| Type | Description |
|---|---|
IntervalTrack
|
An |
IntervalTrack
|
regions. |
Examples:
Source code in src/seqchain/io/tracks.py
WIG¶
load_wig
¶
Parse a WIG file into an IntervalTrack.
Supports both variableStep and fixedStep WIG formats.
Each data position becomes a Region with
start and end = start + 1 (single-base) and score
set to the data value. WIG coordinates are 1-based in the file
and converted to 0-based half-open on load.
Lines starting with #, track, or browser are skipped.
Supports gzip-compressed files (.gz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a WIG file. |
required |
name
|
str | None
|
Track name. Defaults to the filename stem. |
None
|
Returns:
| Type | Description |
|---|---|
IntervalTrack
|
An |
Examples:
Source code in src/seqchain/io/tracks.py
BigWig¶
load_bigwig
¶
Open a BigWig file as a SignalTrack.
Uses a deferred import of pyBigWig so the rest of the library
can be used without it installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a BigWig file ( |
required |
name
|
str | None
|
Track name. Defaults to the filename stem. |
None
|
Returns:
| Type | Description |
|---|---|
SignalTrack
|
A |
Examples:
Source code in src/seqchain/io/tracks.py
Writers¶
write_wig
¶
Write an IntervalTrack to variableStep WIG format.
Each Region's score is written as an integer count at its start position. WIG coordinates are 1-based. Regions are grouped by chromosome and sorted by position. All regions are written, including those with a score of zero — this is required by TRANSIT for essentiality analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
IntervalTrack
|
IntervalTrack to write. |
required |
path
|
str | Path
|
Output file path. |
required |
track_name
|
str | None
|
Optional track name for the header. Defaults to the track's own name. |
None
|
Examples:
Source code in src/seqchain/io/tracks.py
write_bed
¶
Write an IntervalTrack to BED6 format.
Columns: chrom, start (0-based), end, name, score (integer), strand. Regions are sorted by (chrom, start).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track
|
IntervalTrack
|
IntervalTrack to write. |
required |
path
|
str | Path
|
Output file path. |
required |
Examples: