hubward package¶
Submodules¶
hubward.generate_config_from_schema module¶
-
hubward.generate_config_from_schema.
access
(dct, keys)[source]¶ Access a value from an arbitrarily-nested dictionary, given a set of keys.
If any key doesn’t exist, returns None.
>>> access({'a': {'aa': {'aaa': {'b': 1, 'c': 2}}}}, keys=['a', 'aa', 'aaa', 'b']) 1
-
hubward.generate_config_from_schema.
create_config
(schema, fout=None)[source]¶ Generates an example config file based on the schema alone and writes it to fout, which can then be validated.
The goal is to have the schema be the sole source of config files.
“description” fields in the schema will be printed out as YAML comments, serving as documentation.
Parameters: schema : str
Filename of schema
fout : file-like
Output file to write YAML to.
-
hubward.generate_config_from_schema.
follow_ref
(ref, dct)[source]¶ Follow a “$ref” JSON Schema reference
-
hubward.generate_config_from_schema.
ordered_load
(stream, Loader=<class 'yaml.loader.Loader'>, object_pairs_hook=<class 'collections.OrderedDict'>)[source]¶ Load YAML into an ordered dictionary to maintain key sorting.
hubward.liftover module¶
Module for converting genomic coordinates from one version of an assembly to another
hubward.log module¶
hubward.models module¶
-
class
hubward.models.
Data
(obj, reldir)[source]¶ Bases:
object
Methods
liftover
(from_assembly, to_assembly, newfile)Lifts over the processed file to a new file, but only if needed. process
()Run the conversion script if the output needs updating. -
liftover
(from_assembly, to_assembly, newfile)[source]¶ Lifts over the processed file to a new file, but only if needed.
Uses a hidden sentinel file to indicate whether it’s been lifted over.
Parameters: from_assembly : str
Existing data are in this assembly’s coordinates
to_assembly : str
Lift over existing data to this assembly’s coordinates
newfile : str
Target filename of the lifted-over data
-
-
class
hubward.models.
Group
(fn)[source]¶ Bases:
object
Methods
process
()upload
([hub_only, host, user, ...])
-
class
hubward.models.
Study
(dirname)[source]¶ Bases:
object
Methods
composite_track
()Create a composite track ready to be added to a trackhub.TrackDb instance. process
([force])reference_section
()Creates a ReST-formatted reference section to be appended to the end of the documentation for the composite track config page.
hubward.utils module¶
-
hubward.utils.
add_chr
(f)[source]¶ Prepend “chr” to the beginning of chromosome names.
Useful when passed to pybedtool.BedTool.each().
-
hubward.utils.
bigbed
(filename, genome, output, blockSize=256, itemsPerSlot=512, bedtype=None, _as=None, unc=False, tab=False)[source]¶ Parameters: :filename:
BED-like file to convert
:genome:
Assembly string (e.g., “mm10” or “hg19”)
:output:
Path to bigBed file to create.
Other args are passed to bedToBigBed. In particular, `bedtype` (which
becomes the “-type=” argument) is automatically handled for you if it is
kept as the default None.
Assumes that a recent version of bedToBigBed from UCSC is on the path.
-
hubward.utils.
bigwig
(filename, genome, output, blockSize=256, itemsPerSlot=512, bedtype=None, _as=None, unc=False, tab=False)[source]¶ Parameters: :filename:
BEDGRAPH-like file to convert
:genome:
Assembly string (e.g., “mm10” or “hg19”)
:output:
Path to bigWig file to create.
Other args are passed to bedGraphToBigWig.
-
hubward.utils.
colored_bigbed
(x, color, genome, target, autosql=None, bedtype=None)[source]¶ if color is “smart”, then use metaseq’s smart colormap centered on zero.
otherwise, use singlecolormap.
assumes that you have scores in BedTool x; this will zero all scores in the final bigbed
-
hubward.utils.
colortuple
(col)[source]¶ Given a color in any format supported by matplotlib, return a comma-separated string of R,G,B uint8 values.
-
hubward.utils.
fix_macs_wig
(fn, genome, output=None, add_chr=False, to_ignore=None)[source]¶ wig files created by MACS often are extended outside the chromsome ranges. This function edits an input WIG file to fit within the chromosome boundaries defined by genome.
If add_chr is True, then prefix each chromosome name with “chr”.
Also gets rid of any track lines so the file is ready for conversion to bigWig.
Returns the output filename.
- fn : str
- Input WIG filename. Can be gzipped, if extension ends in .gz.
genome : str or dict
- output : str or None
- If None, writes to temp file
- to_ignore : list
- List of chromosomes to ignore.
-
hubward.utils.
get_resource
(fn, as_tempfile=False)[source]¶ Retrieve an installed resource.
If an installed resource can’t be found, then assume we’re working out of the source directory in which case we can find the file in the ../resources dir.
By default, returns a string. If as_tempfile=True, then write the string to a tempfile and return that new filename. The caller is responsible for deleting the tempfile.
-
hubward.utils.
makedirs
(dirnames)[source]¶ Recursively create the given directory or directories without reporting errors if they are present.
-
hubward.utils.
reST_to_html
(s)[source]¶ Convert ReST-formatted string s into HTML.
Output is intended for uploading to UCSC configuration pages, so this uses a whitelist approach for HTML tags.
-
hubward.utils.
sanitize
(s, strict=False)[source]¶ If strict, only allow letters and digits – spaces will be stripped.
Otherwise, convert spaces to underscores.
-
hubward.utils.
singlecolormap
(color, func=None, n=64)[source]¶ Creates a linear colormap where color is the top, and func(color) is the bottom.
func should take an RGB tuple as its only input. If func is None, then use a light gray as the min.
n is the number of levels.
-
hubward.utils.
smart_colormap
(vmin, vmax, color_high='#b11902', hue_low=0.6)[source]¶ Creates a “smart” colormap that is centered on zero, and accounts for asymmetrical vmin and vmax by matching saturation/value of high and low colors.
It works by first creating a colormap from white to color_high. Setting this color to the max(abs([vmin, vmax])), it then determines what the color of min(abs([vmin, vmax])) should be on that scale. Then it shifts the color to the new hue hue_low, and finally creates a new colormap with the new hue-shifted as the low, color_high as the max, and centered on zero.
Parameters: color_high : color
Can be any format supported by matplotlib. Try “#b11902” for a nice red.
hue_low : float in [0, 1]
Try 0.6 for a nice blue
vmin : float
Lowest value in data you’ll be plotting
vmax : float
Highest value in data you’ll be plotting