lcdblib.utils package

Submodules

lcdblib.utils.chrom_convert module

Converts between chromosome names.

lcdblib.utils.chrom_convert.arguments()[source]

Function to pull command line arguments

lcdblib.utils.chrom_convert.convertFeature(f, mapper)[source]
lcdblib.utils.chrom_convert.fasta_convert(input, output, mapper)[source]

Uses Biopython.SeqIO to convert FASTA headers.

lcdblib.utils.chrom_convert.import_conversion(f, t)[source]

Import NCBI conversion table.

Parameters:
  • f (str {FlyBase, UCSC, NCBI}) – The current chromosome format.
  • t (str {FlyBase, UCSC, NCBI}) – The desired chromosome format.
Returns:

dict

Return type:

Mapping {f: t}

lcdblib.utils.chrom_convert.main()[source]
lcdblib.utils.chrom_convert.pybedtools_convert(input, output, mapper)[source]

Use pybedtools to convert chromosomes in BED, GTF, or GFF.

lcdblib.utils.chrom_convert.pysam_convert(input, output, kind, mapper)[source]

Use pysam to convert chromosomes in BAM and SAM files.

pysam uses a header to define chromosomes, then each read is just mapped back to this header. Only the header needs to be modified, and reads need to be written to the new output file which uses this header.

lcdblib.utils.imports module

lcdblib.utils.imports.resolve_name(name)[source]

Imports a specific object from a dotted path and returns just that object.

From nose.utils.resolve_name (with the logging parts taken out) which in turn is from unittest.TestLoader.loadTestByName

lcdblib.utils.utils module

lcdblib.utils.utils.boolean_labels(names, idx, mapping={False: 'NOT', True: 'AND'}, strip='AND_')[source]

Creates labels for boolean lists.

For example:

>>> names = ['exp1', 'exp2', 'exp3']
>>> idx = [True, True, False]
>>> boolean_labels(names, idx)
'exp1_AND_exp2_NOT_exp3'
Parameters:
  • names (list) – List of names to include in output
  • idx (list) – List of booleans, same size as names
  • mapping (dict) – Linking words to use for True and False
  • strip (str) – Strip this text off the beginning of labels.
  • a list of names and a same-size boolean, return strings like (given) –
  • a_NOT_b_AND_c
  • or
  • a_AND_b_AND_c_NOT_d_AND_e
lcdblib.utils.utils.flatten(iter, unlist=False)[source]

Flatten an arbitrarily nested iterable whose innermost items are strings into a flat list of strings.

Parameters:
  • iter (iterable) –
  • unlist (bool) – If True, convert single-item lists into a bare string

Helper function to create a relative symlink.

Changes to the dirname of the linkname and figures out the relative path to the target before creating the symlink.

lcdblib.utils.utils.temp_env(env)[source]

Context manager to temporarily set os.environ.

lcdblib.utils.utils.test_flatten()[source]
lcdblib.utils.utils.update_recursive(orig, update_with)[source]

Recursively update one dict with another.

From https://stackoverflow.com/a/3233356

>>> orig = {'a': {'b': 1, 'c': 2, 'd': [7, 8, 9]}}
>>> update_with = {'a': {'b': 5}}
>>> expected = {'a': {'b': 5, 'c': 2, 'd': [7, 8, 9]}}
>>> result = update_recursive(orig, update_with)
>>> assert result == expected, result
>>> update_with = {'a': {'d': 1}}
>>> result = update_recursive(orig, update_with)
>>> expected = {'a': {'b': 5, 'c': 2, 'd': 1}}
>>> result = update_recursive(orig, update_with)
>>> assert result == expected, result
lcdblib.utils.utils.updatecopy(orig, update_with, keys=None, override=False)[source]

Update a copy of a dictionary, with a bit more control than the built-in dict.update.

Parameters:
  • orig (dict) – Dict to update
  • update_with (dict) – Dict with new values
  • keys (list or None) – If not None, then only consider these keys in update_with. Otherwise consider all.
  • override (bool) – If True, then this is similar to dict.update, except only those keys in keys will be considered. If False (default), then if a key exists in both orig and update_with, no updating will occur so orig will retain its original value.

Module contents