Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JiayuSuPKU committed Sep 19, 2023
1 parent e909b0e commit 390c511
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion simulation/002_zone2counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
type = str,
default = None,
help = 'Output directory. Default: None to use the same directory as the input.')
prs.add_argument('-oa','--output-anndata', action=argparse.BooleanOptionalAction, default=True,
prs.add_argument('-oa','--output-anndata', action='store_true',
help = 'Whether to output entire anndata objects for synthetic spatial data ' \
'and paired single cell data. Default: True.' )

Expand Down
2 changes: 1 addition & 1 deletion smoother/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def calc_corr_decay_stats(self, coords, min_k = 0, max_k = 50, cov_ind = 0, retu
try:
cov = torch.cholesky_inverse(torch.linalg.cholesky(self.inv_cov[cov_ind].to_dense()))
except RuntimeError as exc:
raise RuntimeError(f"The current loss ({self.prior}, l={self.rho}) "
raise RuntimeError(f"The current loss ({self.prior}, rho={self.rho}) "
"contains an improper spatial covariance structure. "
"Please use a different spatial prior or scale "
"if you intend to calculate covariance decay.") from exc
Expand Down
4 changes: 2 additions & 2 deletions smoother/simulation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from scipy.sparse import csr_matrix,lil_matrix
import anndata
from tqdm import tqdm
from smoother.weights import _coordinate_to_weights_knn
from smoother.weights import coordinate_to_weights_knn_dense


def sample_cell_indices(generation_snrna, annot_label, cell_count_df, cell_capture_eff_df):
Expand Down Expand Up @@ -66,7 +66,7 @@ def smooth_by_neighbors(shared_prop, locations2cells_matrix, coords, n_experimen
smoothed cell index matrix (n_spots x n_cells).
'''
# compute adjacency matrix
swm = _coordinate_to_weights_knn(coords, k=4, row_scale=True) * shared_prop
swm = coordinate_to_weights_knn_dense(coords, k=4, row_scale=True) * shared_prop
swm = swm.fill_diagonal_(1 - shared_prop)

# compute smoothed cell index matrix
Expand Down
11 changes: 9 additions & 2 deletions smoother/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ def normalize_minmax(x, min_zero = True, return_scale = False):

return x_norm

def _pca(features, dim):
"""Dimension reduction by PCA."""
def _z_score(features):
"""Z-score standardization."""
# standardize and remove constant features
# features.shape: num_feature x num_spot
features_var = features.std(1) # feature level variance
features_scaled = (features - features.mean(1, keepdim=True)) / features_var[:, None]
features_scaled = features_scaled[features_var > 0,:]
return features_scaled

def _pca(features, dim):
"""Dimension reduction by PCA."""
# standardize and remove constant features
features_scaled = _z_score(features)

# run pca
torch.manual_seed(0) # for repeatability, fix the random seed for pca_lowrank
Expand Down

0 comments on commit 390c511

Please sign in to comment.