# HG changeset patch
# User goeckslab
# Date 1720736561 0
# Node ID 5b17a47d1adeeff364ffb77817b12f1735606ad0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/squidpy commit 721eaced787aa3b04d96ad91f6b4540f26b23949
diff -r 000000000000 -r 5b17a47d1ade main_macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main_macros.xml Thu Jul 11 22:22:41 2024 +0000
@@ -0,0 +1,64 @@
+
+ 1.5.0
+ 20.01
+ 1
+
+
+
+
+
+
+
+
+
+ squidpy
+
+
+
+
+
+ 10.1038/s41592-021-01358-2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 000000000000 -r 5b17a47d1ade squidpy_scatter.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/squidpy_scatter.py Thu Jul 11 22:22:41 2024 +0000
@@ -0,0 +1,87 @@
+import argparse
+import ast
+import json
+import warnings
+
+import squidpy as sq
+from anndata import read_h5ad
+
+
+def main(inputs, output_plot):
+
+ """
+ inputs : str
+ File path to galaxy tool JSON inputs config file
+ output_plot: str
+ File path to save the plotting image
+ """
+ warnings.simplefilter('ignore')
+
+ # read inputs JSON
+ with open(inputs, 'r') as param_handler:
+ params = json.load(param_handler)
+
+ # collapse param dict hierarchy, parse inputs
+ plot_opts = params.pop('plot_opts')
+ legend_opts = params.pop('legend_opts')
+ aes_opts = params.pop('aesthetic_opts')
+ options = {**params, **plot_opts, **legend_opts, **aes_opts}
+
+ # read input anndata file
+ adata_fh = options.pop('anndata')
+ adata = read_h5ad(adata_fh)
+
+ # ensure spatial coords in anndata.obsm['spatial']
+ # if not, populate with user provided X/Y coord column names
+ x, y = options.pop('x_coord'), options.pop('y_coord')
+ if 'spatial' not in adata.obsm:
+ try:
+ adata.obsm['spatial'] = adata.obs[[x, y]].values
+ except Exception as e:
+ print(e)
+
+ # scan thru tool params,
+ # replace None values, and reformat specific parameters
+ for k, v in options.items():
+ if not isinstance(v, str):
+ continue
+
+ if v in ('', 'none'):
+ options[k] = None
+ continue
+
+ if k == 'groups':
+ options[k] = [e.strip() for e in v.split(',')]
+
+ elif k == 'crop_coord':
+ # split str on commas into tuple of coords
+ # then nest in list (expected by squidpy function)
+ options[k] = [tuple([int(e.strip()) for e in v.split(',')])]
+
+ elif k == 'figsize':
+ options[k] = ast.literal_eval(v)
+
+ # not exposing this parameter for now. Only useful to change for ST data
+ # and can otherwise just be problematic.
+ # Explicitly setting to None is necessary to avoid an error
+ options['shape'] = None
+
+ # call squidpy spatial scatter function, unpack tool params
+ sq.pl.spatial_scatter(
+ adata=adata,
+ save='image.png',
+ **options
+ )
+
+
+if __name__ == '__main__':
+
+ aparser = argparse.ArgumentParser()
+ aparser.add_argument(
+ "-i", "--inputs", dest="inputs", required=True)
+ aparser.add_argument(
+ "-p", "--output_plot", dest="output_plot", required=False)
+
+ args = aparser.parse_args()
+
+ main(args.inputs, args.output_plot)
diff -r 000000000000 -r 5b17a47d1ade squidpy_spatial.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/squidpy_spatial.py Thu Jul 11 22:22:41 2024 +0000
@@ -0,0 +1,105 @@
+import argparse
+import ast
+import json
+import warnings
+
+import pandas as pd
+import squidpy as sq
+from anndata import read_h5ad
+
+
+def main(inputs, anndata, output, output_plot):
+ """
+ Parameter
+ ---------
+ inputs : str
+ File path to galaxy tool parameter.
+ anndata : str
+ File path to anndata containing phenotyping info.
+ output : str
+ File path to output.
+ output_plot: str or None
+ File path to save the plotting image.
+ """
+ warnings.simplefilter('ignore')
+
+ with open(inputs, 'r') as param_handler:
+ params = json.load(param_handler)
+
+ adata = read_h5ad(anndata)
+
+ if 'spatial' not in adata.obsm:
+ try:
+ adata.obsm['spatial'] = adata.obs[['X_centroid', 'Y_centroid']].values
+ except Exception as e:
+ print(e)
+
+ tool = params['analyses']['selected_tool']
+ tool_func = getattr(sq.gr, tool)
+
+ options = params['analyses']['options']
+
+ for k, v in options.items():
+ if not isinstance(v, str):
+ continue
+
+ if v in ('', 'none'):
+ options[k] = None
+ continue
+
+ if k == 'genes': # for spatial_autocorr and sepal
+ options[k] = [e.strip() for e in v.split(',')]
+ elif k == 'radius': # for spatial_neighbors
+ options[k] = ast.literal_eval(v)
+ elif k == 'interactions': # for ligrec
+ options[k] = pd.read_csv(v, sep="\t")
+ elif k == 'max_neighs':
+ options[k] = int(v) # for sepal
+
+ cluster_key = params['analyses'].get('cluster_key')
+ if cluster_key:
+ tool_func(adata, cluster_key, **options)
+ else:
+ tool_func(adata, **options)
+
+ if output_plot:
+ plotting_options = params['analyses']['plotting_options']
+ for k, v in plotting_options.items():
+ if not isinstance(v, str):
+ continue
+
+ if v in ('', 'none'):
+ plotting_options[k] = None
+ continue
+
+ if k == 'figsize':
+ options[k] = ast.literal_eval(v)
+ elif k in ('palette', 'score', 'source_groups', 'target_groups'):
+ options[k] = [e.strip() for e in v.split(',')]
+ elif k == 'means_range': # ligrec
+ v = v.strip()
+ if v[0] == '(':
+ v = v[1:]
+ if v[-1] == ')':
+ v = v[:-1]
+ options[k] = tuple([float(e.strip()) for e in v.split(',', 1)])
+
+ plotting_func = getattr(sq.pl, tool)
+ if cluster_key:
+ plotting_func(adata, cluster_key, save=output_plot, **plotting_options)
+ else: # TODO Remove this, since all plottings need cluster key
+ plotting_func(adata, save=output_plot, **plotting_options)
+
+ adata.write(output)
+
+
+if __name__ == '__main__':
+ aparser = argparse.ArgumentParser()
+ aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
+ aparser.add_argument("-e", "--output", dest="output", required=True)
+ aparser.add_argument("-a", "--anndata", dest="anndata", required=True)
+ aparser.add_argument("-p", "--output_plot", dest="output_plot", required=False)
+
+ args = aparser.parse_args()
+
+ main(args.inputs, args.anndata, args.output, args.output_plot)
diff -r 000000000000 -r 5b17a47d1ade squidpy_spatial.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/squidpy_spatial.xml Thu Jul 11 22:22:41 2024 +0000
@@ -0,0 +1,338 @@
+
+ with Squidpy
+
+ main_macros.xml
+
+
+ operation_3443
+
+
+
+ echo "@TOOL_VERSION@"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ analyses['selected_tool'] in ['nhood_enrichment', 'centrality_scores', 'interaction_matrix', 'ligrec', 'ripley', 'co_occurrence']
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 000000000000 -r 5b17a47d1ade test-data/imc.h5ad
Binary file test-data/imc.h5ad has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_centrality_scores.png
Binary file test-data/imc_centrality_scores.png has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_co_occurrence.png
Binary file test-data/imc_co_occurrence.png has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_interaction_matrix.png
Binary file test-data/imc_interaction_matrix.png has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_kmeans.h5ad
Binary file test-data/imc_kmeans.h5ad has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_nhood_enrichment.png
Binary file test-data/imc_nhood_enrichment.png has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_ripley.png
Binary file test-data/imc_ripley.png has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/imc_sn.h5ad
Binary file test-data/imc_sn.h5ad has changed
diff -r 000000000000 -r 5b17a47d1ade test-data/scatter_image.png
Binary file test-data/scatter_image.png has changed