Completed
Push — master ( 944cb1...b75f2d )
by Haibao
50s
created

tests.print_paths()   A

Complexity

Conditions 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 5
rs 9.4285
1
import sys
2
import os
3
from goatools.obo_parser import GODag
4
5
ROOT = os.path.dirname(os.path.abspath(__file__)) + "/data/"
6
7
8
def print_paths(paths, PRT=sys.stdout):
9
    for path in paths:
10
        PRT.write('\n')
11
        for GO in path:
12
            PRT.write('{}\n'.format(GO))
13
14
15
def chk_results(actual_paths, expected_paths):
16
    for actual_path in actual_paths:
17
        # GOTerm -> list of Strings
18
        actual = [GO.id for GO in actual_path]
19
        if actual not in expected_paths:
20
            raise Exception('ACTUAL {} NOT FOUND IN EXPECTED RESULTS\n'.format(actual))
21
22
23
def test_paths_to_top():
24
    dag = GODag(ROOT + "mini_obo.obo")
25
    expected_paths = [['GO:0000001', 'GO:0000002', 'GO:0000005', 'GO:0000010'],
26
                      ['GO:0000001', 'GO:0000003', 'GO:0000005', 'GO:0000010'],
27
                      ['GO:0000001', 'GO:0000003', 'GO:0000006', 'GO:0000008', 'GO:0000010']]
28
    actual_paths = dag.paths_to_top("GO:0000010")
29
    chk_results(actual_paths, expected_paths)
30
    print_paths(actual_paths)