Skip to content

Commit

Permalink
change function and parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahOuologuem committed Feb 10, 2025
1 parent 775e334 commit 66890d4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
20 changes: 10 additions & 10 deletions panpipes/panpipes/pipeline_preprocess_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def gen_filter_jobs():
@mkdir("tables")
@mkdir("filtered.data")
@files(gen_filter_jobs)
def filter_mudata(infile_path,outfile):
def filter_spatialdata(infile_path,outfile):
print('processing file = %s' % str(infile_path))
log_file = os.path.basename(outfile)
log_file= "1_filtering."+log_file.replace("filtered.zarr","") + ".log"
Expand All @@ -61,15 +61,15 @@ def filter_mudata(infile_path,outfile):
filter_dict = dictionary_stripper(PARAMS['filtering'])
cmd = """
python %(py_path)s/run_filter_spatial.py
--input_mudata %(infile_path)s
--output_mudata %(outfile)s
--input_spatialdata %(infile_path)s
--output_spatialdata %(outfile)s
--filter_dict "%(filter_dict)s"
"""
if PARAMS['filtering_keep_barcodes'] is not None:
cmd += " --keep_barcodes %(filtering_keep_barcodes)s"
cmd += " > logs/%(log_file)s "
job_kwargs["job_threads"] = PARAMS['resources_threads_low']
log_msg = f"TASK: 'filter_mudata'" + f" IN CASE OF ERROR, PLEASE REFER TO : 'logs/{log_file}' FOR MORE INFORMATION."
log_msg = f"TASK: 'filter_spatialdata'" + f" IN CASE OF ERROR, PLEASE REFER TO : 'logs/{log_file}' FOR MORE INFORMATION."
get_logger().info(log_msg)
P.run(cmd, **job_kwargs)

Expand All @@ -84,7 +84,7 @@ def run_plotqc_query(pqc_dict):

@active_if(run_plotqc_query(PARAMS['plotqc']))
@active_if(PARAMS['filtering_run'])
@transform(filter_mudata,
@transform(filter_spatialdata,
regex("./filtered.data/(.*)_filtered.zarr"),
r"./logs/2_postfilterplot.\1.log")
def postfilterplot_spatial(filt_file,log_file):
Expand All @@ -93,7 +93,7 @@ def postfilterplot_spatial(filt_file,log_file):
spatial_filetype = PARAMS["assay"]
cmd = """
python %(py_path)s/plot_qc_spatial.py
--input_mudata %(filt_file)s
--input_spatialdata %(filt_file)s
--spatial_filetype %(spatial_filetype)s
--figdir ./figures/spatial
"""
Expand All @@ -108,7 +108,7 @@ def postfilterplot_spatial(filt_file,log_file):
P.run(cmd, **job_kwargs)


@transform(filter_mudata,
@transform(filter_spatialdata,
regex("./filtered.data/(.*)_filtered.zarr"),
r"./logs/3_preprocess.\1.log")
def spatial_preprocess(filt_file,log_file):
Expand All @@ -119,8 +119,8 @@ def spatial_preprocess(filt_file,log_file):
write_output = os.path.join("./tmp/",os.path.basename(filt_file))
cmd = """
python %(py_path)s/run_preprocess_spatial.py
--input_mudata %(filt_file)s
--output_mudata %(write_output)s
--input_spatialdata %(filt_file)s
--output_spatialdata %(write_output)s
--figdir ./figures/spatial
"""
if PARAMS['spatial_norm_hvg_flavour'] is not None:
Expand Down Expand Up @@ -154,7 +154,7 @@ def spatial_preprocess(filt_file,log_file):
get_logger().info(log_msg)
P.run(cmd, **job_kwargs)

@follows(filter_mudata, postfilterplot_spatial, spatial_preprocess)
@follows(filter_spatialdata, postfilterplot_spatial, spatial_preprocess)
@originate("cleanup_done.txt")
def cleanup(file):
# remove any ctmp fails
Expand Down
16 changes: 8 additions & 8 deletions panpipes/panpipes/pipeline_qc_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_up_dirs(log_file):
pass

# -----------------------------------------------------------------------------------------------
## Creating h5mu from filtered data files
## Creating spatialData from filtered data files
# -----------------------------------------------------------------------------------------------


Expand All @@ -73,7 +73,7 @@ def gen_load_spatial_anndata_jobs():
@follows(mkdir("logs"))
@follows(mkdir("tmp"))
@files(gen_load_spatial_anndata_jobs)
def load_mudatas(spatial_path, outfile,
def load_spatialdatas(spatial_path, outfile,
sample_id, spatial_filetype, visium_feature_bc_matrix, visium_fullres_image_file, visium_tissue_positions_file, visium_scalefactors_file,
vpt_cell_by_gene, vpt_cell_metadata, vpt_cell_boundaries):

Expand Down Expand Up @@ -119,19 +119,19 @@ def load_mudatas(spatial_path, outfile,
--vpt_cell_metadata %(vpt_cell_metadata)s
--vpt_cell_boundaries %(vpt_cell_boundaries)s
"""
cmd += " > logs/1_make_mudatas_%(sample_id)s.log"
cmd += " > logs/1_make_spatialdatas_%(sample_id)s.log"
job_kwargs["job_threads"] = PARAMS['resources_threads_medium']
log_msg = f"TASK: 'load_mudatas'" + f" IN CASE OF ERROR, PLEASE REFER TO : 'logs/1_make_mudatas_{sample_id}.log' FOR MORE INFORMATION."
log_msg = f"TASK: 'load_spatialdatas'" + f" IN CASE OF ERROR, PLEASE REFER TO : 'logs/1_make_spatialdatas_{sample_id}.log' FOR MORE INFORMATION."
get_logger().info(log_msg)
P.run(cmd, **job_kwargs)




@follows(load_mudatas)
@follows(load_spatialdatas)
@follows(mkdir("qc.data"))
@follows(mkdir("./figures"))
@transform(load_mudatas,
@transform(load_spatialdatas,
regex("./tmp/(.*)_raw.zarr"),
r"./logs/2_spatialQC_\1.log")
def spatialQC(infile,log_file):
Expand Down Expand Up @@ -179,7 +179,7 @@ def run_plotqc_query(pqc_dict):
@follows(spatialQC)
@follows(mkdir("./figures/spatial"))
@active_if(run_plotqc_query(PARAMS['plotqc']))
@transform(load_mudatas,
@transform(load_spatialdatas,
regex("./tmp/(.*)_raw.zarr"),
r"./logs/3_qcplot.\1.log")
def plotQC_spatial(unfilt_file,log_file):
Expand All @@ -188,7 +188,7 @@ def plotQC_spatial(unfilt_file,log_file):
unfilt_file = unfilt_file.replace("tmp", "qc.data")
cmd = """
python %(py_path)s/plot_qc_spatial.py
--input_mudata %(unfilt_file)s
--input_spatialdata %(unfilt_file)s
--spatial_filetype %(spatial_filetype)s
--figdir ./figures/spatial
"""
Expand Down
12 changes: 6 additions & 6 deletions panpipes/python_scripts/plot_qc_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

parser = argparse.ArgumentParser()

parser.add_argument("--input_mudata",
default="mudata_unfilt.h5mu",
parser.add_argument("--input_spatialdata",
default="spatialdata_unfilt.h5mu",
help="")
parser.add_argument("--figdir",
default="./figures/",
Expand Down Expand Up @@ -58,12 +58,12 @@
sc.settings.figdir = figdir
sc.set_figure_params(scanpy=True, fontsize=14, dpi=300, facecolor='white', figsize=(5,5))

L.info("Reading in SpatialData from '%s'" % args.input_mudata)
sdata = sd.read_zarr(args.input_mudata)
#mdata = mu.read(args.input_mudata)
L.info("Reading in SpatialData from '%s'" % args.input_spatialdata)
sdata = sd.read_zarr(args.input_spatialdata)
#mdata = mu.read(args.input_spatialdata)
#spatial = mdata.mod['spatial']

input_data = os.path.basename(args.input_mudata)
input_data = os.path.basename(args.input_spatialdata)
pattern = r"_filtered.zarr"
match = re.search(pattern, input_data)
if match is None:
Expand Down
22 changes: 11 additions & 11 deletions panpipes/python_scripts/run_filter_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ def test_matching_df_ignore_cat(new_df, old_df):
# parse arguments
parser = argparse.ArgumentParser()

parser.add_argument('--input_mudata',
parser.add_argument('--input_spatialdata',
default='gut_minus1_amp.h5ad',
help='')
parser.add_argument('--output_mudata',
parser.add_argument('--output_spatialdata',
default='',
help='')
parser.add_argument('--filter_dict',
default='',
help='this is pull')
# cross modalities args
parser.add_argument('--keep_barcodes', default=None,
help='1 column list of barcodes to keep, note that they should match the mudata input, this filtering happens first')
help='1 column list of barcodes to keep, note that they should match the spatialdata input, this filtering happens first')


# load options
Expand All @@ -73,14 +73,14 @@ def test_matching_df_ignore_cat(new_df, old_df):
filter_dict = dictionary_stripper(filter_dict)
L.info("Filter dictionary:\n %s" %filter_dict)

# load mudata
# load spatialdata

L.info("Reading in SpatialData from '%s'" % args.input_mudata)
sdata = sd.read_zarr(args.input_mudata)
#mdata = mu.read(args.input_mudata)
L.info("Reading in SpatialData from '%s'" % args.input_spatialdata)
sdata = sd.read_zarr(args.input_spatialdata)
#mdata = mu.read(args.input_spatialdata)

#if isinstance(mdata, AnnData):
# raise TypeError("Input '%s' should be of MuData format, not Anndata" % args.input_mudata)
# raise TypeError("Input '%s' should be of spatialdata format, not Anndata" % args.input_spatialdata)

orig_obs = sdata["table"].obs.copy()

Expand Down Expand Up @@ -147,7 +147,7 @@ def test_matching_df_ignore_cat(new_df, old_df):
assert test_matching_df_ignore_cat(sdata["table"].obs, orig_obs)

# write out obs
output_prefix = re.sub(".zarr", "", os.path.basename(args.output_mudata))
output_prefix = re.sub(".zarr", "", os.path.basename(args.output_spatialdata))

L.info("Saving updated obs in a metadata tsv file to './tables/" + output_prefix + "_filtered_cell_metadata.tsv'")
write_obs(sdata["table"], output_prefix=os.path.join("tables/",output_prefix), output_suffix="_filtered_cell_metadata.tsv")
Expand All @@ -166,8 +166,8 @@ def test_matching_df_ignore_cat(new_df, old_df):

#mdata.update()

L.info("Saving updated SpatialData to '%s'" % args.output_mudata)
sdata.write(args.output_mudata)
L.info("Saving updated SpatialData to '%s'" % args.output_spatialdata)
sdata.write(args.output_spatialdata)

L.info("Done")

20 changes: 10 additions & 10 deletions panpipes/python_scripts/run_preprocess_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

parser = argparse.ArgumentParser()

parser.add_argument("--input_mudata",
default="mudata_unfilt.h5mu",
parser.add_argument("--input_spatialdata",
default="spatialdata_unfilt.h5mu",
help="")
parser.add_argument("--output_mudata",
default="mudata_unfilt.h5mu",
parser.add_argument("--output_spatialdata",
default="spatialdata_unfilt.h5mu",
help="")
parser.add_argument("--figdir",
default="./figures/",
Expand Down Expand Up @@ -89,12 +89,12 @@
sc.settings.figdir = figdir
sc.set_figure_params(scanpy=True, fontsize=14, dpi=300, facecolor='white', figsize=(5,5))

L.info("Reading in SpatialData from '%s'" % args.input_mudata)
sdata = sd.read_zarr(args.input_mudata)
#mdata = mu.read(args.input_mudata)
L.info("Reading in SpatialData from '%s'" % args.input_spatialdata)
sdata = sd.read_zarr(args.input_spatialdata)
#mdata = mu.read(args.input_spatialdata)
#spatial = mdata.mod['spatial']

input_data = os.path.basename(args.input_mudata)
input_data = os.path.basename(args.input_spatialdata)
pattern = r"_filtered.zarr"
match = re.search(pattern, input_data)
sprefix = input_data[:match.start()]
Expand Down Expand Up @@ -174,8 +174,8 @@


#mdata.update()
L.info("Saving updated SpatialData to '%s'" % args.output_mudata)
sdata.write(args.output_mudata)
L.info("Saving updated SpatialData to '%s'" % args.output_spatialdata)
sdata.write(args.output_spatialdata)

L.info("Done")

0 comments on commit 66890d4

Please sign in to comment.