gsMap 1.62__py3-none-any.whl → 1.64__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.
@@ -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('%.4f neighbors per cell on average.' %(Spatial_Net.shape[0]/adata.n_obs))
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.gcn_hidden1, params.p_drop, act=F.relu,heads = params.nheads)
50
- self.gn2 = GNN(params.gcn_hidden1*params.nheads, params.gcn_hidden2, params.p_drop, act=lambda x: x)
51
- self.gn3 = GNN(params.gcn_hidden1*params.nheads, params.gcn_hidden2, params.p_drop, act=lambda x: x)
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.gcn_hidden2, params.feat_hidden2, params.p_drop))
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.gcn_hidden2, params.feat_hidden2, params.p_drop))
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.gcn_lr, weight_decay = self.params.gcn_decay)
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
@@ -2,4 +2,4 @@
2
2
  Genetics-informed pathogenic spatial mapping
3
3
  '''
4
4
 
5
- __version__ = '1.62'
5
+ __version__ = '1.64'
@@ -1,4 +1,4 @@
1
- import argparse
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, add_Cauchy_combination_args
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
- print("Warn: p-values are exactly 0.")
37
+ logger.info("Warn: p-values are exactly 0.")
36
38
  return 0
37
39
  if any([i == 1 for i in pvalues]):
38
- print("Warn: p-values are exactly 1.")
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
- print(f'------Loading LDSC results of {config.input_ldsc_dir}...')
71
- ldsc_input_file= Path(config.input_ldsc_dir)/f'{config.sample_name}_{config.trait_name}.csv.gz'
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
- print(f'------Loading ST data of {config.input_hdf5_path}...')
78
- spe = sc.read_h5ad(f'{config.input_hdf5_path}')
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
- print(f'------Loading additional annotation...')
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
- print(f'Remove {n_remove}/{len(p_temp)} outliers (median + 3IQR) for {ct}.')
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.output_cauchy_dir)
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)