Skip to content

Commit

Permalink
Fixes #5
Browse files Browse the repository at this point in the history
This biggest issue here is that the vanilla notebooks treated SVGs as images, such that the IDs used in their generation were not treated as unique. Therefore, when painted onto the DOM, since SVGs could have non-unique IDs, they would collide with each other. This isn't really seen in jupyterlab because of how it does rendering, but this issues was originally seen in ipython/ipython#1866. I fixed this by quickly parsing the SVG data and inserting the original hash of the data into the unique ids. Kind of a pain, but it fixes this problem
  • Loading branch information
betteridiot committed Aug 14, 2019
1 parent 22052d3 commit 66021f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions seqlogo/seqlogo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np
import pandas as pd
import tempfile
import re

import pkg_resources
weblogo_version = pkg_resources.get_distribution('weblogo').version
Expand All @@ -10,6 +12,7 @@
import weblogo as wl
except ModuleNotFoundError:
import weblogo as wl

from seqlogo import utils


Expand Down Expand Up @@ -89,26 +92,23 @@ def seqlogo(pm, ic_scale = True, color_scheme = None, size = 'medium',

# Create the file if the user supplied an filename
if filename:
out_file = open('{}'.format(filename), 'wb')
out_file.write(out)
out_file.close()
with open('{}'.format(filename), 'wb') as out_file:
out_file.write(out)

if format == 'svg':
svg_hash = hash(out)
out = re.sub(rb'("#?glyph.*?)(")', rb'\1 %s\2' % str(svg_hash).encode(), out)

try:
if get_ipython():
import IPython.display as ipd
if format == 'svg':
ipd.display(ipd.SVG(out))
return ipd.SVG(out)
elif format in ('png', 'jpeg', 'svg'):
ipd.display(ipd.Image(out))
return ipd.Image(out)
else:
raise ValueError('{} format not supported for plotting in console'.format(format))
if filename:
with open(filename, 'wb') as out_file:
out_file.write(out)
except NameError:
if filename is None:
raise ValueError('If not in an IPython/Jupyter console and no filename is given, nothing will be rendered')
else:
with open('{}'.format(filename), 'wb') as out_file:
out_file.write(out)


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from os import path

__version__ = '5.29.5'
__version__ = '5.29.6'

def readme():
this_directory = path.abspath(path.dirname(__file__))
Expand Down

0 comments on commit 66021f0

Please sign in to comment.