changeset 5:e860ca30cd0b draft default tip

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/vitessce commit 90f081e58b5ee41bba3a7e6f01d97b5bd9392759
author goeckslab
date Wed, 28 May 2025 21:14:52 +0000
parents 5f4a4dd06bc9
children
files gate_finder.py gate_finder.xml index.html main_macros.xml vitessce_spatial.py
diffstat 5 files changed, 46 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gate_finder.py	Thu Feb 20 19:47:28 2025 +0000
+++ b/gate_finder.py	Wed May 28 21:14:52 2025 +0000
@@ -53,7 +53,7 @@
     return get_gate_phenotype(gate, np.ravel(data_norm))
 
 
-def main(inputs, output, image, anndata, offsets=None, masks=None):
+def main(inputs, output, image, anndata, offsets=None, masks=None, config_path=None):
     """
     Parameter
     ---------
@@ -67,12 +67,17 @@
         File path to anndata containing phenotyping info.
     masks : str
         File path to the image masks.
+    config_path : str
+        File path to the config containing galaxy_url and dataset_id.
     """
     warnings.simplefilter('ignore')
 
     with open(inputs, 'r') as param_handler:
         params = json.load(param_handler)
 
+    with open(config_path) as conf_fh:
+        config = json.load(conf_fh)
+
     marker = params['marker'].strip()
     from_gate = params['from_gate']
     to_gate = params['to_gate']
@@ -80,6 +85,12 @@
     x_coordinate = params['x_coordinate'].strip() or 'X_centroid'
     y_coordinate = params['y_coordinate'].strip() or 'Y_centroid'
 
+    galaxy_url = config["galaxy_url"]
+    dataset_id = config["dataset_id"]
+
+    # Build the prefix that Vitessce should use
+    display_prefix = (f"{galaxy_url}/api/datasets/{dataset_id}/display?filename=")
+
     adata = read_h5ad(anndata)
 
     # If no raw data is available make a copy
@@ -191,7 +202,7 @@
     )
 
     # export config file
-    config_dict = vc.export(to='files', base_url='http://localhost', out_dir=output)
+    config_dict = vc.export(to='files', base_url=display_prefix, out_dir=output)
 
     with open(Path(output).joinpath('config.json'), 'w') as f:
         json.dump(config_dict, f, indent=4)
@@ -205,7 +216,8 @@
     aparser.add_argument("-a", "--anndata", dest="anndata", required=True)
     aparser.add_argument("-f", "--offsets", dest="offsets", required=False)
     aparser.add_argument("-m", "--masks", dest="masks", required=False)
+    aparser.add_argument("--galaxy_config", dest="config_path", required=True)
 
     args = aparser.parse_args()
 
-    main(args.inputs, args.output, args.image, args.anndata, args.offsets, args.masks)
+    main(args.inputs, args.output, args.image, args.anndata, args.offsets, args.masks, args.config_path)
--- a/gate_finder.xml	Thu Feb 20 19:47:28 2025 +0000
+++ b/gate_finder.xml	Wed May 28 21:14:52 2025 +0000
@@ -12,6 +12,14 @@
     <expand macro="vitessce_cmd" tool_id="gate_finder" />
     <configfiles>
         <inputs name="inputs" />
+        <configfile name="galaxy_config">
+            <![CDATA[
+            {
+            "galaxy_url": "${__app__.config.galaxy_infrastructure_url}",
+            "dataset_id": "${__app__.security.encode_id($output.dataset.id)}"
+            }
+                    ]]>
+        </configfile>
     </configfiles>
     <inputs>
         <param name="image" type="data" format="ome.tiff" label="Select the image (OME-TIFF)" />
--- a/index.html	Thu Feb 20 19:47:28 2025 +0000
+++ b/index.html	Wed May 28 21:14:52 2025 +0000
@@ -27,31 +27,13 @@
       import { Vitessce } from 'vitessce';
       import { config } from './config.js';
 
-      console.log('here be url: '+window.location.href);
-      var current_url = window.location.href.replace(new RegExp('\/[^\/]*$'), '');
-      console.log(current_url);
-      function rewriteURL(input) {
-        for (let k in input) {
-        if (typeof input[k] === 'string' || input[k] instanceof String) {
-            input[k] = input[k].replace('http://localhost', current_url)
-        }
-        else {
-            input[k] = rewriteURL(input[k])
-        }
-        }
-        return input;
-      };
-      var fixed_conf = {...config};
-      fixed_conf = rewriteURL(fixed_conf);
-      console.log('conf fixed:');
-      console.log(fixed_conf);
       function MyApp() {
         return React.createElement(
           Vitessce,
           {
             height: 1000,
             theme: 'dark',
-            config: fixed_conf,
+            config: config,
           }
         );
       }
--- a/main_macros.xml	Thu Feb 20 19:47:28 2025 +0000
+++ b/main_macros.xml	Wed May 28 21:14:52 2025 +0000
@@ -1,6 +1,6 @@
 <macros>
     <token name="@TOOL_VERSION@">3.5.1</token>
-    <token name="@VERSION_SUFFIX@">0</token>
+    <token name="@VERSION_SUFFIX@">1</token>
     <token name="@PROFILE@">22.01</token>
 
     <xml name="vitessce_requirements">
@@ -68,6 +68,7 @@
             --inputs '$inputs'
             --output '${output.files_path}'
             --image '${output.files_path}/A/0/image01.ome.tiff'
+            --galaxy_config '${galaxy_config}'
             --offsets '$image.metadata.offsets'
             #if $masks
                 --masks '${output.files_path}/A/0/masks01.ome.tiff'
@@ -76,8 +77,9 @@
             --anndata '$anndata'
             #end if
             &&
-        cp '$__tool_directory__/index.html' '$output';
-        echo "export var config = \$(cat ${output.files_path}/config.json)" >> '${output.files_path}/config.js';
+        cp '$__tool_directory__/index.html' '$output' &&
+        sed -i 's|display?filename=/|display?filename=|g' ${output.files_path}/config.json &&
+        echo "export var config = \$(cat ${output.files_path}/config.json)" >> '${output.files_path}/config.js' &&
         cat '${output.files_path}/config.json' >> '$vitessce_config';
         ]]>
         </command>
--- a/vitessce_spatial.py	Thu Feb 20 19:47:28 2025 +0000
+++ b/vitessce_spatial.py	Wed May 28 21:14:52 2025 +0000
@@ -2,6 +2,7 @@
 import json
 import warnings
 from os.path import isdir, join
+# import urllib.parse
 from pathlib import Path
 
 import scanpy as sc
@@ -19,7 +20,7 @@
 )
 
 
-def main(inputs, output, image, offsets=None, anndata=None, masks=None):
+def main(inputs, output, image, offsets=None, anndata=None, masks=None, config_path=None):
     """
     Parameter
     ---------
@@ -33,12 +34,20 @@
         File path to anndata containing phenotyping info.
     masks : str
         File path to the image masks.
+    config_path : str
+        File path to the config file containing galaxy_url and dataset_id.
     """
     warnings.simplefilter('ignore')
 
     with open(inputs, 'r') as param_handler:
         params = json.load(param_handler)
 
+    with open(config_path) as conf_fh:
+        config = json.load(conf_fh)
+
+    galaxy_url = config["galaxy_url"]
+    dataset_id = config["dataset_id"]
+
     # initialize vitessce config and add OME-TIFF image, and masks if specified
     vc = VitessceConfig(schema_version="1.0.17", name=None, description=None)
     dataset = vc.add_dataset()
@@ -73,12 +82,15 @@
         w=lc_dims[0],
         h=lc_dims[1])
 
+    # Build the prefix that Vitessce should use
+    display_prefix = (f"{galaxy_url}/api/datasets/{dataset_id}/display?filename=")
+
     # if no anndata file, export the config with these minimal components
     if not anndata:
         vc.layout(lc | spatial)
         config_dict = vc.export(
             to='files',
-            base_url='http://localhost',
+            base_url=display_prefix,
             out_dir=output)
         with open(Path(output).joinpath('config.json'), 'w') as f:
             json.dump(config_dict, f, indent=4)
@@ -191,7 +203,7 @@
     # export the config file
     config_dict = vc.export(
         to='files',
-        base_url='http://localhost',
+        base_url=display_prefix,
         out_dir=output)
 
     with open(Path(output).joinpath('config.json'), 'w') as f:
@@ -206,7 +218,8 @@
     aparser.add_argument("-f", "--offsets", dest="offsets", required=False)
     aparser.add_argument("-a", "--anndata", dest="anndata", required=False)
     aparser.add_argument("-m", "--masks", dest="masks", required=False)
+    aparser.add_argument("--galaxy_config", dest="config_path", required=True)
 
     args = aparser.parse_args()
 
-    main(args.inputs, args.output, args.image, args.offsets, args.anndata, args.masks)
+    main(args.inputs, args.output, args.image, args.offsets, args.anndata, args.masks, args.config_path)