Skip to content

Commit

Permalink
Pin dependencies to avoid breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertDominguez committed Jun 25, 2024
1 parent 3b9e310 commit a0cc987
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions neural_admixture/model/initializations.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get_decoder_init(cls, X: da.core.Array, K: Union[Iterable, int], path: Union
pickle.dump(pca_obj, fb)
except Exception as e:
raise e
assert pca_obj.n_features_ == X.shape[1], 'Computed PCA and training data do not have same number of SNPs'
pca_n_feat = pca_obj.n_features_ if hasattr(pca_obj, "n_features_") else pca_obj.n_features_in_
assert pca_n_feat == X.shape[1], 'Computed PCA and training data do not have same number of SNPs'
log.info('Projecting data...')
X_pca = pca_obj.transform(X).compute()
log.info('Running KMeans on projected data...')
Expand Down Expand Up @@ -132,7 +133,7 @@ def get_decoder_init(cls, X: da.core.Array, K: Union[Iterable, int], path: str,
raise FileNotFoundError
else:
raise FileNotFoundError
except FileNotFoundError as fnfe:
except FileNotFoundError as _:
log.info(f'{n_components}D PCA object not found. Performing PCA...')
pca_obj = DaskIncrementalPCA(n_components=n_components, random_state=42, batch_size=batch_size)
pca_obj.fit(X)
Expand All @@ -141,7 +142,8 @@ def get_decoder_init(cls, X: da.core.Array, K: Union[Iterable, int], path: str,
pickle.dump(pca_obj, fb)
except Exception as e:
raise e
assert pca_obj.n_features_ == X.shape[1], 'Computed PCA and training data do not have same number of SNPs'
pca_n_feat = pca_obj.n_features_ if hasattr(pca_obj, "n_features_") else pca_obj.n_features_in_
assert pca_n_feat == X.shape[1], 'Computed PCA and training data do not have same number of SNPs'
log.info(f'Projecting data to {n_components} dimensions...')
X_proj = pca_obj.transform(X).compute()
if not isinstance(K, Iterable):
Expand Down
2 changes: 2 additions & 0 deletions neural_admixture/src/snp_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def _impute(G: da.core.Array, method: Literal["zero", "mean"]="mean") -> da.core
Returns:
da.core.Array: imputed genotype array
"""
na_cols = da.all(da.isnan(G), axis=0).compute()
G = G[:, ~na_cols]
if da.isnan(G).any().compute():
log.warning(f"Data contains missing values. Will perform {method}-imputation.")
if method == "zero":
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ install_requires =
configargparse>=1.5.3
Cython>=0.29.30
codetiming>=1.3.0
dask>=2022.5.0
dask>=2022.5.0,<2024.2
dask-ml>=2022.5.27
h5py>=3.1.0
matplotlib>=3.3.4
numpy>=1.21.0
numpy>=1.21.0,<2.0.0
pandas>=1.2.4
pandas_plink>=2.2.9
py_pcha>=0.1.3
Expand Down

0 comments on commit a0cc987

Please sign in to comment.