From f977b74c3e8ee336bad64cb8c43ad1e28b909fd7 Mon Sep 17 00:00:00 2001 From: Shaun Adkins Date: Thu, 7 Nov 2024 15:35:51 -0500 Subject: [PATCH 1/3] download file in chunks --- www/cgi/download_source_file.cgi | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/www/cgi/download_source_file.cgi b/www/cgi/download_source_file.cgi index 61d7779c..7de5ee9c 100755 --- a/www/cgi/download_source_file.cgi +++ b/www/cgi/download_source_file.cgi @@ -5,15 +5,28 @@ or H5AD file. ''' -from shutil import copyfileobj -import sys -import cgi, html, json import os +import sys lib_path = os.path.abspath(os.path.join('..', '..', 'lib')) sys.path.append(lib_path) import geardb + +def download_file(file_path, file_name): + print("Content-type: application/octet-stream") + print(f"Content-Disposition: attachment; filename={file_name}") + print() + sys.stdout.flush() + + with open(file_path, 'rb') as binfile: + while True: + chunk = binfile.read(8192) # Read in 8KB chunks + if not chunk: + break + sys.stdout.buffer.write(chunk) + sys.stdout.buffer.flush() + def main(): form = cgi.FieldStorage() dataset_id = html.escape(form.getvalue('dataset_id')) @@ -40,23 +53,9 @@ def main(): h5ad_path = "" if dtype == 'tarball' and os.path.isfile(tarball_path): - print("Content-type: application/octet-stream") - print("Content-Disposition: attachment; filename={0}.tar.gz".format(dataset_id)) - print() - sys.stdout.flush() - - with open(tarball_path, 'rb') as binfile: - copyfileobj(binfile, sys.stdout.buffer) - + download_file(tarball_path, f"{dataset_id}.tar.gz") elif dtype == 'h5ad' and os.path.isfile(h5ad_path): - print("Content-type: application/octet-stream") - print("Content-Disposition: attachment; filename={0}.h5ad".format(dataset_id)) - print() - sys.stdout.flush() - - with open(h5ad_path, 'rb') as binfile: - copyfileobj(binfile, sys.stdout.buffer) - + download_file(h5ad_path, f"{dataset_id}.h5ad") else: raise FileNotFoundError("File not found") From 83ad322ea9e511d0c724c920b7eadf0a7819059c Mon Sep 17 00:00:00 2001 From: adkinsrs Date: Mon, 11 Nov 2024 14:26:07 -0500 Subject: [PATCH 2/3] bugfix --- www/cgi/download_source_file.cgi | 1 + 1 file changed, 1 insertion(+) diff --git a/www/cgi/download_source_file.cgi b/www/cgi/download_source_file.cgi index 7de5ee9c..5e7fd425 100755 --- a/www/cgi/download_source_file.cgi +++ b/www/cgi/download_source_file.cgi @@ -7,6 +7,7 @@ or H5AD file. import os import sys +import cgi, html lib_path = os.path.abspath(os.path.join('..', '..', 'lib')) sys.path.append(lib_path) From 6c3c3cc0aadb866dd0df3c2b8ed45fee69fde90b Mon Sep 17 00:00:00 2001 From: Shaun Adkins Date: Fri, 13 Dec 2024 09:04:21 -0500 Subject: [PATCH 3/3] tSNE plots should now scale properly --- www/api/resources/tsne_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/api/resources/tsne_data.py b/www/api/resources/tsne_data.py index aa2e5d25..6d894b50 100644 --- a/www/api/resources/tsne_data.py +++ b/www/api/resources/tsne_data.py @@ -517,7 +517,7 @@ def post(self, dataset_id): dpi = io_fig.dpi # default dpi is 100, but will be saved as 150 later on # With 2 plots as a default (gene expression and colorize_by), we want to grow the figure size slowly based on the number of plots - num_plots_wide = max_columns if max_columns else num_plots + num_plots_wide = max_columns if plot_by_group and max_columns else num_plots num_plots_high = ceil(num_plots / num_plots_wide) # set the figsize based on the number of plots