lib5c.parsers.bed module

Module for parsing .bed files.

lib5c.parsers.bed.load_features(bedfile, id_index=None, value_index=None, boundaries=None, strict=True)[source]

Loads the features from a .bed file into dicts and returns them.

Parameters
  • bedfile (str) – String reference to location of .bed file to load features from.

  • id_index (int) – If passed, indicates the column index of the id field.

  • value_index (int) – If passed, indicates the column index of the value field.

  • boundaries (list of dicts) –

    If passed, features will only be loaded if they intersect at least one of the features in this list. The features should be represented as dicts with the following structure:

    {
        'chrom': str,
        'start': int,
        'end'  : int
    }
    

  • strict (boolean) – If True, there must not be any incomplete lines in the bedfile.

Returns

The keys are chromosome names. The values are lists of features for that chromosome. The features are represented as dicts with the following structure:

{
    'chrom': str,
    'start': int,
    'end'  : int,
    'id'   : str or None,
    'value': float or None
}

The ‘id’ and ‘value’ fields may be None if no feature ID’s were provided in the BED file, but the keys will always be present in the returned dict.

Return type

dict of lists of dicts

Notes

The parser will attempt to guess the column indices of the id and value fields based on the number of columns and the types of the column entries.

lib5c.parsers.bed.main()[source]