Skip to content

Commit

Permalink
Merge pull request #90 from DendrouLab/fc_testMultimodal
Browse files Browse the repository at this point in the history
Fc test multimodal
  • Loading branch information
crichgriffin authored Sep 11, 2023
2 parents 0606e6d + db873f2 commit e1a78a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
4 changes: 0 additions & 4 deletions panpipes/panpipes/pipeline_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,6 @@ def run_mofa(outfile):
cmd += " > logs/multimodal_mofa.log "
P.run(cmd, **job_kwargs)

#To do
# WNN can run on not batch corrected data or on the output of the steps above,
# where we batch correct each knn
# how can this alternative be translated here in decorators?
# Run WNN

@follows(set_up_dirs)
Expand Down
3 changes: 2 additions & 1 deletion panpipes/python_scripts/batch_correct_totalvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@
# in case of more than 1 variable, create a fake column with combined information
if args.integration_col_categorical is not None :
columns = [x.strip() for x in args.integration_col_categorical.split(",")]
columns =[ x.replace("rna:","") for x in columns]
if len(columns) > 1:
L.info("using 2 columns to integrate on more variables")
# bc_batch = "_".join(columns)
rna.obs["bc_batch"] = rna.obs[columns].apply(lambda x: '|'.join(x), axis=1)
# make sure that batch is a categorical
rna.obs["bc_batch"] = rna.obs["bc_batch"].astype("category")
else:
rna.obs['bc_batch'] = rna.obs[args.integration_col_categorical]
rna.obs['bc_batch'] = rna.obs[columns] #since it's one
rna.obs["bc_batch"] = rna.obs["bc_batch"].astype("category")
batch_categories = list(rna.obs['bc_batch'].unique())
kwargs["batch_key"] = "bc_batch"
Expand Down
33 changes: 31 additions & 2 deletions panpipes/python_scripts/run_collate_mtd_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
# format the column names correctly, and add any merge columns to the dataset
for k in batch_dict.keys():
v=batch_dict[k]
print(k)
print(v)
if k =="multimodal":
mk = []
exc = []
Expand All @@ -59,6 +61,7 @@
else:
exc.append(v2)
if len(exc)>0:
print(exc)
tmp =[]
for g in ["atac","rna","prot","rep"]:
for e in exc:
Expand All @@ -73,11 +76,37 @@
v =[k + ":" +v1 if k!="multimodal" else v1 for v1 in v ] #add the prepending modality
batch_dict[k] = v
if len(v) > 1:
print(v)
mod_meta_df= cell_meta_df[v].dropna()
cell_meta_df[str(k)+ ":bc_batch"] = mod_meta_df.apply(lambda x: '|'.join(x), axis=1)
batch_dict[k].append(k+ ":bc_batch")
# Create a list to store identical column pairs
identical_column_pairs = []

# Iterate through pairs of columns and check if they are identical
for i in range(len(v)):
for j in range(i + 1, len(v)):
col1 = v[i]
col2 = v[j]

if mod_meta_df[col1].equals(mod_meta_df[col2]):
identical_column_pairs.append((col1, col2))
if identical_column_pairs:
print("Identical column pairs:")
for col1, col2 in identical_column_pairs:
print(f"{col1} and {col2} are identical.")
batch_dict[k].append(col1)
else:
print("No identical columns found.")
cell_meta_df[str(k)+ ":bc_batch"] = mod_meta_df.apply(lambda x: '|'.join(x), axis=1)
batch_dict[k].append(k+ ":bc_batch")
L.info("batch values %s" %(batch_dict[k]))

for k in batch_dict.keys():
unique_values = list(set(batch_dict[k]))
batch_dict[k] = unique_values

L.info("saving batch dictionary")
print(batch_dict)

cell_meta_df.to_csv(args.output_cell_metadata_csv)

with open(args.output_batch_yml, 'w') as outfile:
Expand Down

0 comments on commit e1a78a6

Please sign in to comment.