Skip to content

Commit 9e5fea4

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents df8ca91 + 656ebf4 commit 9e5fea4

12 files changed

Lines changed: 70 additions & 34 deletions

File tree

docker/spatial_py/build.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Tool versions
2-
SPATIAL_PY_VERSION=1.0.0
2+
SPATIAL_PY_VERSION=1.0.1
33
GCLOUD_CLI_VERSION=524.0.0-slim
44
PYTHON3_VERSION=3.12.5
55

docker/spatial_py/scripts/cluster

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ def main(args):
1414
##########################
1515
adata = sc.read_h5ad(args.adata_input)
1616

17+
n_comps = args.n_comps
18+
if adata.n_obs < n_comps or adata.n_vars < n_comps:
19+
n_comps = min(n_comps, adata.n_obs - 1, adata.n_vars - 1)
20+
print(f"[INFO] Detected small dimensions (n_obs={adata.n_obs}, n_vars={adata.n_vars}). Setting n_comps={n_comps}.")
21+
else:
22+
print(f"[INFO] Computing the nearest neighbors distance matrix with default settings (n={n_comps}).")
23+
1724
sc.pp.neighbors(
1825
adata,
19-
n_pcs=args.n_comps,
26+
n_pcs=n_comps,
2027
)
2128
sc.tl.umap(adata)
2229

docker/spatial_py/scripts/visium_plot_spatial

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def main(args):
1515
colors = ["total_counts", "n_genes_by_counts", "batch", "leiden"]
1616
titles = [f"{slide} - {color}" for slide in slides for color in colors]
1717

18+
# Clean up
19+
present_slides = adata.obs["visium_slide_ref"].unique()
20+
all_slides = list(adata.uns["spatial"].keys())
21+
for slide in all_slides:
22+
if slide not in present_slides:
23+
del adata.uns["spatial"][slide]
24+
1825
sq.pl.spatial_scatter(
1926
adata,
2027
library_key="visium_slide_ref",

docker/spatial_py/scripts/visium_process

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ def main(args):
7272
##############################
7373
## DIMENSIONALITY REDUCTION ##
7474
##############################
75+
n_comps = args.n_comps
76+
if hvg_adata.n_obs < n_comps or hvg_adata.n_vars < n_comps:
77+
n_comps = min(n_comps, hvg_adata.n_obs - 1, hvg_adata.n_vars - 1)
78+
print(f"[INFO] Detected small dimensions (n_obs={hvg_adata.n_obs}, n_vars={hvg_adata.n_vars}). Setting n_comps={n_comps}.")
79+
print(f"[WARNING] PCA might not be meaningful since dataset is small (e.g., <30 cells) or check filters.")
80+
else:
81+
print(f"[INFO] Running PCA with default settings (n={n_comps}).")
82+
7583
sc.pp.pca(
7684
hvg_adata,
77-
n_comps=args.n_comps,
85+
n_comps=n_comps,
7886
svd_solver="arpack",
7987
)
8088

docker/spatial_py/scripts/visium_spatially_variable_genes

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,42 @@ def main(args):
1515
adata = sc.read_h5ad(args.adata_input)
1616

1717
genes = adata.var_names[adata.var["highly_variable"]].tolist()
18+
19+
# Check spots per slide
20+
spots_per_slide = adata.obs["visium_slide_ref"].value_counts()
21+
print("Spots per slide:")
22+
print(spots_per_slide)
23+
slides_to_keep = spots_per_slide[spots_per_slide >= 4].index.tolist()
24+
adata_filtered = adata[adata.obs["visium_slide_ref"].isin(slides_to_keep)].copy()
25+
1826
sq.gr.spatial_neighbors(
19-
adata,
27+
adata_filtered,
2028
library_key="visium_slide_ref",
2129
coord_type="generic",
2230
delaunay=True,
2331
)
2432
sq.gr.spatial_autocorr(
25-
adata,
33+
adata_filtered,
2634
mode="moran",
2735
genes=genes,
2836
n_perms=100,
2937
n_jobs=1,
3038
)
31-
top_10_variable_genes = adata.uns["moranI"].head(10)
39+
top_10_variable_genes = adata_filtered.uns["moranI"].head(10)
3240

33-
top_4_variable_gene_list = adata.uns["moranI"].head(4).index.tolist()
34-
slides = adata.obs["visium_slide_ref"].unique().tolist()
41+
top_4_variable_gene_list = adata_filtered.uns["moranI"].head(4).index.tolist()
42+
slides = adata_filtered.obs["visium_slide_ref"].unique().tolist()
3543
titles = [f"{slide} - {color}" for slide in slides for color in top_4_variable_gene_list]
44+
45+
# Clean up
46+
present_slides = adata_filtered.obs["visium_slide_ref"].unique()
47+
all_slides = list(adata_filtered.uns["spatial"].keys())
48+
for slide in all_slides:
49+
if slide not in present_slides:
50+
del adata_filtered.uns["spatial"][slide]
51+
3652
sq.pl.spatial_scatter(
37-
adata,
53+
adata_filtered,
3854
library_key="visium_slide_ref",
3955
color=top_4_variable_gene_list,
4056
title=titles,
@@ -43,9 +59,9 @@ def main(args):
4359

4460
# Save table and adata object
4561
top_10_variable_genes.to_csv(f"{args.cohort_id}.moran_top_10_variable_genes.csv")
46-
metadata = adata.obs
62+
metadata = adata_filtered.obs
4763
metadata.to_csv(f"{args.cohort_id}.final_metadata.csv")
48-
adata.write_h5ad(filename=args.adata_output, compression="gzip")
64+
adata_filtered.write_h5ad(filename=args.adata_output, compression="gzip")
4965

5066

5167
if __name__ == "__main__":

wdl-ci.config.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
"tasks": {
263263
"integrate_sample_data": {
264264
"key": "integrate_sample_data",
265-
"digest": "qjngtpgf2tzriftjt4hfwgo2i2z2uucg",
265+
"digest": "hcdomqajbz6ntwc6xeqrsb65q4end4hn",
266266
"tests": [
267267
{
268268
"inputs": {
@@ -276,8 +276,7 @@
276276
"integrated_adata_object": {
277277
"value": "${geomx_input_file_path}/${cohort_analysis_workflow_name}/${geomx_team_id}.harmony_integrated.h5ad",
278278
"test_tasks": [
279-
"compare_file_basename",
280-
"check_hdf5"
279+
"compare_file_basename"
281280
]
282281
}
283282
}
@@ -286,7 +285,7 @@
286285
},
287286
"cluster": {
288287
"key": "cluster",
289-
"digest": "ibhtiot7sakpfyfuuvpxnqiqmsgzh4hj",
288+
"digest": "frghkwauyalgin75nkrjs466t4vep5uk",
290289
"tests": [
291290
{
292291
"inputs": {
@@ -304,8 +303,7 @@
304303
"clustered_adata_object": {
305304
"value": "${geomx_input_file_path}/${cohort_analysis_workflow_name}/${geomx_team_id}.clustered.h5ad",
306305
"test_tasks": [
307-
"compare_file_basename",
308-
"check_hdf5"
306+
"compare_file_basename"
309307
]
310308
},
311309
"umap_cluster_plots_png": {
@@ -329,7 +327,7 @@
329327
"tasks": {
330328
"merge_and_plot_qc_metrics": {
331329
"key": "merge_and_plot_qc_metrics",
332-
"digest": "tfku5xa5owqltkkjxr2ibq36iw5fh6hx",
330+
"digest": "6e55pxc6kpkxuyqrthug5cy4xgpirqta",
333331
"tests": [
334332
{
335333
"inputs": {
@@ -369,7 +367,7 @@
369367
},
370368
"filter_and_normalize": {
371369
"key": "filter_and_normalize",
372-
"digest": "526uk3dkuil6gmxfyxiltlyvegxbxpki",
370+
"digest": "sfml3i63wsmbm4jtgvfjn32lrchcesaw",
373371
"tests": [
374372
{
375373
"inputs": {
@@ -429,7 +427,7 @@
429427
},
430428
"plot_spatial": {
431429
"key": "plot_spatial",
432-
"digest": "ufcwh7kuftyt6nu74cyoawgjvro7lsfv",
430+
"digest": "3pfo5jdbiyz42mvxy6geg4gd7ednbjy3",
433431
"tests": [
434432
{
435433
"inputs": {
@@ -463,7 +461,7 @@
463461
"tasks": {
464462
"spatially_variable_gene_analysis": {
465463
"key": "spatially_variable_gene_analysis",
466-
"digest": "in5bndajrnrb4kupxqv7xydhlqpnmghy",
464+
"digest": "ysgd246bcuttozfizskpva2frc2tnml2",
467465
"tests": [
468466
{
469467
"inputs": {
@@ -627,7 +625,7 @@
627625
},
628626
"counts_to_adata": {
629627
"key": "counts_to_adata",
630-
"digest": "zh45hobarbnoa2z2b6d3i66fdyneqj3w",
628+
"digest": "srukdp6rz3im6dzlcn365i36tv3422yp",
631629
"tests": [
632630
{
633631
"inputs": {
@@ -658,7 +656,7 @@
658656
},
659657
"qc": {
660658
"key": "qc",
661-
"digest": "2jfnfowy32wp57i7ctsx7ni5pzzeadbi",
659+
"digest": "s3lt4rtck6w3p7rc6dlav2wda4oz7f7l",
662660
"tests": [
663661
{
664662
"inputs": {

wf-common

workflows/integrate_data/integrate_data.wdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ task integrate_sample_data {
9292
}
9393

9494
runtime {
95-
docker: "~{container_registry}/spatial_py:1.0.0"
95+
docker: "~{container_registry}/spatial_py:1.0.1"
9696
cpu: 4
9797
memory: "~{mem_gb} GB"
9898
disks: "local-disk ~{disk_size} HDD"
@@ -155,7 +155,7 @@ task cluster {
155155
}
156156

157157
runtime {
158-
docker: "~{container_registry}/spatial_py:1.0.0"
158+
docker: "~{container_registry}/spatial_py:1.0.1"
159159
cpu: 4
160160
memory: "~{mem_gb} GB"
161161
disks: "local-disk ~{disk_size} HDD"

workflows/spatial_visium/cohort_analysis/cohort_analysis.wdl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ workflow cohort_analysis {
3939
}
4040

4141
String sub_workflow_name = "cohort_analysis"
42-
String sub_workflow_version = "1.0.0"
42+
String sub_workflow_version = "1.0.1"
4343

4444
Array[Array[String]] workflow_info = [[run_timestamp, workflow_name, workflow_version, workflow_release]]
4545

@@ -273,7 +273,7 @@ task merge_and_plot_qc_metrics {
273273
}
274274

275275
runtime {
276-
docker: "~{container_registry}/spatial_py:1.0.0"
276+
docker: "~{container_registry}/spatial_py:1.0.1"
277277
cpu: 2
278278
memory: "~{mem_gb} GB"
279279
disks: "local-disk ~{disk_size} HDD"
@@ -354,7 +354,7 @@ task filter_and_normalize {
354354
}
355355

356356
runtime {
357-
docker: "~{container_registry}/spatial_py:1.0.0"
357+
docker: "~{container_registry}/spatial_py:1.0.1"
358358
cpu: 4
359359
memory: "~{mem_gb} GB"
360360
disks: "local-disk ~{disk_size} HDD"
@@ -420,7 +420,7 @@ task plot_spatial {
420420
}
421421

422422
runtime {
423-
docker: "~{container_registry}/spatial_py:1.0.0"
423+
docker: "~{container_registry}/spatial_py:1.0.1"
424424
cpu: 2
425425
memory: "~{mem_gb} GB"
426426
disks: "local-disk ~{disk_size} HDD"

workflows/spatial_visium/cohort_analysis/spatial_statistics/spatial_statistics.wdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ task spatially_variable_gene_analysis {
8989
}
9090

9191
runtime {
92-
docker: "~{container_registry}/spatial_py:1.0.0"
92+
docker: "~{container_registry}/spatial_py:1.0.1"
9393
cpu: 2
9494
memory: "~{mem_gb} GB"
9595
disks: "local-disk ~{disk_size} HDD"

0 commit comments

Comments
 (0)