gsMap 1.62__py3-none-any.whl → 1.63__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/GNN_VAE/adjacency_matrix.py +1 -1
- gsMap/GNN_VAE/model.py +5 -5
- gsMap/GNN_VAE/train.py +1 -1
- gsMap/__init__.py +1 -1
- gsMap/cauchy_combination_test.py +14 -36
- gsMap/config.py +473 -404
- gsMap/diagnosis.py +273 -0
- gsMap/find_latent_representation.py +22 -86
- gsMap/format_sumstats.py +79 -82
- gsMap/generate_ldscore.py +145 -78
- gsMap/latent_to_gene.py +65 -104
- gsMap/main.py +1 -9
- gsMap/report.py +160 -0
- gsMap/run_all_mode.py +195 -0
- gsMap/spatial_ldsc_multiple_sumstats.py +187 -112
- gsMap/templates/report_template.html +198 -0
- gsMap/utils/__init__.py +0 -0
- gsMap/{generate_r2_matrix.py → utils/generate_r2_matrix.py} +1 -9
- gsMap/{make_annotations.py → utils/make_annotations.py} +1 -43
- gsMap/utils/manhattan_plot.py +639 -0
- gsMap/{regression_read.py → utils/regression_read.py} +1 -1
- gsMap/visualize.py +100 -55
- {gsmap-1.62.dist-info → gsmap-1.63.dist-info}/METADATA +16 -46
- gsmap-1.63.dist-info/RECORD +30 -0
- gsmap-1.62.dist-info/RECORD +0 -24
- /gsMap/{jackknife.py → utils/jackknife.py} +0 -0
- {gsmap-1.62.dist-info → gsmap-1.63.dist-info}/LICENSE +0 -0
- {gsmap-1.62.dist-info → gsmap-1.63.dist-info}/WHEEL +0 -0
- {gsmap-1.62.dist-info → gsmap-1.63.dist-info}/entry_points.txt +0 -0
@@ -66,7 +66,7 @@ def Construct_Adjacency_Matrix(adata,Params, verbose=True):
|
|
66
66
|
#-
|
67
67
|
if verbose:
|
68
68
|
print('The graph contains %d edges, %d cells.' %(Spatial_Net.shape[0], adata.n_obs))
|
69
|
-
print('%.
|
69
|
+
print('%.2f neighbors per cell on average.' %(Spatial_Net.shape[0]/adata.n_obs))
|
70
70
|
#-
|
71
71
|
cells = np.array(adata.obs.index)
|
72
72
|
cells_id_tran = dict(zip(cells, range(cells.shape[0])))
|
gsMap/GNN_VAE/model.py
CHANGED
@@ -46,19 +46,19 @@ class GNN_VAE_Model(nn.Module):
|
|
46
46
|
self.encoder.add_module('encoder_L2', full_block(params.feat_hidden1, params.feat_hidden2, params.p_drop))
|
47
47
|
|
48
48
|
# GNN (GAT)
|
49
|
-
self.gn1 = GNN(params.feat_hidden2, params.
|
50
|
-
self.gn2 = GNN(params.
|
51
|
-
self.gn3 = GNN(params.
|
49
|
+
self.gn1 = GNN(params.feat_hidden2, params.gat_hidden1, params.p_drop, act=F.relu,heads = params.nheads)
|
50
|
+
self.gn2 = GNN(params.gat_hidden1*params.nheads, params.gat_hidden2, params.p_drop, act=lambda x: x)
|
51
|
+
self.gn3 = GNN(params.gat_hidden1*params.nheads, params.gat_hidden2, params.p_drop, act=lambda x: x)
|
52
52
|
|
53
53
|
# Decoder
|
54
54
|
self.decoder = nn.Sequential()
|
55
|
-
self.decoder.add_module('decoder_L1', full_block(params.
|
55
|
+
self.decoder.add_module('decoder_L1', full_block(params.gat_hidden2, params.feat_hidden2, params.p_drop))
|
56
56
|
self.decoder.add_module('decoder_L2', full_block(params.feat_hidden2, params.feat_hidden1, params.p_drop))
|
57
57
|
self.decoder.add_module('decoder_output', nn.Sequential(nn.Linear(params.feat_hidden1, input_dim)))
|
58
58
|
|
59
59
|
# Cluster
|
60
60
|
self.cluster = nn.Sequential()
|
61
|
-
self.cluster.add_module('cluster_L1', full_block(params.
|
61
|
+
self.cluster.add_module('cluster_L1', full_block(params.gat_hidden2, params.feat_hidden2, params.p_drop))
|
62
62
|
self.cluster.add_module('cluster_output', nn.Linear(params.feat_hidden2, self.num_classes))
|
63
63
|
|
64
64
|
def encode(self, x, adj):
|
gsMap/GNN_VAE/train.py
CHANGED
@@ -45,7 +45,7 @@ class Model_Train:
|
|
45
45
|
# Set Model
|
46
46
|
self.model = GNN_VAE_Model(self.params.feat_cell,self.params,self.num_classes).to(device)
|
47
47
|
self.optimizer = torch.optim.Adam(params = list(self.model.parameters()),
|
48
|
-
lr = self.params.
|
48
|
+
lr = self.params.gat_lr, weight_decay = self.params.gcn_decay)
|
49
49
|
|
50
50
|
# Train
|
51
51
|
def run_train(self):
|
gsMap/__init__.py
CHANGED
gsMap/cauchy_combination_test.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import logging
|
2
2
|
from pathlib import Path
|
3
3
|
|
4
4
|
import numpy as np
|
@@ -6,7 +6,9 @@ import pandas as pd
|
|
6
6
|
import scanpy as sc
|
7
7
|
import scipy as sp
|
8
8
|
|
9
|
-
from gsMap.config import CauchyCombinationConfig
|
9
|
+
from gsMap.config import CauchyCombinationConfig
|
10
|
+
|
11
|
+
logger = logging.getLogger(__name__)
|
10
12
|
|
11
13
|
# The fun of cauchy combination
|
12
14
|
def acat_test(pvalues, weights=None):
|
@@ -32,10 +34,10 @@ def acat_test(pvalues, weights=None):
|
|
32
34
|
if any([i == 1 for i in pvalues]) & any([i == 0 for i in pvalues]):
|
33
35
|
raise Exception("Cannot have both 0 and 1 p-values.")
|
34
36
|
if any([i == 0 for i in pvalues]):
|
35
|
-
|
37
|
+
logger.info("Warn: p-values are exactly 0.")
|
36
38
|
return 0
|
37
39
|
if any([i == 1 for i in pvalues]):
|
38
|
-
|
40
|
+
logger.info("Warn: p-values are exactly 1.")
|
39
41
|
return 1
|
40
42
|
if weights == None:
|
41
43
|
weights = [1 / len(pvalues) for i in pvalues]
|
@@ -67,18 +69,18 @@ def acat_test(pvalues, weights=None):
|
|
67
69
|
|
68
70
|
def run_Cauchy_combination(config:CauchyCombinationConfig):
|
69
71
|
# Load the ldsc results
|
70
|
-
|
71
|
-
ldsc_input_file=
|
72
|
+
logger.info(f'------Loading LDSC results of {config.ldsc_save_dir}...')
|
73
|
+
ldsc_input_file= config.get_ldsc_result_file(config.trait_name)
|
72
74
|
ldsc = pd.read_csv(ldsc_input_file, compression='gzip')
|
73
75
|
ldsc.spot = ldsc.spot.astype(str).replace('\.0', '', regex=True)
|
74
76
|
ldsc.index = ldsc.spot
|
75
77
|
if config.meta is None:
|
76
78
|
# Load the spatial data
|
77
|
-
|
78
|
-
spe = sc.read_h5ad(f'{config.
|
79
|
+
logger.info(f'------Loading ST data of {config.hdf5_with_latent_path}...')
|
80
|
+
spe = sc.read_h5ad(f'{config.hdf5_with_latent_path}')
|
79
81
|
|
80
82
|
common_cell = np.intersect1d(ldsc.index, spe.obs_names)
|
81
|
-
spe = spe[common_cell
|
83
|
+
spe = spe[common_cell]
|
82
84
|
ldsc = ldsc.loc[common_cell]
|
83
85
|
|
84
86
|
# Add the annotation
|
@@ -86,7 +88,7 @@ def run_Cauchy_combination(config:CauchyCombinationConfig):
|
|
86
88
|
|
87
89
|
elif config.meta is not None:
|
88
90
|
# Or Load the additional annotation (just for the macaque data at this stage: 2023Nov25)
|
89
|
-
|
91
|
+
logger.info(f'------Loading additional annotation...')
|
90
92
|
meta = pd.read_csv(config.meta, index_col=0)
|
91
93
|
meta = meta.loc[meta.slide == config.slide]
|
92
94
|
meta.index = meta.cell_id.astype(str).replace('\.0', '', regex=True)
|
@@ -115,7 +117,7 @@ def run_Cauchy_combination(config:CauchyCombinationConfig):
|
|
115
117
|
|
116
118
|
# Outlier: -log10(p) < median + 3IQR && len(outlier set) < 20
|
117
119
|
if (0 < n_remove < 20):
|
118
|
-
|
120
|
+
logger.info(f'Remove {n_remove}/{len(p_temp)} outliers (median + 3IQR) for {ct}.')
|
119
121
|
p_cauchy_temp = acat_test(p_use)
|
120
122
|
else:
|
121
123
|
p_cauchy_temp = acat_test(p_temp)
|
@@ -129,7 +131,7 @@ def run_Cauchy_combination(config:CauchyCombinationConfig):
|
|
129
131
|
p_tissue = pd.DataFrame(data)
|
130
132
|
p_tissue.columns = ['p_cauchy', 'p_median', 'annotation']
|
131
133
|
# Save the results
|
132
|
-
output_dir = Path(config.
|
134
|
+
output_dir = Path(config.cauchy_save_dir)
|
133
135
|
output_dir.mkdir(parents=True, exist_ok=True, mode=0o755)
|
134
136
|
output_file = output_dir / f'{config.sample_name}_{config.trait_name}.Cauchy.csv.gz'
|
135
137
|
p_tissue.to_csv(
|
@@ -137,27 +139,3 @@ def run_Cauchy_combination(config:CauchyCombinationConfig):
|
|
137
139
|
compression='gzip',
|
138
140
|
index=False,
|
139
141
|
)
|
140
|
-
|
141
|
-
|
142
|
-
if __name__ == '__main__':
|
143
|
-
TEST = True
|
144
|
-
if TEST:
|
145
|
-
test_dir = '/storage/yangjianLab/chenwenhao/projects/202312_gsMap/data/gsMap_test/Nature_Neuroscience_2021'
|
146
|
-
name = 'Cortex_151507'
|
147
|
-
|
148
|
-
config = CauchyCombinationConfig(
|
149
|
-
input_hdf5_path= f'{test_dir}/{name}/hdf5/{name}_add_latent.h5ad',
|
150
|
-
input_ldsc_dir=
|
151
|
-
f'/storage/yangjianLab/chenwenhao/projects/202312_gsMap/data/gsMap_test/Nature_Neuroscience_2021/snake_workdir/Cortex_151507/ldsc/',
|
152
|
-
sample_name=name,
|
153
|
-
annotation='layer_guess',
|
154
|
-
output_cauchy_dir='/storage/yangjianLab/chenwenhao/projects/202312_gsMap/data/gsMap_test/Nature_Neuroscience_2021/snake_workdir/Cortex_151507/cauchy/',
|
155
|
-
trait_name='adult1_adult2_onset_asthma',
|
156
|
-
)
|
157
|
-
else:
|
158
|
-
|
159
|
-
parser = argparse.ArgumentParser(description="Run Cauchy Combination Analysis")
|
160
|
-
add_Cauchy_combination_args(parser)
|
161
|
-
args = parser.parse_args()
|
162
|
-
config = CauchyCombinationConfig(**vars(args))
|
163
|
-
run_Cauchy_combination(config)
|