Skip to main content

A lightweight Python package for creating UCSC Track Hubs with ease.

Project description

bigtrack

A lightweight Python package for creating UCSC Track Hubs with ease.

Note: This package was primarily developed to generate track hubs for my previous publications. It has not been tested for production use.

Installation

Build the latest version from source:

git clone https://github.com/zhang-shilong/bigtrack
cd bigtrack/
pip install .

Usage

Quick start

import bigtrack

# generate a hub
hub = bigtrack.Hub(
    hub="ExampleHub",
    shortLabel="ExampleHub",
    longLabel="ExampleHub",
    email="example@email.com",
)

# make a genome
genome = bigtrack.Genome(
    genome="ExampleGenome",
    organism="Example Organism",
    scientificName="Example Organism",
    twoBitPath="/path/to/two/bit/file",
    chromSizes="/path/to/sizes/file",
    defaultPos="chr1:0-100000",
    orderKey=1,
    description="This is a example",
    htmlPath="/path/to/html/description",
)
hub.add_genome(genome)  # add the genome to hub

# make a group
group_map = bigtrack.Group(
    name="map",
    label="Mapping and Sequencing",
    priority=2,
)
genome.add_group(group_map)  # add the group to genome

# make a trackDb
trackDb_map = bigtrack.TrackDb(
    include="trackDb_map.txt",
)
genome.add_trackDb(trackDb_map)  # add the trackDb to genome

# make a track
track_ideogram = bigtrack.Track(
    track="cytoBandIdeo",
    shortLabel="Chromosome Band (Ideogram)",
    longLabel="Ideogram for Orientation",
    bigDataUrl="/path/to/track/file",
    type="bigBed 4 +",
    group="map",
)
trackDb_map.add_track(track_ideogram)  # add the track to trackDb

# finally, one function to generate the file structure
hub.generate()

Then, find your track hub under the ExampleHub/ directory.

Data structure

When hub.generate() runs, bigtrack writes a directory tree suitable for hosting as a UCSC Track Hub. The exact layout can be configured, but a typical generated structure looks like:

ExampleHub/
├─ hub.txt
├─ genomes.txt
├─ ExampleGenome/
│  ├─ groups.txt
│  ├─ trackDb.txt  # include all trackDbs
│  ├─ trackDb_map.txt
│  └─ trackDb_xxx.txt
└─ AnotherGenome/
   ├─ groups.txt
   ├─ trackDb.txt  # include all trackDbs
   ├─ trackDb_map.txt
   └─ trackDb_xxx.txt

You can host this directory on any web server (HTTP/HTTPS/FTP) and point UCSC Genome Browser at the hub.txt URL.

Hub components

bigtrack models the standard UCSC hub components as Python classes. Each object has reserved keywords — those are required for correct hub generation. Some fields have sensible defaults. Below are the main components, their purpose and required keys. Please note, required keys may not consistent with UCSC guidance.

Hub

Top-level hub object. Represents hub.txt.

Required keys: hub, shortLabel, longLabel, genomesFile (default: genomes.txt), email.

Genome

Represents a genome entry (appears in genomes.txt and holds per-genome resources).

Required keys: genome, trackDb (default: trackDb.txt), groups (default: groups.txt), organism, scientificName.

Group

A logical grouping for tracks used for UI organization.

Required keys: name, label, priority (default: 1), defaultIsClosed (default: 0).

TrackDb

A container class that holds tracks and writes a trackDb file.

Required keys: include.

Track

Basic (atomic) track object.

Required keys: track, parent (default: None), shortLabel, longLabel, type.

To enhance usage, track collections are also available.

CompositeTrack

A composite track groups multiple subtracks that share the same type. See UCSC docs for composite track settings.

Required keys: track, compositeTrack (default: on), parent (default: None), shortLabel, longLabel, type.

SampledCompositeTrack

A convenience helper that produces a sampled subset of a CompositeTrack automatically. Useful when you have many samples and want to produce a smaller subset for quick browsing.

bigtrack.SampledCompositeTrack(
    full_track: bigtrack.CompositeTrack,
    number: int,  # number of sampled child tracks from full_track
    random_seed: int = 0,
    suffix: str = "_subset",
    **kwargs,  # kwargs to override
)

SuperTrack

A superTrack provides a higher-level container that can contain multiple composite tracks or plain tracks. See UCSC docs for super track settings.

Required keys: track, superTrack (default: on), parent (default: None), shortLabel, longLabel.

Example

See codes for T2T Macaque Hub.

Todo

  • Add pre-flight checks while generating hubs
  • Add PyPi / conda support
  • Add automatic format conversion

Acknowledgement

Thanks to the Python package trackhub.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bigtrack-0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bigtrack-0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file bigtrack-0.1.tar.gz.

File metadata

  • Download URL: bigtrack-0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bigtrack-0.1.tar.gz
Algorithm Hash digest
SHA256 b50790ca3fe00fa5ef8662e022ff1e667438083021180fdcca53f9a4830450ba
MD5 cd5012bb2c3655e51248c28bf2e1977b
BLAKE2b-256 833a04a29f6e7e95aeca9941a54a0e5688c79f1ea06963ba0609a3ed87649bce

See more details on using hashes here.

Provenance

The following attestation bundles were made for bigtrack-0.1.tar.gz:

Publisher: python-publish.yml on zhang-shilong/bigtrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bigtrack-0.1-py3-none-any.whl.

File metadata

  • Download URL: bigtrack-0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bigtrack-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2c91c83bec9be87ed66610fdbc8005dc924b4c41dfb35caa543b79e91d02a60
MD5 37949db26d2022b3e66522ddf74691dc
BLAKE2b-256 0b2b14c476acc169daf2a36e508bf082864cf3ba549a0d2f894ec728ef4b7521

See more details on using hashes here.

Provenance

The following attestation bundles were made for bigtrack-0.1-py3-none-any.whl:

Publisher: python-publish.yml on zhang-shilong/bigtrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page