-
Notifications
You must be signed in to change notification settings - Fork 0
/
scpCAT.py
178 lines (150 loc) · 11.7 KB
/
scpCAT.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import os
import argparse
from scpcat.functions import export_subset,_reduction,_createObj,_FindMarkers
from scpcat.functions import detectDoublet,transformer,enrichGO,_extract
from scpcat.functions import _dotplot,_EmbPlot,_DoHeatmap,VlnPlot
from scpcat.plotting import violin_hue,violin_sns
from scpcat.tfModule import addMotif
from scpcat.classifyBC import classify
if __name__=="__main__":
parser = argparse.ArgumentParser(description='Scanpy Cat: Single-Cell RNA-seq Simple Analysis Pipeline...,Just Very Simple,HA HA HA...')
subparsers = parser.add_subparsers()
####################
parser_create = subparsers.add_parser('create',help="create anndata object")
parser_create.add_argument('--path',"-d",type=str, default=None,help="cellranger count or aggr pipeline out path")
parser_create.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_create.set_defaults(func=_createObj)
####################
parser_reduction = subparsers.add_parser('reduction',help="reduction and cluster")
parser_reduction.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_reduction.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_reduction.add_argument('--batch_correct', action='store_true', help='whether do batch correct')
parser_reduction.add_argument('--batch_key', type=str, default=None, help='if do batch correct,which column as batch key')
parser_reduction.add_argument('--n_jobs', '-t', type=int, default=8, help='number of threads')
parser_reduction.set_defaults(func=_reduction)
####################
parser_marker= subparsers.add_parser('findmarker',help="find markers")
parser_marker.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_marker.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_marker.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_marker.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_marker.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_marker.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_marker.add_argument("--groupby",type=str,default="status",help="groupby")
parser_marker.add_argument("--method",type=str,default="t-test",help="t-test_overestim_var,wilcoxon")
parser_marker.add_argument("--splitby",type=str,default=None,help="if splitby,will run in each with groupby(leiden,label_main,label_fine)")
parser_marker.set_defaults(func=_FindMarkers)
####################
parser_dotplot= subparsers.add_parser('dotplot',help="do dotplot")
parser_dotplot.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_dotplot.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_dotplot.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_dotplot.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_dotplot.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_dotplot.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_dotplot.add_argument("--groupby",type=str,default="status",help="groupby")
parser_dotplot.add_argument("--level",nargs="+",type=str,default=None,help="groupby factor level")
parser_dotplot.add_argument("--color",type=str,default="Oranges",help="which color to use")
parser_dotplot.add_argument("--genelist",type=str,required=True,default=None,help="gene list file,to show in dotplot")
parser_dotplot.add_argument("--height",type=int,default=8,help="figure height")
parser_dotplot.add_argument("--width",type=int,default=12,help="figure width")
parser_dotplot.set_defaults(func=_dotplot)
#####################
parser_embplot= subparsers.add_parser('embplot',help="do embedding plot")
parser_embplot.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_embplot.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_embplot.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_embplot.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_embplot.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_embplot.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_embplot.add_argument("--groupby",type=str,default="status",help="groupby")
parser_embplot.add_argument("--level",nargs="+",type=str,default=None,help="groupby factor level")
parser_embplot.add_argument("--theme",type=str,default=None,help="which theme use for embedding plot")
parser_embplot.add_argument("--embedding",type=str,default="umap",help="which embedding use for embedding plot")
#parser_embplot.add_argument("--genelist",nargs="+",type=str,default=None,help="gene list file,to show in embdding plot")
parser_embplot.add_argument("--genelist",type=str,default=None,help="gene list file,to show in embdding plot")
parser_embplot.add_argument("--height",type=int,default=8,help="figure height")
parser_embplot.add_argument("--width",type=int,default=12,help="figure width")
parser_embplot.set_defaults(func=_EmbPlot)
####################
parser_heatmap= subparsers.add_parser('heatmap',help="do heatmap")
parser_heatmap.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_heatmap.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_heatmap.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_heatmap.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_heatmap.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_heatmap.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_heatmap.add_argument("--groupby",type=str,default="status",help="groupby")
parser_heatmap.add_argument("--level",nargs="+",type=str,default=None,help="groupby factor level")
parser_heatmap.add_argument("--color",type=str,default="Oranges",help="which color to use")
parser_heatmap.add_argument("--genelist",type=str,default=None,help="gene list file,to show in heatmap")
parser_heatmap.add_argument('--n_genes', '-n', type=int, default=10, help='number of genes in echo group to show')
parser_heatmap.set_defaults(func=_DoHeatmap)
####################
parser_vln= subparsers.add_parser('vlnplot',help="do violin plot")
parser_vln.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_vln.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_vln.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_vln.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_vln.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_vln.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_vln.add_argument("--groupby",type=str,default="status",help="groupby")
parser_vln.add_argument("--level",nargs="+",type=str,default=None,help="groupby factor level")
parser_vln.add_argument("--genelist",type=str,default=None,help="gene list file,to show in vlnplot")
parser_vln.add_argument("--orient",type=str,default="h",help="h(hline) or v(vline")
parser_vln.add_argument("--hue_order",nargs="+",type=str,default=None,help="hue order(HC vs VKH")
parser_vln.add_argument("--hue",type=str,default=None,help="hue column,level length ==2,like (Status)")
parser_vln.add_argument("--height",type=int,default=8,help="figure height")
parser_vln.add_argument("--width",type=int,default=12,help="figure width")
parser_vln.set_defaults(func=VlnPlot)
####################
parser_s= subparsers.add_parser('subset',help="export subset")
parser_s.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_s.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_s.add_argument("--subset",nargs="+",type=str,default=None,help="subset")
parser_s.add_argument("--column",type=str,default="leiden",help="subset column")
parser_s.add_argument("--bclist",type=str,default=None,help="cell barcode list file,to show in heatmap")
parser_s.add_argument('--invert', action='store_true', help='whether invert')
parser_s.set_defaults(func=export_subset)
####################
parser_e= subparsers.add_parser("enrich",help="gene enrichment")
parser_e.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_e.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_e.add_argument('--org', type=str, default='hsapiens', help='hsapiens or mmusculus')
parser_e.add_argument("--genelist",type=str,default=None,help="gene list for enrichment")
parser_e.add_argument('--groupby', type=str, default="leiden",help='groupby')
parser_e.set_defaults(func=enrichGO)
parser_t= subparsers.add_parser("transform",help="convert seurat to anadata")
parser_t.add_argument('--filename',"-f",type=str, default=None,help="seurat rds filename")
parser_t.add_argument("--name",type=str,default="seurat",help="prefix name")
parser_t.add_argument("--outdir","-o",type=str,default="anndata",help="outpath to save h5ad")
parser_t.set_defaults(func=transformer)
parser_d= subparsers.add_parser("doublet",help="detect doublet")
parser_d.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_d.add_argument('--outdir', '-o', type=str, default='output', help='Output path')
parser_d.set_defaults(func=detectDoublet)
#####################
parser_ex= subparsers.add_parser('wraperLoupe',help="extract embedding and cluster for loupe software")
parser_ex.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_ex.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_ex.add_argument("--subset1",nargs="+",type=str,default=None,help="subset1")
parser_ex.add_argument("--subset2",nargs="+",type=str,default=None,help="subset2")
parser_ex.add_argument("--column1",type=str,default="leiden",help="subset column1")
parser_ex.add_argument("--column2",type=str,default=None,help="subset column2 ")
parser_ex.add_argument("--emblist",nargs="+",type=str,default="umap",help="embedding names")
parser_ex.add_argument("--labels",nargs="+",type=str,default="leiden",help="cluster names")
parser_ex.set_defaults(func=_extract)
parser_tf= subparsers.add_parser('addMotif',help="add Motif Module")
parser_tf.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_tf.add_argument("--organism",type=str,default="Human",help="Human or Mouse")
parser_tf.add_argument("--ntop","-n",type=int,default=1000,help="top number for progeny model")
parser_tf.add_argument('--outdir', '-o', type=str, default='output/', help='Output path')
parser_tf.set_defaults(func=addMotif)
parser_cy= subparsers.add_parser('classify',help="Use scorect method to predict celltype with reference markers")
parser_cy.add_argument('--path',"-d",type=str, default=None,help="anndata h5ad file")
parser_cy.add_argument('--groupby',"-g",type=str, default="leiden",help="which group use for predictor")
parser_cy.add_argument('--db',type=str,default=None,help="reference markers table")
parser_cy.add_argument('--outdir','-o',default="out",type=str,help='Output path')
parser_cy.set_defaults(func=classify)
args=parser.parse_args()
args.func(args)