Loading into memory

This submodule enables you to read tracks into memory and to write tracks from memory using dictionaries. Doing this can quickly create memory problems, and is discouraged. However, if you know your track is not very large, and you want to load in the RAM, you can.

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

Loads a track from disk, whatever the format is and puts it in an enourmous dictionary. Contrary to most of the algorithms in this package, this method will load everything into the RAM. Be careful when using this method on large tracks.

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 dictionary containing all features of every chromosome contained in a track.

from track.memory import read, write
genes = read('tracks/rp_genes.bed')
print genes['chrX'][1523]
track.memory.write(dictionary, path, format=None)[source]

Write a dictionary to disk, whatever the format is.

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

None

from track.memory import read, write
genes = read('tracks/rp_genes.gff')
genes['chrX'][1523] = (183, 195, 'bra', 1.9)
write('tracks/modified.bed', genes)

Previous topic

Manipulating tracks

Next topic

Numbering convention

This Page