def test_mapping_split_file(self):

        bhm.main("transaction_test_split", "./test/test_simple_batch.json", "./test/configuration_to_build_matrix.json")
        bhm.main(
            "transaction_test_combined", "./test/test_all_file_batch.json", "./test/configuration_to_build_matrix.json"
        )

        f5s1 = h5py.File("./test/transaction_test_split_1.hdf5", "r")
        f5s2 = h5py.File("./test/transaction_test_split_2.hdf5", "r")
        f5s3 = h5py.File("./test/transaction_test_split_3.hdf5", "r")

        f5c = h5py.File("./test/transaction_test_combined_1.hdf5", "r")

        lab_category_count_1 = f5s1["/independent/classes/lab/category/core_array"][...]
        lab_category_count_2 = f5s2["/independent/classes/lab/category/core_array"][...]
        lab_category_count_3 = f5s3["/independent/classes/lab/category/core_array"][...]

        lab_category_count_c = f5c["/independent/classes/lab/category/core_array"][...]

        # Concatenate to create a single file
        lab_category_count_cs = np.concatenate((lab_category_count_1, lab_category_count_2, lab_category_count_3))

        self.assertEquals(lab_category_count_c.shape, lab_category_count_cs.shape)
        self.assertEquals(np.sum(lab_category_count_c), np.sum(lab_category_count_cs))

        # Read the combined file
        f5ca = h5py.File("./test/transaction_test_split_combined.hdf5", "r")
        lab_category_count_ca = f5ca["/independent/classes/lab/category/core_array"][...]

        self.assertEqual(lab_category_count_c.shape, lab_category_count_ca.shape)
        self.assertEquals(np.sum(lab_category_count_c), np.sum(lab_category_count_ca))
    def test_mapping_single_file(self):

        if os.path.exists("./test/transaction_test_1.hdf5"):
            os.remove("./test/transaction_test_1.hdf5")

        bhm.main("transaction_test", "./test/test_single_file_batch.json", "./test/configuration_to_build_matrix.json")
        f5 = h5py.File("./test/transaction_test_1.hdf5", "r")
        dca = f5["/independent/classes/discharge/core_array"][...]
        self.assertEquals(dca.shape, (2, 5))

        dcac = f5["/independent/classes/discharge/column_annotations"][...]
        self.assertEquals(dcac.shape, (3, 5))

        lab_count = f5["/independent/classes/lab/count/core_array"][...]
        lab_count_c = f5["/independent/classes/lab/count/column_annotations"][...]

        self.assertEqual(lab_count.tolist(), [[4.0, 0.0], [4.0, 1.0]])
        self.assertEqual(lab_count_c.tolist(), [["BUN", "Troponin"], ["value", "value"], ["count", "count"]])

        lab_category_count = f5["/independent/classes/lab/category/core_array"][...]
        lab_category_count_c = f5["/independent/classes/lab/category/column_annotations"][...]

        self.assertEqual(lab_category_count.tolist(), [[4.0, 0.0, 0.0, 0.0], [1.0, 1.0, 2.0, 1.0]])
        self.assertEqual(
            lab_category_count_c.tolist(),
            [["BUN", "BUN", "BUN", "Troponin"], ["high", "low", "normal", "extreme"], ["", "", "", ""]],
        )

        self.assertEquals(np.sum(lab_category_count), np.sum(lab_count), "Sums should be equal")

        diagnosis1 = f5["/independent/classes/diagnosis/core_array"][...]
        diagnosis_c = f5["/independent/classes/diagnosis/column_annotations"]

        self.assertTrue(np.sum(diagnosis1) > 0)
    def test_filter_and_first_set(self):

        directory = "./test/"
        bhm.main("filter_test", "./test/test_single_file_batch.json", "./test/configuration_to_build_matrix.json")
        f5 = h5py.File("./test/filter_test_1.hdf5", "r")

        lab_first = f5["/independent/classes/lab/first/core_array"][...]
        lab_first_day = f5["/independent/classes/lab/first_day/core_array"][...]

        self.assertNotEqual(lab_first.tolist(), lab_first_day.tolist())
    def test_mapping_single_compressed_file(self):

        if os.path.exists("./test/transaction_test_1.hdf5"):
            os.remove("./test/transaction_test_1.hdf5")

        bhm.main("transaction_test", "./test/test_all_file_batch_gz.json", "./test/configuration_to_build_matrix.json")