-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig_check.py
150 lines (117 loc) · 3.76 KB
/
config_check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
Functions for identifying the type of
:py:class:`~enrich2.storemanager.StoreManager` derived object associated with a
given configuration object (decoded from a JSON file as described `here
<https://docs.python.org/2/library/json.html>`_).
"""
def is_experiment(cfg):
"""
Check if the given configuration object specifies an
:py:class:`~enrich2.experiment.Experiment`.
Args:
cfg (dict): decoded JSON object
Returns:
bool: True if `cfg` if specifies an
:py:class:`~enrich2.experiment.Experiment`, else False.
"""
if "conditions" in list(cfg.keys()):
return True
else:
return False
def is_condition(cfg):
"""
Check if the given configuration object specifies a
:py:class:`~enrich2.condition.Condition`.
Args:
cfg (dict): decoded JSON object
Returns:
bool: True if `cfg` if specifies a
:py:class:`~enrich2.condition.Condition`, else False.
"""
if "selections" in list(cfg.keys()):
return True
else:
return False
def is_selection(cfg):
"""
Check if the given configuration object specifies a
:py:class:`~enrich2.selection.Selection`.
Args:
cfg (dict): decoded JSON object
Returns:
bool: True if `cfg` if specifies a
:py:class:`~enrich2.selection.Selection`, else False.
"""
if "libraries" in list(cfg.keys()):
return True
else:
return False
def is_seqlib(cfg):
"""
Check if the given configuration object specifies a
:py:class:`~enrich2.seqlib.SeqLib` derived object.
Args:
cfg (dict): decoded JSON object
Returns:
bool: True if `cfg` if specifies a :py:class:`~enrich2.seqlib.SeqLib`
derived object, else False.
"""
if "fastq" in list(cfg.keys()) or "identifiers" in list(cfg.keys()):
return True
else:
return False
def seqlib_type(cfg):
"""
Get the type of :py:class:`~enrich2.seqlib.SeqLib` derived object
specified by the configuration object.
Args:
cfg (dict): decoded JSON object
Returns:
str: The class name of the :py:class:`~seqlib.seqlib.SeqLib` derived
object specified by `cfg`.
Raises:
ValueError: If the class name cannot be determined.
"""
if "barcodes" in cfg:
if "map file" in cfg["barcodes"]:
if "variants" in cfg and "identifiers" in cfg:
raise ValueError("Unable to determine SeqLib type.")
elif "variants" in cfg:
return "BcvSeqLib"
elif "identifiers" in cfg:
return "BcidSeqLib"
else:
raise ValueError("Unable to determine SeqLib type.")
else:
return "BarcodeSeqLib"
elif "overlap" in cfg and "variants" in cfg:
return "OverlapSeqLib"
elif "variants" in cfg:
return "BasicSeqLib"
elif "identifiers" in cfg:
return "IdOnlySeqLib"
else:
raise ValueError("Unable to determine SeqLib type for configuration " "object.")
def element_type(cfg):
"""
Get the type of :py:class:`~enrich2.storemanager.StoreManager` derived
object specified by the configuration object.
Args:
cfg (dict): decoded JSON object
Returns:
str: The class name of the
:py:class:`~enrich2.storemanager.StoreManager` derived object specified
by `cfg`.
Raises:
ValueError: If the class name cannot be determined.
"""
if is_experiment(cfg):
return "Experiment"
elif is_condition(cfg):
return "Condition"
elif is_selection(cfg):
return "Selection"
elif is_seqlib(cfg):
return seqlib_type(cfg)
else:
raise ValueError("Unable to determine type for configuration object.")