Skip to content

Commit

Permalink
FIX: Fixing the ordering of the eigenvalues. (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortonjt authored Sep 30, 2019
1 parent 5e71cb0 commit 3ab1ded
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mmvec/q2/_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def paired_omics(microbes: biom.Table,
ranks = ranks - ranks.mean(axis=1).values.reshape(-1, 1)
ranks = ranks - ranks.mean(axis=0)
u, s, v = svds(ranks, k=latent_dim)

s = s[::-1]
u = u[:, ::-1]
v = v[::-1, :]
microbe_embed = u @ np.diag(s)
metabolite_embed = v.T

Expand Down
6 changes: 6 additions & 0 deletions mmvec/q2/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def test_fit(self):
res_biplot.features.shape,
np.array([self.metabolites.shape[0], latent_dim]))

# make sure that the biplot has the correct ordering
self.assertGreater(res_biplot.proportion_explained[0],
res_biplot.proportion_explained[1])
self.assertGreater(res_biplot.eigvals[0],
res_biplot.eigvals[1])


if __name__ == "__main__":
unittest.main()
3 changes: 3 additions & 0 deletions scripts/mmvec
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def paired_omics(microbe_file, metabolite_file,
# Save to an ordination file
ranks = ranks - ranks.mean(axis=0)
u, s, v = svds(ranks, k=latent_dim)
s = s[::-1]
u = u[:, ::-1]
v = v[::-1, :]
microbe_embed = u @ np.diag(s)
metabolite_embed = v.T
pc_ids = ['PC%d' % i for i in range(microbe_embed.shape[1])]
Expand Down

0 comments on commit 3ab1ded

Please sign in to comment.