-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_refine.py
More file actions
79 lines (58 loc) · 1.97 KB
/
Copy pathplot_refine.py
File metadata and controls
79 lines (58 loc) · 1.97 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import scanpy as sc
import argparse
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser()
parser.add_argument('myObject')
args = parser.parse_args()
myObject = args.myObject
orig_base = os.path.splitext(os.path.basename(myObject))[0]
parts = orig_base.split('_clustered_ddanalysed_doubletScores_0.8')
base_name = os.path.splitext(os.path.basename(myObject))[0]
base_name = "refined_"+ base_name
newObject = base_name + ".h5ad"
adata = sc.read(myObject)
cell_counts = adata.obs['sample'].value_counts()
print(cell_counts)
print(adata.obs.columns)
sc.pl.violin(
adata,
["n_genes_by_counts", "total_counts", "pct_counts_mt"],
jitter=0.4,
multi_panel=True, save=f"_{base_name}_PreQC.png")
adata = adata[
(adata.obs['n_genes_by_counts'] > 800) &
(adata.obs['n_genes_by_counts'] < 8000) &
(adata.obs['total_counts'] > 1200) &
(adata.obs['total_counts'] < 30000) &
(adata.obs['pct_counts_mt'] < 25), :
]
sc.pl.violin(
adata,
["n_genes_by_counts", "total_counts", "pct_counts_mt"],
jitter=0.4,
multi_panel=True,save=f"_{base_name}_PostQC.png")
sc.pl.violin(
adata,
keys=['n_genes_by_counts', 'total_counts', 'pct_counts_mt'],
groupby='leiden', # change if you use another cluster label
jitter=0.4,
rotation=45,
multi_panel=True,save=f"_{base_name}_qc_violin.png")
samples = adata.obs['sample'].unique()
# Loop through samples and plot individual UMAPs
import matplotlib.pyplot as plt
for sample in samples:
sc.pl.umap(
adata[adata.obs['sample'] == sample],
color='sample',
title=f"Sample: {sample}",
size=20,
show=False # do not display
)
fig = plt.gcf() # get the current figure
fig.set_size_inches(10, 10) # resize figure
fig.savefig(f"figures/refined_{base_name}_{sample}.png", dpi=600, bbox_inches='tight')
plt.close(fig)
adata.obs_names_make_unique()
adata.write(newObject, compression="gzip")