From 24f035ac9707641c3fd79beb4287b2072b6529d0 Mon Sep 17 00:00:00 2001 From: SarahOuologuem Date: Thu, 7 Nov 2024 15:05:26 +0100 Subject: [PATCH] add vpt parameters --- panpipes/funcs/io.py | 63 +++++++++++++++--------- panpipes/panpipes/pipeline_qc_spatial.py | 37 ++++++++------ 2 files changed, 62 insertions(+), 38 deletions(-) diff --git a/panpipes/funcs/io.py b/panpipes/funcs/io.py index c6ff2c5c..b50496da 100644 --- a/panpipes/funcs/io.py +++ b/panpipes/funcs/io.py @@ -157,40 +157,58 @@ def gen_load_spatial_jobs(caf, mode_dictionary = {}, load_raw=True): else: spatial_path = caf["spatial_path"][nn] if caf['spatial_filetype'][nn]=="vizgen": - spatial_counts = None - spatial_fullres_image_file = None - spatial_tissue_positions_file = None - spatial_scalefactors_file = None + visium_feature_bc_matrix = None + visium_fullres_image_file = None + visium_tissue_positions_file = None + visium_scalefactors_file = None spatial_filetype = caf['spatial_filetype'][nn] + if pd.notna(caf['vpt_cell_by_gene'][nn]): + vpt_cell_by_gene = caf['vpt_cell_by_gene'][nn] + else: + vpt_cell_by_gene = None + if pd.notna(caf['vpt_cell_metadata'][nn]): + vpt_cell_metadata = caf['vpt_cell_metadata'][nn] + else: + vpt_cell_metadata = None + if pd.notna(caf['vpt_cell_boundaries'][nn]): + vpt_cell_boundaries = caf['vpt_cell_boundaries'][nn] + else: + vpt_cell_boundaries = None elif caf['spatial_filetype'][nn]=="visium": + vpt_cell_by_gene = None + vpt_cell_metadata = None + vpt_cell_boundaries = None spatial_filetype = caf['spatial_filetype'][nn] #counts file - if pd.notna(caf["spatial_counts"][nn]): - spatial_counts= caf["spatial_counts"][nn] + if pd.notna(caf["visium_feature_bc_matrix"][nn]): + visium_feature_bc_matrix= caf["visium_feature_bc_matrix"][nn] else: - spatial_counts = None + visium_feature_bc_matrix = None # fullres image - if pd.notna(caf["spatial_fullres_image_file"][nn]): - spatial_fullres_image_file= caf["spatial_fullres_image_file"][nn] + if pd.notna(caf["visium_fullres_image_file"][nn]): + visium_fullres_image_file= caf["visium_fullres_image_file"][nn] else: - spatial_fullres_image_file = None + visium_fullres_image_file = None # tissue position - if pd.notna(caf["spatial_tissue_positions_file"][nn]): - spatial_tissue_positions_file= caf["spatial_tissue_positions_file"][nn] + if pd.notna(caf["visium_tissue_positions_file"][nn]): + visium_tissue_positions_file= caf["visium_tissue_positions_file"][nn] else: - spatial_tissue_positions_file = None + visium_tissue_positions_file = None # scalefactor - if pd.notna(caf["spatial_scalefactors_file"][nn]): - spatial_scalefactors_file= caf["spatial_scalefactors_file"][nn] + if pd.notna(caf["visium_scalefactors_file"][nn]): + visium_scalefactors_file= caf["visium_scalefactors_file"][nn] else: - spatial_scalefactors_file = None + visium_scalefactors_file = None else: spatial_path= None spatial_filetype = None - spatial_counts = None - spatial_fullres_image_file = None - spatial_tissue_positions_file = None - spatial_scalefactors_file = None + visium_feature_bc_matrix = None + visium_fullres_image_file = None + visium_tissue_positions_file = None + visium_scalefactors_file = None + vpt_cell_by_gene = None + vpt_cell_metadata = None + vpt_cell_boundaries = None if 'barcode_mtd_path' in caf.columns: cell_mtd_path = caf['barcode_mtd_path'][nn] #not yielding this right now! @@ -204,8 +222,9 @@ def gen_load_spatial_jobs(caf, mode_dictionary = {}, load_raw=True): outfile = outfile + ".zarr" sample_id = caf['sample_id'][nn] - yield spatial_path, outfile, \ - sample_id, spatial_filetype, spatial_counts, spatial_fullres_image_file, spatial_tissue_positions_file, spatial_scalefactors_file + yield 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 def read_anndata( diff --git a/panpipes/panpipes/pipeline_qc_spatial.py b/panpipes/panpipes/pipeline_qc_spatial.py index 93cd2fa8..3bc90556 100644 --- a/panpipes/panpipes/pipeline_qc_spatial.py +++ b/panpipes/panpipes/pipeline_qc_spatial.py @@ -74,8 +74,8 @@ def gen_load_spatial_anndata_jobs(): @follows(mkdir("tmp")) @files(gen_load_spatial_anndata_jobs) def load_mudatas(spatial_path, outfile, - sample_id, spatial_filetype, spatial_counts, - spatial_fullres_image_file, spatial_tissue_positions_file, spatial_scalefactors_file): + 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): path_dict = {'spatial':spatial_path} @@ -83,17 +83,16 @@ def load_mudatas(spatial_path, outfile, print('sample_id = %s' % str(sample_id)) print('outfile = %s' % str(outfile)) print('spatial_filetype = %s' % str(spatial_filetype)) - #print('spatial_counts = %s' % str(spatial_counts)) - #if spatial_filetype == "vizgen": - # print('spatial_metadata = %s' % str(spatial_metadata)) - # print('spatial_transformation = %s' % str(spatial_transformation)) - #else: - # print("visium") + if spatial_filetype == "visium": - print('spatial_counts = %s' % str(spatial_counts)) - print('spatial_fullres_image_file= %s' % str(spatial_fullres_image_file)) - print('spatial_tissue_positions_file= %s' % str(spatial_tissue_positions_file)) - print('spatial_scalefactors_file= %s' % str(spatial_scalefactors_file)) + print('visium_feature_bc_matrix = %s' % str(visium_feature_bc_matrix)) + print('visium_fullres_image_file= %s' % str(visium_fullres_image_file)) + print('visium_tissue_positions_file= %s' % str(visium_tissue_positions_file)) + print('visium_scalefactors_file= %s' % str(visium_scalefactors_file)) + if spatial_filetype == "vizgen": + print('vpt_cell_by_gene = %s' % str(vpt_cell_by_gene)) + print('vpt_cell_metadata= %s' % str(vpt_cell_metadata)) + print('vpt_cell_boundaries= %s' % str(vpt_cell_boundaries)) modality_dict = {k:True if path_dict[k] is not None else False for k,v in {'spatial': True}.items() } print(modality_dict) @@ -109,10 +108,16 @@ def load_mudatas(spatial_path, outfile, """ if spatial_filetype == "visium": cmd += """ - --spatial_counts %(spatial_counts)s - --scalefactors_file %(spatial_scalefactors_file)s - --fullres_image_file %(spatial_fullres_image_file)s - --tissue_positions_file %(spatial_tissue_positions_file)s + --visium_feature_bc_matrix %(visium_feature_bc_matrix)s + --scalefactors_file %(visium_scalefactors_file)s + --fullres_image_file %(visium_fullres_image_file)s + --tissue_positions_file %(visium_tissue_positions_file)s + """ + if spatial_filetype == "vizgen": + cmd += """ + --vpt_cell_by_gene %(vpt_cell_by_gene)s + --vpt_cell_metadata %(vpt_cell_metadata)s + --vpt_cell_boundaries %(vpt_cell_boundaries)s """ cmd += " > logs/1_make_mudatas_%(sample_id)s.log" job_kwargs["job_threads"] = PARAMS['resources_threads_medium']