Skip to content

Commit

Permalink
✅ update test
Browse files Browse the repository at this point in the history
- probable reason: scikit-learn is not a dependency in requirments_dev.txt
- TSNE default probably have changed?
  • Loading branch information
enryH committed Sep 2, 2024
1 parent b2ec431 commit 2057646
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion acore/exploratory_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def run_tsne(data, drop_cols=['sample', 'subject'], group='group', annotation_co
if len(list(set(annotation_cols).intersection(data.columns))) > 0:
annotations = data[annotation_cols]
if X.size > 0:
tsne = TSNE(n_components=components, verbose=0, perplexity=perplexity, n_iter=n_iter, init=init)
tsne = TSNE(n_components=components, verbose=0, perplexity=perplexity, max_iter=n_iter, init=init)
X = tsne.fit_transform(X)
args = {"x_title": "C1", "y_title": "C2"}
if components == 2:
Expand Down
24 changes: 13 additions & 11 deletions tests/test_exploratory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,35 @@ def test_run_pca(self):
pd.DataFrame({
'group': ['A', 'A', 'B', 'B'],
'x': [0.877154, -3.883458, -1.550791, 4.557095],
'y': [2.815737, 0.420979, -2.278209, -0.958507],
'y': [-2.815737, -0.420979, 2.278209, 0.958507],
}),
pd.DataFrame({
'x': [0.958489, 0.092382, 0.269749],
'y': [0.235412, -0.790179, -0.565861],
'y': [-0.235412, 0.790179, 0.565861],
'value': [0.986975, 0.795561, 0.626868]
},
index=['protein2', 'protein1', 'protein3']),
pd.Series([0.71760534, 0.26139782])
)

result, _ = ea.run_pca(self.data, drop_cols=[], annotation_cols=[], group='group', components=components, dropna=True)

exp_dict = {'x_title': 'PC1 (0.72)',
'y_title': 'PC2 (0.26)', 'group': 'group'}
result, annotation = ea.run_pca(self.data, drop_cols=[], annotation_cols=[], group='group', components=components, dropna=True)
assert annotation == exp_dict
# results: tuple of 3 DFs: components, loadings, explained_variance
pd.testing.assert_frame_equal(result[0], expected_result[0], check_exact=False)
pd.testing.assert_frame_equal(result[1], expected_result[1], check_exact=False)
pd.testing.assert_series_equal(pd.Series(result[2]), expected_result[2], check_exact=False, check_dtype=False)

def test_run_tsne(self):
components = 2
expected_result = pd.DataFrame({
'group': ['A', 'A', 'B', 'B'],
'x': [-14.171760, -25.144415, 38.065639, 49.065693],
'y': [23.172457, -40.054382, -50.829048, 12.445741]})

'x': [-113.341728, 36.020717, 57.2992514, -134.729141],
'y': [131.169082, -59.616630, 110.601203, -39.086254]
})
result, _ = ea.run_tsne(self.data, drop_cols=['sample', 'subject'], group='group', components=components, perplexity=3, n_iter=1000, init='pca', dropna=True)

pd.testing.assert_frame_equal(result['tsne'], expected_result, check_exact=False, check_dtype=False)
result = result['tsne']
pd.testing.assert_frame_equal(result, expected_result, check_exact=False, check_dtype=False)

def test_run_umap(self):
_ = ea.run_umap(self.data, drop_cols=['sample', 'subject'], group='group', n_neighbors=10, min_dist=0.3, metric='cosine', dropna=True)
Expand Down

0 comments on commit 2057646

Please sign in to comment.