comparison vitessce_spatial.py @ 5:e860ca30cd0b draft

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
comparison
equal deleted inserted replaced
4:5f4a4dd06bc9 5:e860ca30cd0b
1 import argparse 1 import argparse
2 import json 2 import json
3 import warnings 3 import warnings
4 from os.path import isdir, join 4 from os.path import isdir, join
5 # import urllib.parse
5 from pathlib import Path 6 from pathlib import Path
6 7
7 import scanpy as sc 8 import scanpy as sc
8 from anndata import read_h5ad 9 from anndata import read_h5ad
9 from vitessce import ( 10 from vitessce import (
17 optimize_adata, 18 optimize_adata,
18 VAR_CHUNK_SIZE, 19 VAR_CHUNK_SIZE,
19 ) 20 )
20 21
21 22
22 def main(inputs, output, image, offsets=None, anndata=None, masks=None): 23 def main(inputs, output, image, offsets=None, anndata=None, masks=None, config_path=None):
23 """ 24 """
24 Parameter 25 Parameter
25 --------- 26 ---------
26 inputs : str 27 inputs : str
27 File path to galaxy inputs config file. 28 File path to galaxy inputs config file.
31 File path to the OME Tiff image. 32 File path to the OME Tiff image.
32 anndata : str 33 anndata : str
33 File path to anndata containing phenotyping info. 34 File path to anndata containing phenotyping info.
34 masks : str 35 masks : str
35 File path to the image masks. 36 File path to the image masks.
37 config_path : str
38 File path to the config file containing galaxy_url and dataset_id.
36 """ 39 """
37 warnings.simplefilter('ignore') 40 warnings.simplefilter('ignore')
38 41
39 with open(inputs, 'r') as param_handler: 42 with open(inputs, 'r') as param_handler:
40 params = json.load(param_handler) 43 params = json.load(param_handler)
44
45 with open(config_path) as conf_fh:
46 config = json.load(conf_fh)
47
48 galaxy_url = config["galaxy_url"]
49 dataset_id = config["dataset_id"]
41 50
42 # initialize vitessce config and add OME-TIFF image, and masks if specified 51 # initialize vitessce config and add OME-TIFF image, and masks if specified
43 vc = VitessceConfig(schema_version="1.0.17", name=None, description=None) 52 vc = VitessceConfig(schema_version="1.0.17", name=None, description=None)
44 dataset = vc.add_dataset() 53 dataset = vc.add_dataset()
45 54
71 view_type=cm.LAYER_CONTROLLER, 80 view_type=cm.LAYER_CONTROLLER,
72 dataset=dataset, 81 dataset=dataset,
73 w=lc_dims[0], 82 w=lc_dims[0],
74 h=lc_dims[1]) 83 h=lc_dims[1])
75 84
85 # Build the prefix that Vitessce should use
86 display_prefix = (f"{galaxy_url}/api/datasets/{dataset_id}/display?filename=")
87
76 # if no anndata file, export the config with these minimal components 88 # if no anndata file, export the config with these minimal components
77 if not anndata: 89 if not anndata:
78 vc.layout(lc | spatial) 90 vc.layout(lc | spatial)
79 config_dict = vc.export( 91 config_dict = vc.export(
80 to='files', 92 to='files',
81 base_url='http://localhost', 93 base_url=display_prefix,
82 out_dir=output) 94 out_dir=output)
83 with open(Path(output).joinpath('config.json'), 'w') as f: 95 with open(Path(output).joinpath('config.json'), 'w') as f:
84 json.dump(config_dict, f, indent=4) 96 json.dump(config_dict, f, indent=4)
85 return 97 return
86 98
189 ) 201 )
190 202
191 # export the config file 203 # export the config file
192 config_dict = vc.export( 204 config_dict = vc.export(
193 to='files', 205 to='files',
194 base_url='http://localhost', 206 base_url=display_prefix,
195 out_dir=output) 207 out_dir=output)
196 208
197 with open(Path(output).joinpath('config.json'), 'w') as f: 209 with open(Path(output).joinpath('config.json'), 'w') as f:
198 json.dump(config_dict, f, indent=4) 210 json.dump(config_dict, f, indent=4)
199 211
204 aparser.add_argument("-e", "--output", dest="output", required=True) 216 aparser.add_argument("-e", "--output", dest="output", required=True)
205 aparser.add_argument("-g", "--image", dest="image", required=True) 217 aparser.add_argument("-g", "--image", dest="image", required=True)
206 aparser.add_argument("-f", "--offsets", dest="offsets", required=False) 218 aparser.add_argument("-f", "--offsets", dest="offsets", required=False)
207 aparser.add_argument("-a", "--anndata", dest="anndata", required=False) 219 aparser.add_argument("-a", "--anndata", dest="anndata", required=False)
208 aparser.add_argument("-m", "--masks", dest="masks", required=False) 220 aparser.add_argument("-m", "--masks", dest="masks", required=False)
221 aparser.add_argument("--galaxy_config", dest="config_path", required=True)
209 222
210 args = aparser.parse_args() 223 args = aparser.parse_args()
211 224
212 main(args.inputs, args.output, args.image, args.offsets, args.anndata, args.masks) 225 main(args.inputs, args.output, args.image, args.offsets, args.anndata, args.masks, args.config_path)