Skip to content

Commit

Permalink
Merge pull request #13 from openproblems-bio/marco/add-correlation-co…
Browse files Browse the repository at this point in the history
…ntrol

Simplified pearson and added spearman correlation baseline
  • Loading branch information
janursa authored Sep 11, 2024
2 parents cf3016f + 275db7f commit 3aa0f1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 35 deletions.
31 changes: 0 additions & 31 deletions .gitignore

This file was deleted.

10 changes: 6 additions & 4 deletions src/control_methods/baseline_corr/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import anndata as ad
import scanpy as sc
from tqdm import tqdm
from sklearn.preprocessing import StandardScaler
from scipy.stats import spearmanr

## VIASH START
par = {
}
## VIASH END
def create_corr_net(X: np.ndarray, groups: np.ndarray):
def create_corr_net(X: np.ndarray, groups: np.ndarray, method="pearson"):
grns = []
for group in tqdm(np.unique(groups), desc="Processing groups"):
X_sub = X[groups == group, :]
X_sub = StandardScaler().fit_transform(X_sub)
grn = np.dot(X_sub.T, X_sub) / X_sub.shape[0]
if method is "pearson":
grn = np.corrcoef(X_sub.T)
elif method is "spearman":
grn = spearmanr(X_sub).statistic
grns.append(grn)
return np.mean(grns, axis=0)
print('Read data')
Expand Down

0 comments on commit 3aa0f1e

Please sign in to comment.