-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_h5ad_to_csv.py
More file actions
29 lines (24 loc) · 994 Bytes
/
convert_h5ad_to_csv.py
File metadata and controls
29 lines (24 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import scanpy as sc
import argparse
import pandas as pd
if __name__ == "__main__":
# Argument parsing.
parser = argparse.ArgumentParser()
parser.add_argument("x_matrix_file", help="X_matrix file")
parser.add_argument("output_matrix_file", help="Output matrix file")
args = parser.parse_args()
# load h5ad file and convert to csv
adata = sc.read_h5ad(args.x_matrix_file)
# extract x from adata file and convert to df
df = pd.DataFrame(adata.X, columns=adata.var_names)
df["X_centroid"] = adata.obs["X_centroid"].values
df["Y_centroid"] = adata.obs["Y_centroid"].values
# Convert E-cdaherin to Ecad
df = df.rename(columns={"E-cadherin": "Ecad"})
# Convert p-ERK to pERK
df = df.rename(columns={"p-ERK": "pERK"})
df = df.rename(columns={"ERK-1": "pERK"})
# Convert p-Rb to pRB
df = df.rename(columns={"p-Rb": "pRB"})
df = df.rename(columns={"Rb": "pRB"})
df.to_csv(args.output_matrix_file, sep=",", index=False)