Пример #1
0
 def setUp(self):
     super(SetUpSparseDataMTL, self).setUp()
     self._task_objects = [
         TaskDataStub(sparse=True),
         TaskDataStub(sparse=True)
     ]
     self._task_objects[0].tasks_from_metadata = False
     self._task_objects[1].tasks_from_metadata = False
    def test_result_processor_perfect(self):
        self.workflow._task_objects = [TaskDataStub()]
        self.workflow._load_tasks()

        beta1 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [0.5, 0]]),
                             ["gene1", "gene2", "gene4", "gene6"],
                             ["gene3", "gene6"])
        beta2 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [0.5, 0]]),
                             ["gene1", "gene2", "gene4", "gene6"],
                             ["gene3", "gene6"])
        beta3 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [0.5, 0.2]]),
                             ["gene1", "gene2", "gene4", "gene6"],
                             ["gene3", "gene6"])
        rb1 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [0.25, 0]]),
                           ["gene1", "gene2", "gene4", "gene6"],
                           ["gene3", "gene6"])
        rb2 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [1, 0]]),
                           ["gene1", "gene2", "gene4", "gene6"],
                           ["gene3", "gene6"])
        rb3 = pd.DataFrame(np.array([[0, 1], [0, 1], [1, 0], [0.5, 0.5]]),
                           ["gene1", "gene2", "gene4", "gene6"],
                           ["gene3", "gene6"])

        self.workflow.startup_finish()
        self.workflow.emit_results(
            [[beta1, beta1], [beta2, beta2], [beta3, beta3]],
            [[rb1, rb1], [rb2, rb2], [rb3, rb3]], self.workflow.gold_standard,
            self.workflow.priors_data)
        self.assertAlmostEqual(self.workflow.results.score, 1)
    def test_num_props(self):

        self.assertIsNone(self.workflow._num_obs)
        self.assertIsNone(self.workflow._num_tfs)
        self.assertIsNone(self.workflow._num_genes)

        task_obs = TaskDataStub.expression_matrix.shape[1]
        task_tfs = TaskDataStub.priors_data.shape[1]
        task_genes = TaskDataStub.expression_matrix.shape[0]

        self.workflow._task_objects = [
            TaskDataStub(), TaskDataStub(),
            TaskDataStub()
        ]

        self.assertEqual(self.workflow._num_obs, task_obs * 3)
        self.assertEqual(self.workflow._num_genes, task_genes)
        self.assertEqual(self.workflow._num_tfs, task_tfs)
Пример #4
0
    def test_align_task_priors(self):
        self.workflow.set_crossvalidation_parameters(
            split_gold_standard_for_crossvalidation=True, cv_split_ratio=0.2)
        self.workflow._process_default_priors()

        gs_genes = self.workflow.gold_standard.shape[0]
        self.workflow._task_objects = [
            copy.deepcopy(TaskDataStub()),
            copy.deepcopy(TaskDataStub()),
            copy.deepcopy(TaskDataStub())
        ]

        self.assertTupleEqual(self.workflow._task_objects[0].priors_data.shape,
                              TaskDataStub.priors_data.shape)

        self.workflow._process_task_priors()

        expect_size = 2
        prior_sizes = list(
            map(lambda x: x.priors_data.shape[0], self.workflow._task_objects))

        self.assertListEqual([expect_size] * 3, prior_sizes)
    def test_taskdata_processing(self):
        self.workflow._task_objects = [TaskDataStub()]
        # Test the TaskData processing
        self.assertEqual(len(self.workflow._task_objects), 1)
        self.workflow._load_tasks()
        self.assertEqual(len(self.workflow._task_objects), 3)

        # Test processing the TaskData objects into data structures in MultitaskLearningWorkflow
        self.assertEqual(self.workflow._n_tasks, 3)
        self.assertEqual(
            list(
                map(lambda x: x.expression_matrix.shape,
                    self.workflow._task_objects)), [(6, 2), (6, 4), (6, 4)])
        self.assertEqual(
            list(map(lambda x: x.meta_data.shape,
                     self.workflow._task_objects)), [(2, 2), (4, 2), (4, 2)])
Пример #6
0
 def test_task_processing(self):
     self.workflow._task_objects = [TaskDataStub()]
     self.workflow._load_tasks()
     self.workflow.startup_finish()
     self.assertEqual(self.workflow._regulators.tolist(),
                      ["gene3", "gene6"])
     self.assertEqual(self.workflow._targets.tolist(),
                      ["gene1", "gene2", "gene4", "gene6"])
     self.assertEqual(len(self.workflow._task_design), 3)
     self.assertEqual(len(self.workflow._task_response), 3)
     self.assertEqual(len(self.workflow._task_bootstraps), 3)
     pdt.assert_frame_equal(self.workflow._task_design[0].to_df(),
                            pd.DataFrame([[16., 5.], [15., 15.]],
                                         index=["gene3", "gene6"],
                                         columns=["0", "6"]).T,
                            check_dtype=False)
     pdt.assert_frame_equal(self.workflow._task_response[0].to_df(),
                            pd.DataFrame(
                                [[2, 3], [28, 27], [16, 5], [3, 4]],
                                index=["gene1", "gene2", "gene4", "gene6"],
                                columns=["0", "6"]).T,
                            check_dtype=False)
Пример #7
0
 def setUp(self):
     super(SetUpDenseDataMTL, self).setUp()
     self._task_objects = [TaskDataStub(), TaskDataStub()]
     self._task_objects[0].tasks_from_metadata = False
     self._task_objects[1].tasks_from_metadata = False
 def setUp(self):
     super(TestMultitaskFactory, self).setUp()
     self._task_objects = [TaskDataStub(), TaskDataStub()]
     self._task_objects[0].tasks_from_metadata = False
     self._task_objects[1].tasks_from_metadata = False