Ejemplo n.º 1
0
def uncompress_if_required(fhand):
    'It returns a uncompressed handle if required'
    magic = peek_chunk_from_file(fhand, 2)
    if magic == '\037\213':
        fhand = GzipFile(fileobj=fhand)
    elif magic == 'BZ':
        try:
            fhand = BZ2File(fhand)
        except NameError:
            raise OptionalRequirementError(BZIP_ERROR)
    return fhand
Ejemplo n.º 2
0
def get_fig_and_canvas(num_rows=1, num_cols=1, figsize=None):
    if figsize is None:
        height = 5.0 * num_rows
        width = 7.5 * num_cols
        if height > 320.0:
            height = 320.0
        figsize = (width, height)
    try:
        fig = Figure(figsize=figsize)
        canvas = FigureCanvas(fig)
    except NameError:
        msg = 'Matplotlib module is required to draw graphical histograms'
        raise OptionalRequirementError(msg)
    return fig, canvas
Ejemplo n.º 3
0
def compress_fhand(fhand, compression_kind=None):
    'Compresses the file if required'
    if compression_kind == BGZF:
        if fhand_is_seekable(fhand):
            fhand = BgzfWriter(fileobj=fhand)
        else:
            raise RuntimeError('bgzf is only available for seekable files')
    elif compression_kind == GZIP:
        fhand = GzipFile(fileobj=fhand)
    elif compression_kind == BZIP2:
        mode = 'w' if 'w' in fhand.mode else 'r'
        try:
            fhand = BZ2File(fhand, mode=mode)
        except NameError:
            raise OptionalRequirementError(BZIP_ERROR)
    return fhand
Ejemplo n.º 4
0
def get_canvas_and_axes(figure_size=FIGURE_SIZE,
                        left=0.1,
                        right=0.9,
                        top=0.9,
                        bottom=0.1,
                        plot_type=111):
    'It returns a matplotlib canvas and axes instance'
    try:
        fig = Figure(figsize=FIGURE_SIZE)
        canvas = FigureCanvas(fig)
    except NameError:
        msg = 'Matplotlib module is required to draw graphical histograms'
        raise OptionalRequirementError(msg)

    axes = fig.add_subplot(plot_type)
    fig.subplots_adjust(left=left, right=right, top=top, bottom=bottom)

    return canvas, axes
Ejemplo n.º 5
0
 def FakeRequiredfunct(*args, **kwargs):
     raise OptionalRequirementError(msg)
Ejemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     raise OptionalRequirementError(msg)