test_main.py 2.21 KB
Newer Older
1
"""This module contains tests for the survival module."""
2 3 4 5

from lifelines.datasets import load_waltons

from fractalis.analytics.tasks.kaplan_meier_survival.main \
6
    import SurvivalTask
7 8


9
class TestSurvivalTask:
10

11
    task = SurvivalTask()
12 13 14 15 16 17 18 19 20 21

    def test_correct_output_for_simple_input(self):
        df = load_waltons()
        df.insert(0, 'id', df.index)
        duration = df[['id', 'T']].copy()
        duration.insert(1, 'feature', 'duration')
        duration.columns.values[2] = 'value'
        results = self.task.main(durations=[duration],
                                 categories=[],
                                 event_observed=[],
22
                                 estimator='KaplanMeier',
23 24
                                 id_filter=[],
                                 subsets=[])
25 26 27 28
        assert results['stats'][''][0]['timeline']
        assert results['stats'][''][0]['estimate']
        assert results['stats'][''][0]['ci_lower']
        assert results['stats'][''][0]['ci_upper']
29 30 31 32 33 34 35 36 37 38 39 40 41 42

    def test_correct_output_for_complex_input(self):
        df = load_waltons()
        df.insert(0, 'id', df.index)
        duration = df[['id', 'T']].copy()
        duration.insert(1, 'feature', 'duration')
        duration.columns.values[2] = 'value'
        event_observed = df[['id', 'E']].copy()
        event_observed.insert(1, 'feature', 'was_observed')
        categories = df[['id', 'group']].copy()
        categories.insert(1, 'feature', 'group')
        results = self.task.main(durations=[duration],
                                 categories=[categories],
                                 event_observed=[event_observed],
43
                                 estimator='NelsonAalen',
44 45
                                 id_filter=[],
                                 subsets=[])
46 47 48 49 50 51 52 53
        assert results['stats']['control'][0]['timeline']
        assert results['stats']['control'][0]['estimate']
        assert results['stats']['control'][0]['ci_lower']
        assert results['stats']['control'][0]['ci_upper']
        assert results['stats']['miR-137'][0]['timeline']
        assert results['stats']['miR-137'][0]['estimate']
        assert results['stats']['miR-137'][0]['ci_lower']
        assert results['stats']['miR-137'][0]['ci_upper']