Skip to content

Commit

Permalink
Merge pull request Reed-CompBio#185 from ntalluri/pca-robustness
Browse files Browse the repository at this point in the history
Added test to check robustness of PCA representation
  • Loading branch information
agitter authored Sep 10, 2024
2 parents 1957465 + 1bf6bb7 commit cd1efd7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ def test_pca(self):

assert coord.equals(expected)

def test_pca_robustness(self):
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-s1/s1.txt', INPUT_DIR + 'test-data-s2/s2.txt', INPUT_DIR + 'test-data-s3/s3.txt'])
expected = pd.read_table(EXPECT_DIR + 'expected-pca-coordinates.tsv')
expected = expected.round(5)
for _ in range(5):
dataframe_shuffled = dataframe.sample(frac=1, axis=1) # permute the columns
ml.pca(dataframe_shuffled, OUT_DIR + 'pca-shuffled-columns.png', OUT_DIR + 'pca-shuffled-columns-variance.txt',
OUT_DIR + 'pca-shuffled-columns-coordinates.tsv')
coord = pd.read_table(OUT_DIR + 'pca-shuffled-columns-coordinates.tsv')
coord = coord.round(5) # round values to 5 digits to account for numeric differences across machines
coord.sort_values(by='algorithm', ignore_index=True, inplace=True)

assert coord.equals(expected)

for _ in range(5):
dataframe_shuffled = dataframe.sample(frac=1, axis=0) # permute the rows
ml.pca(dataframe_shuffled, OUT_DIR + 'pca-shuffled-rows.png', OUT_DIR + 'pca-shuffled-rows-variance.txt',
OUT_DIR + 'pca-shuffled-rows-coordinates.tsv')
coord = pd.read_table(OUT_DIR + 'pca-shuffled-rows-coordinates.tsv')
coord = coord.round(5) # round values to 5 digits to account for numeric differences across machines
coord.sort_values(by='algorithm', ignore_index=True, inplace=True)

assert coord.equals(expected)


def test_hac_horizontal(self):
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-s1/s1.txt', INPUT_DIR + 'test-data-s2/s2.txt', INPUT_DIR + 'test-data-s3/s3.txt'])
ml.hac_horizontal(dataframe, OUT_DIR + 'hac-horizontal.png', OUT_DIR + 'hac-clusters-horizontal.txt')
Expand Down

0 comments on commit cd1efd7

Please sign in to comment.