Skip to content

Commit

Permalink
Merge pull request #18211 from mvdbeek/fix_pca_3d_rendering_and_error…
Browse files Browse the repository at this point in the history
…_handling

[24.0] Fix pca 3d rendering of tabular files and visualization error handling in general
  • Loading branch information
dannon authored May 23, 2024
2 parents 3a89e74 + 15fa3a4 commit 326e291
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
20 changes: 14 additions & 6 deletions config/plugins/visualizations/PCA_3Dplot/templates/PCA_3Dplot.mako
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<%!
import csv
import sys
from io import StringIO
import csv
from galaxy.exceptions import RequestParameterInvalidException
MAX_SIZE = 100000 # 100 KB, empirically the largest value I can render on my browser (m2 mac, chrome)
%>

<%
Expand Down Expand Up @@ -29,11 +33,15 @@ def create_options(header):
return colour_options, start_options
def load_data():
input = "\n".join(list(hda.datatype.dataprovider(hda, 'line', comment_char=none, provide_blank=True, strip_lines=False, strip_newlines=True)))
tabular_file = StringIO(input)
dialect = csv.Sniffer().sniff(tabular_file.read(1024), delimiters=";,\t")
tabular_file.seek(0)
table = csv.reader(tabular_file, dialect)
lines = []
size = 0
for line in hda.datatype.dataprovider(hda, 'line', comment_char=none, provide_blank=True, strip_lines=False, strip_newlines=True):
size += len(line)
if size > MAX_SIZE:
raise RequestParameterInvalidException("Dataset too large to render, dataset must be less than 100 KB in size.")
lines.append(line)
dialect = csv.Sniffer().sniff("\n".join(lines))
table = csv.reader(lines, dialect)
data = "["
for i, row in enumerate(table):
if i == 0:
Expand Down
15 changes: 13 additions & 2 deletions config/plugins/visualizations/ts_visjs/templates/ts_visjs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import collections
import json
import sys
from numpy import inf
from galaxy.exceptions import RequestParameterInvalidException
MAX_SIZE = 100000 # 100 KB
%>

<%
Expand Down Expand Up @@ -58,8 +62,15 @@ def write_reaction(edge_id, left_index, right_index, substrates, products, rate,
def load_data():
output = {"nodes": "", "border_nodes": "", "edges": "", "edges": "", "self_loops": ""}
data = ''.join(list(hda.datatype.dataprovider(hda, 'line', strip_lines=True, strip_newlines=True)))
data = json.loads(data)
lines = []
size = 0
for line in hda.datatype.dataprovider(hda, 'line', strip_lines=True, strip_newlines=True):
size += len(line)
if size > MAX_SIZE:
raise RequestParameterInvalidException("Dataset too large to render, dataset must be less than 100 KB in size.")
lines.append(line)
data = json.loads("".join(lines))
ordering = data['ordering']
nodes = {int(key): to_counter(data['nodes'][key], ordering) for key in data['nodes'].keys()}
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/controllers/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def render(self, trans, visualization_name, embedded=None, **kwargs):
try:
return plugin.render(trans=trans, embedded=embedded, **kwargs)
except Exception as exception:
self._handle_plugin_error(trans, visualization_name, exception)
return self._handle_plugin_error(trans, visualization_name, exception)

def _get_plugin_from_registry(self, trans, visualization_name):
"""
Expand Down

0 comments on commit 326e291

Please sign in to comment.