Completed
Push — master ( ca146f...1b2584 )
by
unknown
53s
created

test_optional_attrs()   A

Complexity

Conditions 2

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 32
rs 9.112
c 7
b 0
f 0
1
#!/usr/bin/env python
2
"""Test the loading of all optional GO term attributes.
3
4
Maximum number of fields on a GO term:
5
6
  required:
7
      1 name
8
      1 namespace
9
     10 is_a
10
     16 alt_id
11
12
  optional scalar:
13
      1 def
14
      1 comment
15
16
  optional set:
17
     12 subset    goslim_mouse
18
19
  optional special:
20
      3 relationship
21
    284 synonym   synonym: "peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
22
    827 xref      Wikipedia:Zygotene
23
24
25
In go-basic.obo fmt(1.2) rel(2018-02-11) 15,329 out of 47,120 GO Terms have synonym types:
26
  90444 EXACT
27
  18574 NARROW
28
  15037 RELATED
29
   3562 BROAD
30
"""
31
32
from __future__ import print_function
33
34
import sys
35
from goatools.test_data.optional_attrs import OptionalAttrs
36
37
38
def test_optional_attrs():
39
    """Test loading optional GO term field, 'synonym'."""
40
    prt = sys.stdout
41
    prt = None
42
    # Summary for all fields in a GO DAG
43
    opt_attrs = ['def', 'comment', 'subset', 'synonym', 'xref', 'relationship']
44
    obj = OptionalAttrs("go-basic.obo", opt_attrs)
45
    obj.prt_summary()
46
47
    # SCALAR: Check optional attributes whose information is stored in string
48
    for attr in ['defn', 'comment']:
49
        # Check that all GOTerms have a string; ACTUAL matches EXPECTED if present, else ""
50
        obj.chk_str(attr)
51
        print("PASSED COUNT TEST: {ATTR}".format(ATTR=attr))
52
53
    # SET: Check optional attributes whose information is stored in a set
54
    # Check that all GO IDs that should have relationships do have relationships.
55
    # For each GO ID, check that actual count of a set attr equals expected count
56
    obj.chk_set('subset')
57
    print("PASSED: subset")
58
59
    # RELATIONSHIP: Stored in a dict with values being sets of GO IDs
60
    obj.chk_relationships()
61
    print("PASSED: relationship")
62
63
    # SYNONYM: Synonyms are stored in a list of namedtuples
64
    obj.chk_synonyms(prt)
65
    print("PASSED: synonyms")
66
67
    # XREF: Stored in a set
68
    obj.chk_xref(prt)
69
    print("PASSED: xrefs")
70
71
def test_no_optional_attrs():
72
    """Test loading DAG with no optional attributes."""
73
    obj = OptionalAttrs("go-basic.obo", None)
74
    obj.chk_no_optattrs()
75
    obj = OptionalAttrs("go-basic.obo", [])
76
    obj.chk_no_optattrs()
77
    obj = OptionalAttrs("go-basic.obo", set([]))
78
    obj.chk_no_optattrs()
79
80
81
if __name__ == '__main__':
82
    test_no_optional_attrs()
83
    test_optional_attrs()
84
85
# Copyright (C) 2010-2018, H Tang et al., All rights reserved.
86