gsMap 1.71.1__py3-none-any.whl → 1.71.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gsMap/latent_to_gene.py CHANGED
@@ -1,234 +1,252 @@
1
- import logging
2
- from pathlib import Path
3
-
4
- import numpy as np
5
- import pandas as pd
6
- import scanpy as sc
7
- from scipy.stats import gmean
8
- from scipy.stats import rankdata
9
- from sklearn.metrics.pairwise import cosine_similarity
10
- from sklearn.neighbors import NearestNeighbors
11
- from tqdm import tqdm
12
-
13
- from gsMap.config import LatentToGeneConfig
14
-
15
- logger = logging.getLogger(__name__)
16
-
17
-
18
- def find_neighbors(coor, num_neighbour):
19
- """
20
- Find Neighbors of each cell (based on spatial coordinates).
21
- """
22
- nbrs = NearestNeighbors(n_neighbors=num_neighbour).fit(coor)
23
- distances, indices = nbrs.kneighbors(coor, return_distance=True)
24
- cell_indices = np.arange(coor.shape[0])
25
- cell1 = np.repeat(cell_indices, indices.shape[1])
26
- cell2 = indices.flatten()
27
- distance = distances.flatten()
28
- spatial_net = pd.DataFrame({'Cell1': cell1, 'Cell2': cell2, 'Distance': distance})
29
- return spatial_net
30
-
31
-
32
- def build_spatial_net(adata, annotation, num_neighbour):
33
- """
34
- Build spatial neighbourhood matrix for each spot (cell) based on the spatial coordinates.
35
- """
36
- logger.info(f'------Building spatial graph based on spatial coordinates...')
37
-
38
- coor = adata.obsm['spatial']
39
- if annotation is not None:
40
- logger.info(f'Cell annotations are provided...')
41
- spatial_net_list = []
42
- # Cells with annotations
43
- for ct in adata.obs[annotation].dropna().unique():
44
- idx = np.where(adata.obs[annotation] == ct)[0]
45
- coor_temp = coor[idx, :]
46
- spatial_net_temp = find_neighbors(coor_temp, min(num_neighbour, coor_temp.shape[0]))
47
- # Map back to original indices
48
- spatial_net_temp['Cell1'] = idx[spatial_net_temp['Cell1'].values]
49
- spatial_net_temp['Cell2'] = idx[spatial_net_temp['Cell2'].values]
50
- spatial_net_list.append(spatial_net_temp)
51
- logger.info(f'{ct}: {coor_temp.shape[0]} cells')
52
-
53
- # Cells labeled as nan
54
- if pd.isnull(adata.obs[annotation]).any():
55
- idx_nan = np.where(pd.isnull(adata.obs[annotation]))[0]
56
- logger.info(f'Nan: {len(idx_nan)} cells')
57
- spatial_net_temp = find_neighbors(coor, num_neighbour)
58
- spatial_net_temp = spatial_net_temp[spatial_net_temp['Cell1'].isin(idx_nan)]
59
- spatial_net_list.append(spatial_net_temp)
60
- spatial_net = pd.concat(spatial_net_list, axis=0)
61
- else:
62
- logger.info(f'Cell annotations are not provided...')
63
- spatial_net = find_neighbors(coor, num_neighbour)
64
-
65
- return spatial_net
66
-
67
-
68
- def find_neighbors_regional(cell_pos, spatial_net_dict, coor_latent, config, cell_annotations):
69
- num_neighbour = config.num_neighbour
70
- annotations = config.annotation
71
-
72
- cell_use_pos = spatial_net_dict.get(cell_pos, [])
73
- if len(cell_use_pos) == 0:
74
- return []
75
-
76
- cell_latent = coor_latent[cell_pos, :].reshape(1, -1)
77
- neighbors_latent = coor_latent[cell_use_pos, :]
78
- similarity = cosine_similarity(cell_latent, neighbors_latent).reshape(-1)
79
-
80
- if annotations is not None:
81
- cell_annotation = cell_annotations[cell_pos]
82
- neighbor_annotations = cell_annotations[cell_use_pos]
83
- mask = neighbor_annotations == cell_annotation
84
- if not np.any(mask):
85
- return []
86
- similarity = similarity[mask]
87
- cell_use_pos = cell_use_pos[mask]
88
-
89
- if len(similarity) == 0:
90
- return []
91
-
92
- indices = np.argsort(-similarity) # descending order
93
- top_indices = indices[:num_neighbour]
94
- cell_select_pos = cell_use_pos[top_indices]
95
- return cell_select_pos
96
-
97
-
98
- def compute_regional_mkscore(cell_pos, spatial_net_dict, coor_latent, config, cell_annotations,
99
- ranks, frac_whole, adata_X_bool):
100
- """
101
- Compute gmean ranks of a region.
102
- """
103
- cell_select_pos = find_neighbors_regional(
104
- cell_pos, spatial_net_dict, coor_latent, config, cell_annotations
105
- )
106
- if len(cell_select_pos) == 0:
107
- return np.zeros(ranks.shape[1], dtype=np.float16)
108
-
109
- # Ratio of expression ranks
110
- ranks_tg = ranks[cell_select_pos, :]
111
- gene_ranks_region = gmean(ranks_tg, axis=0)
112
- gene_ranks_region[gene_ranks_region <= 1] = 0
113
-
114
- if not config.no_expression_fraction:
115
- # Ratio of expression fractions
116
- frac_focal = adata_X_bool[cell_select_pos, :].sum(axis=0).A1 / len(cell_select_pos)
117
- frac_region = frac_focal / frac_whole
118
- frac_region[frac_region <= 1] = 0
119
- frac_region[frac_region > 1] = 1
120
-
121
- # Simultaneously consider the ratio of expression fractions and ranks
122
- gene_ranks_region = gene_ranks_region * frac_region
123
-
124
- mkscore = np.exp(gene_ranks_region ** 1.5) - 1
125
- return mkscore.astype(np.float16, copy=False)
126
-
127
-
128
- def run_latent_to_gene(config: LatentToGeneConfig):
129
- logger.info('------Loading the spatial data...')
130
- adata = sc.read_h5ad(config.hdf5_with_latent_path)
131
-
132
- if config.annotation is not None:
133
- logger.info(f'------Cell annotations are provided as {config.annotation}...')
134
- adata = adata[~pd.isnull(adata.obs[config.annotation]), :]
135
-
136
- # Homologs transformation
137
- if config.homolog_file is not None:
138
- logger.info(f'------Transforming the {config.species} to HUMAN_GENE_SYM...')
139
- homologs = pd.read_csv(config.homolog_file, sep='\t')
140
- if homologs.shape[1] != 2:
141
- raise ValueError(
142
- "Homologs file must have two columns: one for the species and one for the human gene symbol.")
143
-
144
- homologs.columns = [config.species, 'HUMAN_GENE_SYM']
145
- homologs.set_index(config.species, inplace=True)
146
- adata = adata[:, adata.var_names.isin(homologs.index)]
147
- logger.info(f"{adata.shape[1]} genes retained after homolog transformation.")
148
- if adata.shape[1] < 100:
149
- raise ValueError("Too few genes retained in ST data (<100).")
150
- adata.var_names = homologs.loc[adata.var_names, 'HUMAN_GENE_SYM'].values
151
- adata = adata[:, ~adata.var_names.duplicated()]
152
-
153
- # Create mappings
154
- n_cells = adata.n_obs
155
- n_genes = adata.n_vars
156
-
157
- if config.annotation is not None:
158
- cell_annotations = adata.obs[config.annotation].values
159
- else:
160
- cell_annotations = None
161
-
162
- # Build the spatial graph
163
- spatial_net = build_spatial_net(adata, config.annotation, config.num_neighbour_spatial)
164
- spatial_net_dict = spatial_net.groupby('Cell1')['Cell2'].apply(np.array).to_dict()
165
-
166
- # Extract the latent representation
167
- coor_latent = adata.obsm[config.latent_representation]
168
- coor_latent = coor_latent.astype(np.float32)
169
-
170
- # Compute ranks
171
- logger.info('------Ranking the spatial data...')
172
- adata_X = adata.X.tocsr()
173
- ranks = np.zeros((n_cells, n_genes), dtype=np.float32)
174
-
175
- for i in tqdm(range(n_cells), desc="Computing ranks per cell"):
176
- data = adata_X[i, :].toarray().flatten()
177
- ranks[i, :] = rankdata(data, method='average')
178
-
179
- # Geometric mean across slices
180
- if config.gM_slices is not None:
181
- logger.info('Geometrical mean across multiple slices is provided.')
182
- gM_df = pd.read_parquet(config.gM_slices)
183
- if config.species is not None:
184
- homologs = pd.read_csv(config.homolog_file, sep='\t', header=None)
185
- if homologs.shape[1] < 2:
186
- raise ValueError(
187
- "Homologs file must have at least two columns: one for the species and one for the human gene symbol.")
188
- homologs.columns = [config.species, 'HUMAN_GENE_SYM']
189
- homologs.set_index(config.species, inplace=True)
190
- gM_df = gM_df.loc[gM_df.index.isin(homologs.index)]
191
- gM_df.index = homologs.loc[gM_df.index, 'HUMAN_GENE_SYM'].values
192
- common_genes = np.intersect1d(adata.var_names, gM_df.index)
193
- gM_df = gM_df.loc[common_genes]
194
- gM = gM_df['G_Mean'].values
195
- adata = adata[:, common_genes]
196
- ranks = ranks[:, np.isin(adata.var_names, common_genes)]
197
- else:
198
- gM = gmean(ranks, axis=0)
199
-
200
- # Compute the fraction of each gene across cells
201
- adata_X_bool = adata_X.astype(bool)
202
- frac_whole = np.asarray(adata_X_bool.sum(axis=0)).flatten() / n_cells
203
-
204
- # Normalize the ranks
205
- ranks = ranks / gM
206
-
207
- # Compute marker scores in parallel
208
- logger.info('------Computing marker scores...')
209
-
210
- def compute_mk_score_wrapper(cell_pos):
211
- return compute_regional_mkscore(
212
- cell_pos, spatial_net_dict, coor_latent, config, cell_annotations, ranks, frac_whole, adata_X_bool
213
- )
214
-
215
- mk_scores = [compute_mk_score_wrapper(cell_pos) for cell_pos in tqdm(range(n_cells), desc="Calculating marker scores")]
216
- mk_score = np.vstack(mk_scores).T
217
-
218
- # Remove mitochondrial genes
219
- gene_names = adata.var_names.values.astype(str)
220
- mt_gene_mask = ~(np.char.startswith(gene_names, 'MT-') | np.char.startswith(gene_names, 'mt-'))
221
- mk_score = mk_score[mt_gene_mask, :]
222
- gene_names = gene_names[mt_gene_mask]
223
-
224
- # Save the marker scores
225
- logger.info(f'------Saving marker scores ...')
226
- output_file_path = Path(config.mkscore_feather_path)
227
- output_file_path.parent.mkdir(parents=True, exist_ok=True, mode=0o755)
228
- mk_score_df = pd.DataFrame(mk_score, index=gene_names, columns=adata.obs_names)
229
- mk_score_df.reset_index(inplace=True)
230
- mk_score_df.rename(columns={'index': 'HUMAN_GENE_SYM'}, inplace=True)
231
- mk_score_df.to_feather(output_file_path)
232
-
233
- # Save the modified adata object to disk
234
- adata.write(config.hdf5_with_latent_path)
1
+ import logging
2
+ from pathlib import Path
3
+
4
+ import numpy as np
5
+ import pandas as pd
6
+ import scanpy as sc
7
+ import scipy
8
+ from scipy.stats import gmean
9
+ from scipy.stats import rankdata
10
+ from sklearn.metrics.pairwise import cosine_similarity
11
+ from sklearn.neighbors import NearestNeighbors
12
+ from tqdm import tqdm
13
+
14
+ from gsMap.config import LatentToGeneConfig
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ def find_neighbors(coor, num_neighbour):
20
+ """
21
+ Find Neighbors of each cell (based on spatial coordinates).
22
+ """
23
+ nbrs = NearestNeighbors(n_neighbors=num_neighbour).fit(coor)
24
+ distances, indices = nbrs.kneighbors(coor, return_distance=True)
25
+ cell_indices = np.arange(coor.shape[0])
26
+ cell1 = np.repeat(cell_indices, indices.shape[1])
27
+ cell2 = indices.flatten()
28
+ distance = distances.flatten()
29
+ spatial_net = pd.DataFrame({'Cell1': cell1, 'Cell2': cell2, 'Distance': distance})
30
+ return spatial_net
31
+
32
+
33
+ def build_spatial_net(adata, annotation, num_neighbour):
34
+ """
35
+ Build spatial neighbourhood matrix for each spot (cell) based on the spatial coordinates.
36
+ """
37
+ logger.info(f'------Building spatial graph based on spatial coordinates...')
38
+
39
+ coor = adata.obsm['spatial']
40
+ if annotation is not None:
41
+ logger.info(f'Cell annotations are provided...')
42
+ spatial_net_list = []
43
+ # Cells with annotations
44
+ for ct in adata.obs[annotation].dropna().unique():
45
+ idx = np.where(adata.obs[annotation] == ct)[0]
46
+ coor_temp = coor[idx, :]
47
+ spatial_net_temp = find_neighbors(coor_temp, min(num_neighbour, coor_temp.shape[0]))
48
+ # Map back to original indices
49
+ spatial_net_temp['Cell1'] = idx[spatial_net_temp['Cell1'].values]
50
+ spatial_net_temp['Cell2'] = idx[spatial_net_temp['Cell2'].values]
51
+ spatial_net_list.append(spatial_net_temp)
52
+ logger.info(f'{ct}: {coor_temp.shape[0]} cells')
53
+
54
+ # Cells labeled as nan
55
+ if pd.isnull(adata.obs[annotation]).any():
56
+ idx_nan = np.where(pd.isnull(adata.obs[annotation]))[0]
57
+ logger.info(f'Nan: {len(idx_nan)} cells')
58
+ spatial_net_temp = find_neighbors(coor, num_neighbour)
59
+ spatial_net_temp = spatial_net_temp[spatial_net_temp['Cell1'].isin(idx_nan)]
60
+ spatial_net_list.append(spatial_net_temp)
61
+ spatial_net = pd.concat(spatial_net_list, axis=0)
62
+ else:
63
+ logger.info(f'Cell annotations are not provided...')
64
+ spatial_net = find_neighbors(coor, num_neighbour)
65
+
66
+ return spatial_net.groupby('Cell1')['Cell2'].apply(np.array).to_dict()
67
+
68
+
69
+ def find_neighbors_regional(cell_pos, spatial_net_dict, coor_latent, config, cell_annotations):
70
+ num_neighbour = config.num_neighbour
71
+ annotations = config.annotation
72
+
73
+ cell_use_pos = spatial_net_dict.get(cell_pos, [])
74
+ if len(cell_use_pos) == 0:
75
+ return []
76
+
77
+ cell_latent = coor_latent[cell_pos, :].reshape(1, -1)
78
+ neighbors_latent = coor_latent[cell_use_pos, :]
79
+ similarity = cosine_similarity(cell_latent, neighbors_latent).reshape(-1)
80
+
81
+ if annotations is not None:
82
+ cell_annotation = cell_annotations[cell_pos]
83
+ neighbor_annotations = cell_annotations[cell_use_pos]
84
+ mask = neighbor_annotations == cell_annotation
85
+ if not np.any(mask):
86
+ return []
87
+ similarity = similarity[mask]
88
+ cell_use_pos = cell_use_pos[mask]
89
+
90
+ if len(similarity) == 0:
91
+ return []
92
+
93
+ indices = np.argsort(-similarity) # descending order
94
+ top_indices = indices[:num_neighbour]
95
+ cell_select_pos = cell_use_pos[top_indices]
96
+ return cell_select_pos
97
+
98
+
99
+ def compute_regional_mkscore(cell_pos, spatial_net_dict, coor_latent, config, cell_annotations,
100
+ ranks, frac_whole, adata_X_bool):
101
+ """
102
+ Compute gmean ranks of a region.
103
+ """
104
+ cell_select_pos = find_neighbors_regional(
105
+ cell_pos, spatial_net_dict, coor_latent, config, cell_annotations
106
+ )
107
+ if len(cell_select_pos) == 0:
108
+ return np.zeros(ranks.shape[1], dtype=np.float16)
109
+
110
+ # Ratio of expression ranks
111
+ ranks_tg = ranks[cell_select_pos, :]
112
+ gene_ranks_region = gmean(ranks_tg, axis=0)
113
+ gene_ranks_region[gene_ranks_region <= 1] = 0
114
+
115
+ if not config.no_expression_fraction:
116
+ # Ratio of expression fractions
117
+ frac_focal = adata_X_bool[cell_select_pos, :].sum(axis=0).A1 / len(cell_select_pos)
118
+ frac_region = frac_focal / frac_whole
119
+ frac_region[frac_region <= 1] = 0
120
+ frac_region[frac_region > 1] = 1
121
+
122
+ # Simultaneously consider the ratio of expression fractions and ranks
123
+ gene_ranks_region = gene_ranks_region * frac_region
124
+
125
+ mkscore = np.exp(gene_ranks_region ** 1.5) - 1
126
+ return mkscore.astype(np.float16, copy=False)
127
+
128
+
129
+ def run_latent_to_gene(config: LatentToGeneConfig):
130
+ logger.info('------Loading the spatial data...')
131
+ adata = sc.read_h5ad(config.hdf5_with_latent_path)
132
+ logger.info(f'Loaded spatial data with {adata.n_obs} cells and {adata.n_vars} genes.')
133
+
134
+ if config.annotation is not None:
135
+ logger.info(f'------Cell annotations are provided as {config.annotation}...')
136
+ initial_cell_count = adata.n_obs
137
+ adata = adata[~pd.isnull(adata.obs[config.annotation]), :]
138
+ logger.info(f'Removed null annotations. Cells retained: {adata.n_obs} (initial: {initial_cell_count}).')
139
+
140
+ # Homologs transformation
141
+ if config.homolog_file is not None:
142
+ logger.info(f'------Transforming the {config.species} to HUMAN_GENE_SYM...')
143
+ homologs = pd.read_csv(config.homolog_file, sep='\t')
144
+ if homologs.shape[1] != 2:
145
+ raise ValueError("Homologs file must have two columns: one for the species and one for the human gene symbol.")
146
+
147
+ homologs.columns = [config.species, 'HUMAN_GENE_SYM']
148
+ homologs.set_index(config.species, inplace=True)
149
+ adata = adata[:, adata.var_names.isin(homologs.index)]
150
+ logger.info(f"{adata.shape[1]} genes retained after homolog transformation.")
151
+ if adata.shape[1] < 100:
152
+ raise ValueError("Too few genes retained in ST data (<100).")
153
+ adata.var_names = homologs.loc[adata.var_names, 'HUMAN_GENE_SYM'].values
154
+ adata = adata[:, ~adata.var_names.duplicated()]
155
+
156
+ # Create mappings
157
+ n_cells = adata.n_obs
158
+ n_genes = adata.n_vars
159
+
160
+ if config.annotation is not None:
161
+ cell_annotations = adata.obs[config.annotation].values
162
+ logger.info(f'Using cell annotations for {len(cell_annotations)} cells.')
163
+ else:
164
+ cell_annotations = None
165
+
166
+ # Build the spatial graph
167
+ logger.info('------Building the spatial graph...')
168
+ spatial_net_dict = build_spatial_net(adata, config.annotation, config.num_neighbour_spatial)
169
+ logger.info('Spatial graph built successfully.')
170
+
171
+ # Extract the latent representation
172
+ logger.info('------Extracting the latent representation...')
173
+ coor_latent = adata.obsm[config.latent_representation]
174
+ coor_latent = coor_latent.astype(np.float32)
175
+ logger.info('Latent representation extracted.')
176
+
177
+ # Geometric mean across slices
178
+ gM = None
179
+ if config.gM_slices is not None:
180
+ logger.info('Geometrical mean across multiple slices is provided.')
181
+ gM_df = pd.read_parquet(config.gM_slices)
182
+ if config.species is not None:
183
+ homologs = pd.read_csv(config.homolog_file, sep='\t')
184
+ if homologs.shape[1] < 2:
185
+ raise ValueError("Homologs file must have at least two columns: one for the species and one for the human gene symbol.")
186
+ homologs.columns = [config.species, 'HUMAN_GENE_SYM']
187
+ homologs.set_index(config.species, inplace=True)
188
+ gM_df = gM_df.loc[gM_df.index.isin(homologs.index)]
189
+ gM_df.index = homologs.loc[gM_df.index, 'HUMAN_GENE_SYM'].values
190
+ common_genes = np.intersect1d(adata.var_names, gM_df.index)
191
+ gM_df = gM_df.loc[common_genes]
192
+ gM = gM_df['G_Mean'].values
193
+ adata = adata[:, common_genes]
194
+ logger.info(f'{len(common_genes)} common genes retained after loading the cross slice geometric mean.')
195
+
196
+ # Compute ranks after taking common genes with gM_slices
197
+ logger.info('------Ranking the spatial data...')
198
+ if not scipy.sparse.issparse(adata.X):
199
+ adata_X = scipy.sparse.csr_matrix(adata.X)
200
+ elif isinstance(adata.X, scipy.sparse.csr_matrix):
201
+ adata_X = adata.X # Avoid copying if already CSR
202
+ else:
203
+ adata_X = adata.X.tocsr()
204
+
205
+ ranks = np.zeros((n_cells, adata.n_vars), dtype=np.float32)
206
+
207
+ for i in tqdm(range(n_cells), desc="Computing ranks per cell"):
208
+ data = adata_X[i, :].toarray().flatten()
209
+ ranks[i, :] = rankdata(data, method='average')
210
+
211
+ if gM is None:
212
+ gM = gmean(ranks, axis=0)
213
+
214
+ # Compute the fraction of each gene across cells
215
+ adata_X_bool = adata_X.astype(bool)
216
+ frac_whole = np.asarray(adata_X_bool.sum(axis=0)).flatten() / n_cells
217
+ logger.info('Gene expression proportion of each gene across cells computed.')
218
+
219
+ # Normalize the ranks
220
+ ranks /= gM
221
+
222
+ # Compute marker scores in parallel
223
+ logger.info('------Computing marker scores...')
224
+ def compute_mk_score_wrapper(cell_pos):
225
+ return compute_regional_mkscore(
226
+ cell_pos, spatial_net_dict, coor_latent, config, cell_annotations, ranks, frac_whole, adata_X_bool
227
+ )
228
+
229
+ mk_scores = [compute_mk_score_wrapper(cell_pos) for cell_pos in tqdm(range(n_cells), desc="Calculating marker scores")]
230
+ mk_score = np.vstack(mk_scores).T
231
+ logger.info('Marker scores computed.')
232
+
233
+ # Remove mitochondrial genes
234
+ gene_names = adata.var_names.values.astype(str)
235
+ mt_gene_mask = ~(np.char.startswith(gene_names, 'MT-') | np.char.startswith(gene_names, 'mt-'))
236
+ mk_score = mk_score[mt_gene_mask, :]
237
+ gene_names = gene_names[mt_gene_mask]
238
+ logger.info(f'Removed mitochondrial genes. Remaining genes: {len(gene_names)}.')
239
+
240
+ # Save the marker scores
241
+ logger.info(f'------Saving marker scores ...')
242
+ output_file_path = Path(config.mkscore_feather_path)
243
+ output_file_path.parent.mkdir(parents=True, exist_ok=True, mode=0o755)
244
+ mk_score_df = pd.DataFrame(mk_score, index=gene_names, columns=adata.obs_names)
245
+ mk_score_df.reset_index(inplace=True)
246
+ mk_score_df.rename(columns={'index': 'HUMAN_GENE_SYM'}, inplace=True)
247
+ mk_score_df.to_feather(output_file_path)
248
+ logger.info(f'Marker scores saved to {output_file_path}.')
249
+
250
+ # Save the modified adata object to disk
251
+ adata.write(config.hdf5_with_latent_path)
252
+ logger.info(f'Modified adata object saved to {config.hdf5_with_latent_path}.')
gsMap/main.py CHANGED
@@ -1,31 +1,31 @@
1
- from gsMap import (__version__)
2
- from gsMap.config import *
3
-
4
- def main():
5
- parser = create_parser()
6
- args = parser.parse_args()
7
- if args.subcommand is None:
8
- parser.print_help()
9
- exit(1)
10
- args.func(
11
- args
12
- )
13
-
14
- def create_parser():
15
- parser = argparse.ArgumentParser(description=" gsMap: genetically informed spatial mapping of cells for complex traits",
16
- formatter_class=argparse.RawTextHelpFormatter,
17
- prog='gsMap'
18
- )
19
- parser.add_argument('--version', '-v', action='version', version=f'gsMap version {__version__}')
20
- subparsers = parser.add_subparsers(dest="subcommand", help="Subcommands", title="Available subcommands")
21
- for subcommand in cli_function_registry.values():
22
- subcommand_parser = subparsers.add_parser(subcommand.name, help=subcommand.description,
23
- formatter_class=argparse.ArgumentDefaultsHelpFormatter
24
- )
25
- subcommand.add_args_function(subcommand_parser)
26
- subcommand_parser.set_defaults(func=subcommand.func)
27
- return parser
28
-
29
-
30
- if __name__ == "__main__":
31
- main()
1
+ from gsMap import (__version__)
2
+ from gsMap.config import *
3
+
4
+ def main():
5
+ parser = create_parser()
6
+ args = parser.parse_args()
7
+ if args.subcommand is None:
8
+ parser.print_help()
9
+ exit(1)
10
+ args.func(
11
+ args
12
+ )
13
+
14
+ def create_parser():
15
+ parser = argparse.ArgumentParser(description=" gsMap: genetically informed spatial mapping of cells for complex traits",
16
+ formatter_class=argparse.RawTextHelpFormatter,
17
+ prog='gsMap'
18
+ )
19
+ parser.add_argument('--version', '-v', action='version', version=f'gsMap version {__version__}')
20
+ subparsers = parser.add_subparsers(dest="subcommand", help="Subcommands", title="Available subcommands")
21
+ for subcommand in cli_function_registry.values():
22
+ subcommand_parser = subparsers.add_parser(subcommand.name, help=subcommand.description,
23
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter
24
+ )
25
+ subcommand.add_args_function(subcommand_parser)
26
+ subcommand_parser.set_defaults(func=subcommand.func)
27
+ return parser
28
+
29
+
30
+ if __name__ == "__main__":
31
+ main()