Skip to content

Commit

Permalink
Corrected a bug in finding metadata column names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamie committed Jul 15, 2024
1 parent 03588db commit 6db0d80
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bin/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,18 @@ def RunPCA(cts, var_threshold, n_components):
action=argparse.BooleanOptionalAction,
help="Use SCVI latent variable instead of PCA.",
)
parser.add_argument("--metadata", required=False, default="", help="Metadata to be added to obs.")
parser.add_argument(
"--metadata", required=False, default="", help="Metadata to be added to obs."
)
args = parser.parse_args()

adata = sc.read_h5ad(args.input_h5ad)

if not args.metadata == "":
metadata = pd.read_csv(args.metadata)
new_cols = [x for x in metadata.cols if x not in adata.obs.columns]
intersect_cols = [x for x in metadata.cols if x in adata.obs.columns]
metadata = adata.obs.merge(metadata, how = 'left', on = intersect_cols)
new_cols = [x for x in metadata.columns if x not in adata.obs.columns]
intersect_cols = [x for x in metadata.columns if x in adata.obs.columns]
metadata = adata.obs.merge(metadata, how="left", on=intersect_cols)
assert metadata.shape[0] == adata.shape[0]
for new_col in new_cols:
adata.obs[new_col] = metadata[new_col]
Expand Down

0 comments on commit 6db0d80

Please sign in to comment.