Loading a track

track.load(path, format=None, readonly=False)[source]

Loads a track from disk, whatever the format is.

Parameters:
  • path (string) – is the path to track file to load or an URL. If the path is an URL, the file will be downloaded automatically. If the path is a GZIP file, it will be decompressed automatically.
  • format (string) – is an optional parameter specifying the format of the track to load when it cannot be guessed from the file extension.
  • readonly (bool) – is an optional parameter that defaults to False. When set to True, any operation attempting to write to the track will silently be ignored
Returns:

a Track instance

import track
with track.load('tracks/rp_genes.bed') as rpgenes:
    data = rpgenes.read()
with track.load('/tmp/ae456f0', 'sql') as t:
    data = t.read()
with track.load('tracks/repeats.bed', readonly=True) as repeats:
    data = repeats.read()
with track.load('http://example.com/genes.bed') as genes:
    data = genes.read()

Creating a new track

track.new(path, format=None)[source]

Creates a new empty track in preparation for writing to it.

Parameters:
  • path (string) – is the path to track file to create.
  • format (string) – is an optional parameter specifying the format of the track to create when it cannot be guessed from the file extension.
Returns:

a Track instance

import track
with track.new('tmp/track.sql') as t:
    t.write('chr1', [(10, 20, 'Gene A', 0.0, 1)])
    t.set_chrmeta('hg19')
with track.new('tracks/peaks.sql', 'sql') as t:
    t.fields = ['start', 'end', 'name', 'score']
    t.write('chr5', [(500, 1200, 'Peak1', 11.3)])

Converting tracks

track.convert(source, destination, assembly=None)[source]

Converts a track from one format to an other. The source file should have a different format from the destination file. If either the source or destination are missing a file extension, you can specify their formats using a tuple. See examples below.

Parameters:
  • source (string) – is the path to the original track to load.
  • destination (string) – is the path to the track to be created.
  • assembly (string) – an optional compatible assembly name. Useful when the destination format needs to contain chromosome meta data and this is not available in the source file.
Returns:

the path to the track created (or a list of track paths in the case of multi-track files).

import track
track.convert('tracks/genes.bed', 'tracks/genes.sql')
track.convert('tracks/genes.sql', 'tracks/genes.bigWig', assembly='hg19')
track.convert(('tracks/no_extension', 'gff'), 'tracks/genes.sql')
track.convert(('tmp/4afb0edf', 'bed'), ('tmp/converted', 'wig'))

Table Of Contents

Previous topic

Quick start

Next topic

Using the Track object

This Page