Skip to content

Commit

Permalink
Merge branch 'ete4' of github.com:etetoolkit/ete into ete4
Browse files Browse the repository at this point in the history
  • Loading branch information
jordibc committed Feb 21, 2024
2 parents 8589f3b + 365dc63 commit af776fa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
42 changes: 42 additions & 0 deletions tests/redundant/test_arraytable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import unittest

import numpy as np

from ete4 import ArrayTable
from .. import datasets as ds


class Test_Core_ArrayTable(unittest.TestCase):
"""Tests reading clustering or phylogenetic profile data."""

def test_arraytable_parser(self):
"""Test reading numeric tables."""
A = ArrayTable(ds.expression)

self.assertEqual(A.get_row_vector("A").tolist(),
[-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58])
self.assertEqual(A.get_several_row_vectors(["A", "C"]).tolist(),
[[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58],
[-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]])

self.assertEqual(A.get_several_column_vectors(["col2", "col7"]).tolist(),
[[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25],
[0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]])

self.assertEqual(A.get_column_vector("col4").tolist(),
[0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3])

A.remove_column("col4")
self.assertTrue(A.get_column_vector("col4") is None)

Abis = A.merge_columns({"merged1": ["col1", "col2"],
"merged2": ["col5", "col6"]}, "mean")

self.assertTrue((np.round(Abis.get_column_vector("merged1"), 3) ==
[-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39]).all())
# Continue this......
# Sure. C'mon Jaime, you can do it!


if __name__ == '__main__':
unittest.main()
51 changes: 23 additions & 28 deletions tests/test_arraytable.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import unittest
"""
Tests reading clustering or phylogenetic profile data.
"""

import numpy as np

from ete4 import ArrayTable
from . import datasets as ds


class Test_Core_ArrayTable(unittest.TestCase):
"""Tests reading clustering or phylogenetic profile data."""
def test_arraytable_parser():
"""Test reading numeric tables and simple manipulations."""
A = ArrayTable(ds.expression)

def test_arraytable_parser(self):
"""Test reading numeric tables."""
A = ArrayTable(ds.expression)
assert (A.get_row_vector("A").tolist() ==
[-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58])

self.assertEqual(A.get_row_vector("A").tolist(),
[-1.23, -0.81, 1.79, 0.78,-0.42,-0.69, 0.58])
self.assertEqual(A.get_several_row_vectors(["A", "C"]).tolist(),
[[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58],
[-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]])
assert (A.get_several_row_vectors(["A", "C"]).tolist() ==
[[-1.23, -0.81, 1.79, 0.78, -0.42, -0.69, 0.58],
[-2.19, 0.13, 0.65, -0.51, 0.52, 1.04, 0.36]])

self.assertEqual(A.get_several_column_vectors(["col2", "col7"]).tolist(),
[[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25],
[0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]])
assert (A.get_column_vector("col4").tolist() ==
[0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3])

self.assertEqual(A.get_column_vector("col4").tolist(),
[0.78, 0.36, -0.51, -0.76, 0.07, -0.14, 0.23, -0.3])
assert (A.get_several_column_vectors(["col2", "col7"]).tolist() ==
[[-0.81, -0.94, 0.13, -0.98, -0.83, -1.11, -1.17, -1.25],
[0.58, 1.12, 0.36, 0.93, 0.65, 0.48, 0.26, 0.77]])

A.remove_column("col4")
self.assertTrue(A.get_column_vector("col4") is None)
A.remove_column("col4")
assert A.get_column_vector("col4") is None

Abis = A.merge_columns({"merged1": ["col1", "col2"],
"merged2": ["col5", "col6"]}, "mean")
Abis = A.merge_columns({"merged1": ["col1", "col2"],
"merged2": ["col5", "col6"]}, "mean")
assert (np.round(Abis.get_column_vector("merged1"), 3).tolist() ==
[-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39])

self.assertTrue((np.round(Abis.get_column_vector("merged1"), 3) ==
[-1.02, -1.35, -1.03, -1.1, -1.15, -1.075, -1.37, -1.39]).all())
# Continue this......
# Sure. C'mon Jaime, you can do it!


if __name__ == '__main__':
unittest.main()
# TODO: More tests. Jaime, you can do it!

0 comments on commit af776fa

Please sign in to comment.