Skip to content

Commit 8e0168d

Browse files
authored
Merge pull request #6946 from nilchia/bellavista_prepare
add bellavista prepare
2 parents 607e1d0 + 6c9ac97 commit 8e0168d

File tree

4 files changed

+376
-0
lines changed

4 files changed

+376
-0
lines changed

tools/bellavista/.shed.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: bellavista
2+
owner: iuc
3+
description: Open-Source Visualization for Imaging-Based Spatial Transcriptomics
4+
homepage_url: https://github.com/pkosurilab/BellaVista
5+
long_description: |
6+
BellaVista is an open-source Python package developed for 10x Genomics Xenium, Vizgen MERSCOPE, and custom (home-built) MERFISH datasets utilizing napari for interactive data exploration.
7+
remote_repository_url: https://github.com/galaxyproject/tools-iuc/tree/master/tools/bellavista
8+
type: unrestricted
9+
categories:
10+
- Single Cell
11+
- Spatial Omics
12+
- Transcriptomics
13+
- Imaging
14+
auto_tool_repositories:
15+
name_template: "{{ tool_id }}"
16+
description_template: "Wrapper for {{ tool_name }}."

tools/bellavista/bellavista.bash

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/bash
2+
3+
# turn off visualization
4+
sed -i 's/"plot_image": true,/"plot_image": false,/g' config.json
5+
sed -i 's/"plot_transcripts": true,/"plot_transcripts": false,/g' config.json
6+
sed -i 's/"plot_cell_seg": true,/"plot_cell_seg": false,/g' config.json
7+
sed -i 's/"plot_nuclear_seg": true,/"plot_nuclear_seg": false,/g' config.json
8+
sed -i 's/"plot_allgenes": true,/"plot_allgenes": false,/g' config.json
9+
10+
# start time
11+
START_TIME=$(date +%s)
12+
13+
echo "Time limit set to ${TIME_LIMIT_SECONDS} seconds"
14+
15+
touch './bellavista.log'
16+
/opt/bellavista/bellavista/bin/bellavista "./config.json" 2>&1 | tee './bellavista.log' &
17+
TOOL_PID=$!
18+
19+
# function to handle complete cleanup
20+
cleanup() {
21+
# Kill all processes
22+
pkill -P $TOOL_PID 2>/dev/null || true
23+
kill -9 $TOOL_PID 2>/dev/null || true
24+
25+
# Make sure any background processes from this script are terminated
26+
jobs -p | xargs -r kill -9 2>/dev/null || true
27+
28+
echo "Bella Vista stopped."
29+
exit 0
30+
}
31+
32+
# Set trap to ensure cleanup on script exit
33+
trap cleanup EXIT INT TERM
34+
35+
while sleep 1; do
36+
# Check if the job is finished
37+
if grep -q "Bella Vista input files created!" './bellavista.log' && \
38+
[ -d "./BellaVista_output/OMEzarrImages" ] && \
39+
[ -f "./BellaVista_output/OMEzarrImages/.zgroup" ]; then
40+
echo "Bella Vista input files created! Stopping the tool..."
41+
kill -INT $TOOL_PID
42+
sleep 1
43+
# If still running, use stronger signal
44+
if ps -p $TOOL_PID > /dev/null; then
45+
kill -9 $TOOL_PID
46+
fi
47+
break
48+
elif grep -q "Bella Vista input files created!" './bellavista.log'; then
49+
echo "Log indicates completion but output directory structure is incomplete. Continuing..."
50+
fi
51+
52+
# Check timeout
53+
CURRENT_TIME=$(date +%s)
54+
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
55+
56+
if [[ "$ELAPSED_TIME" =~ ^[0-9]+$ ]] && [[ "$TIME_LIMIT_SECONDS" =~ ^[0-9]+$ ]]; then
57+
if [ $ELAPSED_TIME -ge $TIME_LIMIT_SECONDS ]; then
58+
echo "Time limit of ${TIME_LIMIT_SECONDS} seconds reached. Please contact admins. Stopping the tool..."
59+
kill -INT $TOOL_PID
60+
sleep 1
61+
# If still running, use SIGKILL (force quit)
62+
if ps -p $TOOL_PID > /dev/null; then
63+
kill -9 $TOOL_PID
64+
fi
65+
break
66+
fi
67+
fi
68+
done
69+
70+
# Final cleanup
71+
cleanup
72+
73+
# check this line in test. It should not be printed
74+
echo "Script completed."
+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<tool id="bellavista_prepare" name="Bellavista" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@">
2+
<description>Prepare large images for bellavista visualizer</description>
3+
<creator>
4+
<organization name="European Galaxy Team" url="https://galaxyproject.org/eu/" />
5+
<person givenName="Amirhossein" familyName="Naghsh Nilchi" email="[email protected]" />
6+
<person givenName="Pavan" familyName="Videm" email="[email protected]" />
7+
<person givenName="Björn" familyName="Grüning" email="[email protected]" />
8+
</creator>
9+
<macros>
10+
<import>macros.xml</import>
11+
</macros>
12+
<expand macro="requirements"/>
13+
<command detect_errors="exit_code"><![CDATA[
14+
export TIME_LIMIT_SECONDS=$timeout &&
15+
export BELLAVISTA_DIR=`pwd`/input/ &&
16+
mkdir -p 'input' 'input/BellaVista_output' &&
17+
chmod -R 777 'input/' &&
18+
#if $technology_conditional.plot_genes.plot_transcripts == "true":
19+
ln -s '$technology_conditional.plot_genes.transcript_filename' './input/${technology_conditional.plot_genes.transcript_filename.element_identifier}.${technology_conditional.plot_genes.transcript_filename.ext}' &&
20+
#end if
21+
#for $image in $technology_conditional.images:
22+
ln -s '$image' 'input/${image.element_identifier}.${image.ext}' &&
23+
#end for
24+
ln -s '$bellavista_config_file' './input/config.json' &&
25+
#if $technology_conditional.plot_cell_segmentation.plot_cell_seg == "true":
26+
ln -s '$technology_conditional.plot_cell_segmentation.cell_segmentation' './input/${technology_conditional.plot_cell_segmentation.cell_segmentation.element_identifier}.${technology_conditional.plot_cell_segmentation.cell_segmentation.ext}' &&
27+
#end if
28+
#if $technology_conditional.plot_nuclear_segmentation.plot_nuclear_seg == "true":
29+
ln -s '$technology_conditional.plot_nuclear_segmentation.nuclear_segmentation' './input/${technology_conditional.plot_nuclear_segmentation.nuclear_segmentation.element_identifier}.${technology_conditional.plot_nuclear_segmentation.nuclear_segmentation.ext}' &&
30+
#end if
31+
#if $technology_conditional.technology == "MERSCOPE":
32+
ln -s '$technology_conditional.um_to_px_transform' './input/micron_to_mosaic_pixel_transform.csv' &&
33+
#end if
34+
cat ./input/config.json &&
35+
36+
cd "\$BELLAVISTA_DIR" &&
37+
bash '$__tool_directory__/bellavista.bash' &&
38+
cd .. &&
39+
40+
tar -czf 'bellavista.tar.gz' 'input/BellaVista_output'
41+
]]></command>
42+
<configfiles>
43+
<configfile name="bellavista_config_file"><![CDATA[
44+
{
45+
"system": "$technology",
46+
"data_folder": "./",
47+
"create_bellavista_inputs": true,
48+
49+
"visualization_parameters": {
50+
"plot_image": true,
51+
#if $technology_conditional.plot_genes.plot_transcripts == "true":
52+
"plot_transcripts": true,
53+
#else
54+
"plot_transcripts": false,
55+
#end if
56+
#if $technology_conditional.plot_cell_segmentation.plot_cell_seg == "true":
57+
"plot_cell_seg": true,
58+
#else
59+
"plot_cell_seg": false,
60+
#end if
61+
#if $technology_conditional.plot_nuclear_segmentation.plot_nuclear_seg == "true":
62+
"plot_nuclear_seg": true,
63+
#else
64+
"plot_nuclear_seg": false,
65+
#end if
66+
"genes_visible_on_startup": false,
67+
#if $technology_conditional.plot_genes.plot_all_genes.all_genes == "Yes":
68+
"plot_allgenes": true,
69+
#else
70+
"plot_allgenes": false,
71+
#set $gene_list = ['"' + str(x.strip()) + '"' for x in str($technology_conditional.plot_genes.plot_all_genes.selected_genes).split(',')]
72+
#set $genes = ','.join($gene_list)
73+
"selected_genes": $genes,
74+
#end if
75+
"rotate_angle": $rotate_angle,
76+
"transcript_point_size": $transcript_point_size
77+
},
78+
79+
"input_files": {
80+
#set $last_index = len($technology_conditional.images) - 1
81+
"images": [
82+
#for $i in range(len($images)):
83+
"$images[$i].element_identifier.$images[$i].ext"#if $i != $last_index#,#end if
84+
#end for
85+
],
86+
#if $technology_conditional.plot_cell_segmentation.plot_cell_seg == "true":
87+
"cell_segmentation": "${technology_conditional.plot_cell_segmentation.cell_segmentation.element_identifier}.${technology_conditional.plot_cell_segmentation.cell_segmentation.ext}",
88+
#end if
89+
#if $technology_conditional.plot_nuclear_segmentation.plot_nuclear_seg == "true":
90+
"nuclear_segmentation": "${technology_conditional.plot_nuclear_segmentation.nuclear_segmentation.element_identifier}.${technology_conditional.plot_nuclear_segmentation.nuclear_segmentation.ext}",
91+
#end if
92+
#if $technology_conditional.technology == "MERSCOPE":
93+
"um_to_px_transform": "micron_to_mosaic_pixel_transform.csv",
94+
#end if
95+
#if $technology_conditional.plot_genes.plot_transcripts == "true":
96+
"transcript_filename": "${technology_conditional.plot_genes.transcript_filename.element_identifier}.${technology_conditional.plot_genes.transcript_filename.ext}",
97+
#end if
98+
"z_plane": $technology_conditional.z_plane
99+
}
100+
}
101+
]]></configfile>
102+
</configfiles>
103+
<inputs>
104+
<conditional name="technology_conditional">
105+
<param name="technology" type="select" label="Spatial transcriptomic technology">
106+
<option value="Xenium">Xenium</option>
107+
<option value="MERSCOPE" selected="true">MERSCOPE</option>
108+
</param>
109+
<when value="Xenium">
110+
<expand macro="common_param"/>
111+
</when>
112+
<when value="MERSCOPE">
113+
<expand macro="common_param">
114+
<param name="um_to_px_transform" type="data" format="csv" optional="false" label="micron to pixel transformations"/>
115+
</expand>
116+
</when>
117+
</conditional>
118+
<section name="advanced_output" title="Advanced output options">
119+
<param name="config" type="boolean" truevalue="True" falsevalue="False" checked="true" label="Output config file?"/>
120+
</section>
121+
<param name="timeout" type="hidden" min="0" max="21600" value="3600" label="timeout" help="hidden input to set timeout in seconds" />
122+
</inputs>
123+
<outputs>
124+
<data name="bellavista_output" format="tar.gz" label="${tool.name} on ${on_string}: Bellavista prepared inputs" from_work_dir="./bellavista.tar.gz" />
125+
<data name="config" format="json" label="${tool.name} on ${on_string}: config file" from_work_dir="input/config.json">
126+
<filter>advanced_output['config']</filter>
127+
</data>
128+
</outputs>
129+
<tests>
130+
<test expect_num_outputs="2">
131+
<conditional name="technology_conditional">
132+
<param name="technology" value="MERSCOPE"/>
133+
<param name="images" location="https://zenodo.org/records/15319018/files/mosaic_PolyT_z3.tif,https://zenodo.org/records/15319018/files/mosaic_PolyT_z4.tif"/>
134+
<conditional name="plot_genes">
135+
<param name="plot_transcripts" value="true"/>
136+
<param name="transcript_filename" location="https://zenodo.org/records/15319018/files/detected_transcripts.csv"/>
137+
</conditional>
138+
<conditional name="plot_cell_segmentation">
139+
<param name="plot_cell_seg" value="false"/>
140+
</conditional>
141+
<conditional name="plot_nuclear_segmentation">
142+
<param name="plot_nuclear_seg" value="false"/>
143+
</conditional>
144+
<param name="um_to_px_transform" location="https://zenodo.org/records/15319018/files/micron_to_mosaic_pixel_transform.csv"/>
145+
<param name="z_plane" value="3"/>
146+
<param name="transcript_point_size" value="1"/>
147+
<param name="rotate_angle" value="0"/>
148+
</conditional>
149+
<section name="advanced_output">
150+
<param name="config" value="true"/>
151+
</section>
152+
<output name="bellavista_output">
153+
<assert_contents>
154+
<has_archive_member path="input/BellaVista_output/gene_dict.pkl"/>
155+
<has_archive_member path="input/BellaVista_output/OMEzarrImages"/>
156+
<has_archive_member path="input/BellaVista_output/um_to_px_transforms.pkl"/>
157+
</assert_contents>
158+
</output>
159+
<output name="config">
160+
<assert_contents>
161+
<has_text text="MERSCOPE"/>
162+
<has_text text="&quot;create_bellavista_inputs&quot;: true"/>
163+
<has_text text="&quot;plot_cell_seg&quot;: false"/>
164+
</assert_contents>
165+
</output>
166+
<assert_stdout>
167+
<has_text text="Creating Bella Vista input files for Vizgen MERSCOPE"/>
168+
<has_text text="Bella Vista input files created!"/>
169+
<not_has_text text="Script completed."/>
170+
</assert_stdout>
171+
</test>
172+
<test expect_num_outputs="0">
173+
<conditional name="technology_conditional">
174+
<param name="technology" value="MERSCOPE"/>
175+
<param name="images" location="https://zenodo.org/records/15319018/files/mosaic_PolyT_z3.tif,https://zenodo.org/records/15319018/files/mosaic_PolyT_z4.tif"/>
176+
<conditional name="plot_genes">
177+
<param name="plot_transcripts" value="true"/>
178+
<param name="transcript_filename" location="https://zenodo.org/records/15319018/files/detected_transcripts.csv"/>
179+
</conditional>
180+
<conditional name="plot_cell_segmentation">
181+
<param name="plot_cell_seg" value="false"/>
182+
</conditional>
183+
<conditional name="plot_nuclear_segmentation">
184+
<param name="plot_nuclear_seg" value="false"/>
185+
</conditional>
186+
<param name="um_to_px_transform" location="https://zenodo.org/records/15319018/files/micron_to_mosaic_pixel_transform.csv"/>
187+
<param name="z_plane" value="3"/>
188+
<param name="transcript_point_size" value="1"/>
189+
<param name="rotate_angle" value="0"/>
190+
</conditional>
191+
<section name="advanced_output">
192+
<param name="config" value="true"/>
193+
</section>
194+
<param name="timeout" value="1"/>
195+
<assert_stdout>
196+
<has_text text="Time limit of 1 seconds reached. Please contact admins. Stopping the tool..."/>
197+
<has_text text="Bella Vista stopped"/>
198+
<not_has_text text="Script completed."/>
199+
</assert_stdout>
200+
</test>
201+
</tests>
202+
<help><![CDATA[
203+
BellaVista is an open-source visualization tool for imaging-based spatial transcriptomics data. It allows users to visualize and explore spatial transcriptomics data in a user-friendly interface. The tool supports MERSCOPE and Xenium imaging-based spatial transcriptomics technologies.
204+
205+
Users can customize the visualization by selecting specific genes, adjusting image rotation angles, and controlling the size of transcript points. BellaVista also provides options for plotting cell and nuclear segmentation, enhancing the exploration of spatial transcriptomics data.
206+
207+
.. image:: https://raw.githubusercontent.com/pkosurilab/BellaVista/c8129bb8954c92962a87606595c09b35cc414295/images/bellavista_figure.png
208+
:height: 500
209+
:width: 700
210+
]]>
211+
</help>
212+
<expand macro="citations"/>
213+
</tool>

tools/bellavista/macros.xml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<macros>
2+
<token name="@TOOL_VERSION@">0.0.2</token>
3+
<token name="@VERSION_SUFFIX@">0</token>
4+
<token name="@PROFILE@">23.0</token>
5+
<xml name="requirements">
6+
<requirements>
7+
<container type="docker">quay.io/bgruening/bellavista:0.0.2-3</container>
8+
<yield/>
9+
</requirements>
10+
</xml>
11+
<xml name="common_param">
12+
<param name="images" type="data" format="tiff,ome.tiff" multiple="true" optional="false" label="Images"/>
13+
<conditional name="plot_genes">
14+
<param name="plot_transcripts" type="select" label="Plot transcripts?">
15+
<option value="false">No</option>
16+
<option value="true" selected="true">Yes</option>
17+
</param>
18+
<when value="false"></when>
19+
<when value="true">
20+
<param name="transcript_filename" type="data" format="csv,parquet" optional="false" label="transcript spatial locations"/>
21+
<conditional name="plot_all_genes">
22+
<param name="all_genes" type="select" label="Plot all genes?">
23+
<option value="Yes" selected="true">Yes</option>
24+
<option value="No">No</option>
25+
</param>
26+
<when value="Yes"/>
27+
<when value="No">
28+
<param name="selected_genes" type="text" optional="false" value="" label="Comma separated list of custom genes">
29+
<sanitizer>
30+
<valid initial="string.printable">
31+
<remove value="&apos;"/>
32+
</valid>
33+
</sanitizer>
34+
</param>
35+
</when>
36+
</conditional>
37+
</when>
38+
</conditional>
39+
<conditional name="plot_cell_segmentation">
40+
<param name="plot_cell_seg" type="select" label="Plot cell segmentation?">
41+
<option value="false">No</option>
42+
<option value="true" selected="true">Yes</option>
43+
</param>
44+
<when value="false"></when>
45+
<when value="true">
46+
<param name="cell_segmentation" type="data" format="parquet,zarr" optional="false" label="Cell segmentations"/>
47+
</when>
48+
</conditional>
49+
<conditional name="plot_nuclear_segmentation">
50+
<param name="plot_nuclear_seg" type="select" label="Plot nuclear segmentation?">
51+
<option value="false" selected="true">No</option>
52+
<option value="true">Yes</option>
53+
</param>
54+
<when value="false"></when>
55+
<when value="true">
56+
<param name="nuclear_segmentation" type="data" format="parquet,zarr" optional="false" label="Nuclear segmentations"/>
57+
</when>
58+
</conditional>
59+
<yield />
60+
<param name="z_plane" type="integer" min="0" value="0" label="z-plane of image to be visualize"/>
61+
<param name="transcript_point_size" type="integer" min="0" value="1" label="Size of the points representing individual transcripts"/>
62+
<param name="rotate_angle" type="integer" min="-180" max="180" value="0" label="Image rotation angle in degrees"/>
63+
</xml>
64+
<xml name="citations">
65+
<citations>
66+
<citation type="doi">10.1016/j.bpj.2024.11.3199</citation>
67+
<citation type="bibtex">@Manual{github,
68+
title = {Open-source Visualization for Imaging-Based Spatial Transcriptomics},
69+
url = {https://github.com/pkosurilab/BellaVista}}
70+
</citation>
71+
</citations>
72+
</xml>
73+
</macros>

0 commit comments

Comments
 (0)