Skip to content

Commit 723f4ca

Browse files
committed
working novae rule
1 parent d140e27 commit 723f4ca

1 file changed

Lines changed: 37 additions & 32 deletions

File tree

workflow/Snakefile

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ rule novae:
276276
output:
277277
touch(paths.smk_novae),
278278
conda:
279-
"sopa2"
279+
"novae"
280280
threads: 16
281281
resources:
282282
mem_mb=64_000,
283283
queue="gpuexpress -R 'a100' -gpu 'num=1'",
284-
time=180,
284+
time=45,
285285
params:
286286
sdata_path = paths.sdata_path,
287287
radius = config["novae"]["radius"],
@@ -293,14 +293,17 @@ rule novae:
293293
python -c "
294294
import novae
295295
import spatialdata as sd
296+
from spatialdata import SpatialData
296297
import anndata as ad
297298
import os
298-
import shutil
299-
import zarr
299+
import numpy as np
300+
301+
# Define the table key constant since we're not in the sopa environment
302+
TABLE_KEY = 'table'
300303
301304
# Read the SpatialData object
302305
sdata = sd.read_zarr('{params.sdata_path}')
303-
adata = sdata['table']
306+
adata = sdata[TABLE_KEY]
304307
305308
# Run Novae on the AnnData object
306309
model = novae.Novae.from_pretrained('{params.model}')
@@ -317,33 +320,35 @@ model.assign_domains(adata, level=10)
317320
model.assign_domains(adata, level=15)
318321
319322
# Update the table in the SpatialData object
320-
sdata['table'] = adata
321-
322-
# Create a temporary directory for writing
323-
temp_dir = '{params.sdata_path}_temp'
324-
if os.path.exists(temp_dir):
325-
shutil.rmtree(temp_dir)
326-
os.makedirs(temp_dir)
327-
328-
# Write the entire SpatialData object to the temporary directory
329-
sdata.write(temp_dir)
330-
331-
# Close the SpatialData object to release file locks
332-
del sdata
333-
334-
# Copy only the table directory from the temporary location to the original location
335-
src_table_dir = os.path.join(temp_dir, 'tables', 'table')
336-
dst_table_dir = os.path.join('{params.sdata_path}', 'tables', 'table')
337-
338-
# Remove the destination directory if it exists
339-
if os.path.exists(dst_table_dir):
340-
shutil.rmtree(dst_table_dir)
341-
342-
# Copy the new table directory to the destination
343-
shutil.copytree(src_table_dir, dst_table_dir)
344-
345-
# Clean up the temporary directory
346-
shutil.rmtree(temp_dir)
323+
sdata[TABLE_KEY] = adata
324+
325+
# Use a direct approach for updating just the table
326+
if sdata.is_backed():
327+
sdata.delete_element_from_disk(TABLE_KEY)
328+
sdata.write_element(TABLE_KEY, overwrite=True)
329+
else:
330+
# Fallback to a temporary directory approach if not backed
331+
import tempfile
332+
import shutil
333+
334+
temp_dir = tempfile.mkdtemp()
335+
try:
336+
# Write to temporary location
337+
sdata.write(temp_dir)
338+
339+
# Copy only the table directory
340+
src_table_dir = os.path.join(temp_dir, 'tables', 'table')
341+
dst_table_dir = os.path.join('{params.sdata_path}', 'tables', 'table')
342+
343+
# Remove the destination directory if it exists
344+
if os.path.exists(dst_table_dir):
345+
shutil.rmtree(dst_table_dir)
346+
347+
# Copy the new table directory to the destination
348+
shutil.copytree(src_table_dir, dst_table_dir)
349+
finally:
350+
# Clean up the temporary directory
351+
shutil.rmtree(temp_dir)
347352
348353
print('Successfully updated the table with Novae domains')
349354
"

0 commit comments

Comments
 (0)