rrazaghi / modbamtools

Set of tools to manipulate and visualize modified base bam files
Apache License 2.0
47 stars 4 forks source link

Plotting a BED file - parse_bed_rectangle_gl function #24

Open steven-solar opened 1 year ago

steven-solar commented 1 year ago

Hi, I am using modbamtools to view methylation of a region of interest and ran the following command:

modbamtools plot \
    -r <chr>:<start>-<end> \
    -b <example>.bed \
    -o <example> \
    <example>.bam

And received the following error:

Traceback (most recent call last):
  File "/opt/conda/envs/0.4.8/bin/modbamtools", line 8, in <module>
    sys.exit(cli())
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/modbamtools/cli.py", line 334, in plot
    fig = Plotter(
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/modbamtools/modbamviz.py", line 47, in __init__
    self.tracks, self.num_tracks = get_tracks_gl(
  File "/opt/conda/envs/0.4.8/lib/python3.9/site-packages/modbamtools/tracks_webgl.py", line 242, in get_tracks_gl
    elements = parse_bed_rectangle_gl(bed, chrom, start, end)
NameError: name 'parse_bed_rectangle_gl' is not defined

I was able to successfully plot my bams without including a BED file (same command but without including the -b flag), but I wanted to include a bed file to denote a region of particular interest. Any idea what may be causing the issue or how to fix it? Thanks!

rl4940 commented 1 year ago

I am suffering the same error code

jazsakr commented 9 months ago

I had that same issue. Looking at that tracks_webgl.py script, it seems like that function might be called parse_bed_gl and not parse_bed_rectangle_gl. So edited that line 242 from elements = parse_bed_rectangle_gl(bed, chrom, start, end) to elements = parse_bed_gl(bed, chrom, start, end). That seemed to work but then I got a new error:

Traceback (most recent call last):
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/bin/modbamtools", line 8, in <module>
    sys.exit(cli())
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/modbamtools/cli.py", line 334, in plot
    fig = Plotter(
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/modbamtools/modbamviz.py", line 47, in __init__
    self.tracks, self.num_tracks = get_tracks_gl(
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/modbamtools/tracks_webgl.py", line 242, in get_tracks_gl
    elements = parse_bed_gl(bed, chrom, start, end)
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/site-packages/modbamtools/tracks_webgl.py", line 126, in parse_bed_gl
    for l in b:
  File "/data/homezvol3/jsakr/miniconda3/envs/methyl/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

From googling, it looks like my new error might be due to the compression of my bed file. The modbamtools documentation says --bed "makes tracks from sorted and tabix bed files." If I don't compress my bed file, I get a [tabix] the compression of 'ccres_sorted.bed' is not BGZF error.