labimotion 1.5.0.rc9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labimotion/apis/standard_api.rb +1 -2
  3. data/lib/labimotion/apis/standard_layer_api.rb +4 -17
  4. data/lib/labimotion/apis/vocabulary_api.rb +6 -20
  5. data/lib/labimotion/constants.rb +25 -0
  6. data/lib/labimotion/entities/dataset_entity.rb +0 -1
  7. data/lib/labimotion/entities/element_entity.rb +1 -0
  8. data/lib/labimotion/entities/properties_entity.rb +104 -44
  9. data/lib/labimotion/entities/segment_entity.rb +0 -2
  10. data/lib/labimotion/entities/vocabulary_entity.rb +3 -12
  11. data/lib/labimotion/helpers/element_helpers.rb +5 -4
  12. data/lib/labimotion/helpers/generic_helpers.rb +6 -1
  13. data/lib/labimotion/helpers/param_helpers.rb +0 -16
  14. data/lib/labimotion/helpers/segment_helpers.rb +1 -1
  15. data/lib/labimotion/libs/converter.rb +0 -1
  16. data/lib/labimotion/libs/data/mapper/Chemwiki.json +236 -0
  17. data/lib/labimotion/libs/data/mapper/Source.json +78 -0
  18. data/lib/labimotion/libs/data/vocab/Standard.json +5 -5
  19. data/lib/labimotion/libs/data/vocab/System.json +14 -14
  20. data/lib/labimotion/libs/dataset_builder.rb +70 -0
  21. data/lib/labimotion/libs/export_dataset.rb +343 -98
  22. data/lib/labimotion/libs/nmr_mapper.rb +204 -247
  23. data/lib/labimotion/libs/sample_association.rb +4 -0
  24. data/lib/labimotion/libs/vocabulary_handler.rb +18 -12
  25. data/lib/labimotion/models/concerns/generic_klass_revisions.rb +1 -0
  26. data/lib/labimotion/models/concerns/generic_revisions.rb +3 -0
  27. data/lib/labimotion/models/element.rb +3 -0
  28. data/lib/labimotion/models/std_layer.rb +2 -2
  29. data/lib/labimotion/models/std_layers_revision.rb +2 -2
  30. data/lib/labimotion/utils/mapper_utils.rb +169 -0
  31. data/lib/labimotion/utils/utils.rb +21 -0
  32. data/lib/labimotion/version.rb +1 -1
  33. data/lib/labimotion.rb +3 -3
  34. metadata +9 -4
@@ -0,0 +1,236 @@
1
+ {
2
+ "CHMO:0000025": {
3
+ "index": ["A", "B", "C", "D", "Q2", "Q3", "G", "H", "Q4", "Q5", "K", "L", "Q6", "N", "O", "P", "Q7", "R", "S", "T", "U", "V", "W", "X", "Q8", "Q9", "Q10"],
4
+ "mapper": {
5
+ "A": {
6
+ "sources": ["inchikey"]
7
+ },
8
+ "B": {
9
+ "sources": ["molfile"]
10
+ },
11
+ "C": {
12
+ "sources": ["concentration"]
13
+ },
14
+ "D": {
15
+ "sources": ["redox"],
16
+ "separator": ","
17
+ },
18
+ "G": {
19
+ "sources": ["solvent_volume"]
20
+ },
21
+ "H": {
22
+ "sources": ["elect_inchikey"]
23
+ },
24
+ "K": {
25
+ "sources": ["elect_concentration"]
26
+ },
27
+ "L": {
28
+ "sources": ["reference_internal"]
29
+ },
30
+ "N": {
31
+ "sources": ["scan_rate"]
32
+ },
33
+ "O": {
34
+ "sources": ["scan_number"]
35
+ },
36
+ "P": {
37
+ "sources": ["voltage_limit_one", "voltage_limit_two"],
38
+ "separator": ","
39
+ },
40
+ "R": {
41
+ "sources": ["atmosphere"]
42
+ },
43
+ "S": {
44
+ "sources": ["temperature"]
45
+ },
46
+ "T": {
47
+ "sources": ["condition"]
48
+ },
49
+ "U": {
50
+ "sources": ["we"]
51
+ },
52
+ "V": {
53
+ "sources": ["we_area"]
54
+ },
55
+ "W": {
56
+ "sources": ["ce"]
57
+ },
58
+ "X": {
59
+ "sources": ["re"]
60
+ },
61
+ "Q2": {
62
+ "sources": ["solvent"]
63
+ },
64
+ "Q3": {
65
+ "sources": ["solvent_molfile"]
66
+ },
67
+ "Q4": {
68
+ "sources": ["elect_molfile"]
69
+ },
70
+ "Q5": {
71
+ "sources": ["elect_purity"]
72
+ },
73
+ "Q6": {
74
+ "sources": ["reference_internal_compound_molfile"]
75
+ },
76
+ "Q7": {
77
+ "sources": ["scan_direction"],
78
+ "separator": ","
79
+ },
80
+ "Q8": {
81
+ "sources": ["details"],
82
+ "separator": ","
83
+ },
84
+ "Q9": {
85
+ "sources": ["includes"],
86
+ "separator": ","
87
+ },
88
+ "Q10": {
89
+ "sources": ["base_page"],
90
+ "separator": ","
91
+ }
92
+ },
93
+ "source": {
94
+ "concentration": {
95
+ "title": "Analyte concentration [mM]",
96
+ "param": "sample_preparation.concentration",
97
+ "type": "dataset"
98
+ },
99
+ "temperature": {
100
+ "title": "Temperature [°C]",
101
+ "param": "set.temperature",
102
+ "type": "dataset"
103
+ },
104
+ "condition": {
105
+ "title": "Condition",
106
+ "param": "set.conditions",
107
+ "type": "dataset"
108
+ },
109
+ "scan_rate": {
110
+ "title": "Scan rate [mV/s]",
111
+ "param": "meas.scan_rate",
112
+ "type": "dataset"
113
+ },
114
+ "atmosphere": {
115
+ "title": "Gas",
116
+ "param": "set.atmosphere",
117
+ "type": "dataset"
118
+ },
119
+ "scan_number": {
120
+ "title": "Scan number",
121
+ "param": "meas.cycles",
122
+ "type": "dataset"
123
+ },
124
+ "we": {
125
+ "title": "Working electrode",
126
+ "param": "electrodes.working",
127
+ "type": "dataset"
128
+ },
129
+ "we_area": {
130
+ "title": "Working electrode surface area",
131
+ "param": "electrodes.working_area",
132
+ "type": "dataset"
133
+ },
134
+ "ce": {
135
+ "title": "Counter electrode",
136
+ "param": "electrodes.counter",
137
+ "type": "dataset"
138
+ },
139
+ "re": {
140
+ "title": "Reference electrode",
141
+ "param": "electrodes.reference",
142
+ "type": "dataset"
143
+ },
144
+ "voltage_limit_one": {
145
+ "title": "Potential window",
146
+ "param": "meas.voltage_limit_one",
147
+ "type": "dataset"
148
+ },
149
+ "voltage_limit_two": {
150
+ "title": "Potential window",
151
+ "param": "meas.voltage_limit_two",
152
+ "type": "dataset"
153
+ },
154
+ "reference_internal": {
155
+ "title": "Internal reference compound_inchikey",
156
+ "param": "meas.reference_internal",
157
+ "type": "dataset"
158
+ },
159
+ "elect_inchikey": {
160
+ "title": "Electrolyte_inchikey",
161
+ "param": "sample_preparation.salt",
162
+ "type": "dataset"
163
+ },
164
+ "elect_concentration": {
165
+ "title": "Electrolyte concentration [M]",
166
+ "param": "sample_preparation.concentration_salt",
167
+ "type": "dataset"
168
+ },
169
+ "solvent": {
170
+ "title": "Solvent A_inchikey",
171
+ "param": "sample_preparation.solvent",
172
+ "type": "dataset"
173
+ },
174
+ "solvent_volume": {
175
+ "title": "Solvent volume [ml]",
176
+ "param": "sample_preparation.amount_sol",
177
+ "type": "dataset"
178
+ },
179
+ "solvent_molfile": {
180
+ "title": "Solvent A_molfile",
181
+ "param": "n/a",
182
+ "type": "string"
183
+ },
184
+ "scan_direction": {
185
+ "title": "Scan direction",
186
+ "param": "n/a",
187
+ "type": "string"
188
+ },
189
+ "reference_internal_compound_molfile": {
190
+ "title": "Internal reference compound_molfile",
191
+ "param": "n/a",
192
+ "type": "string"
193
+ },
194
+ "elect_purity": {
195
+ "title": "Electrolyte purity [%]",
196
+ "param": "n/a",
197
+ "type": "string"
198
+ },
199
+ "redox": {
200
+ "title": "Redox-Potential",
201
+ "param": 6,
202
+ "type": "spc"
203
+ },
204
+ "elect_molfile": {
205
+ "title": "Electrolyte_inchikey",
206
+ "param": "n/a",
207
+ "type": "string"
208
+ },
209
+ "inchikey": {
210
+ "title": "Analyte_inchikey",
211
+ "param": "inchikey",
212
+ "type": "molecule"
213
+ },
214
+ "molfile": {
215
+ "title": "Analyte_molfile",
216
+ "param": "molfile",
217
+ "type": "sample"
218
+ },
219
+ "details": {
220
+ "title": "Details",
221
+ "param": "n/a",
222
+ "type": "string"
223
+ },
224
+ "includes": {
225
+ "title": "Included",
226
+ "param": "n/a",
227
+ "type": "string"
228
+ },
229
+ "base_page": {
230
+ "title": "BasePageName",
231
+ "param": "n/a",
232
+ "type": "string"
233
+ }
234
+ }
235
+ }
236
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "sourceMap": {
3
+ "sourceSelector": [
4
+ "parm",
5
+ "acqus",
6
+ "procs"
7
+ ],
8
+ "acqus": {
9
+ "file": "acqus",
10
+ "parameters": [
11
+ "DATE",
12
+ "D1",
13
+ "INSTRUM",
14
+ "NS",
15
+ "NUC1",
16
+ "NUC2",
17
+ "PROBHD",
18
+ "PULPROG",
19
+ "SFO1",
20
+ "SFO2",
21
+ "SOLVENT",
22
+ "SW",
23
+ "TD",
24
+ "TE",
25
+ "TITLE"
26
+ ]
27
+ },
28
+ "procs": {
29
+ "file": "pdata/1/procs",
30
+ "parameters": [
31
+ "SI",
32
+ "SF",
33
+ "WDW",
34
+ "LB",
35
+ "GB"
36
+ ]
37
+ },
38
+ "parm": {
39
+ "file": "pdata/1/parm.txt",
40
+ "parameters": [
41
+ "Date_",
42
+ "Time",
43
+ "INSTRUM",
44
+ "PROBHD",
45
+ "SOLVENT",
46
+ "TE",
47
+ "NS",
48
+ "PULPROG",
49
+ "TD",
50
+ "D1",
51
+ "SF",
52
+ "SFO1",
53
+ "SFO2",
54
+ "NUC1",
55
+ "NUC2"
56
+ ]
57
+ },
58
+ "parameters": {
59
+ "DATE": "general.date",
60
+ "D1": "set.done",
61
+ "INSTRUM": "instrument.instrument",
62
+ "NS": "set.ns",
63
+ "NUC1": "set.nucone",
64
+ "NUC2": "set.nuctwo",
65
+ "SF": "set.sf",
66
+ "SFO1": "set.sfoone",
67
+ "SFO2": "set.sfotwo",
68
+ "PROBHD": "equipment.probehead",
69
+ "PULPROG": "set.PULPROG",
70
+ "SOLVENT": "sample_preparation.solvent",
71
+ "TD": "set.td",
72
+ "TE": "set.temperature",
73
+ "TITLE": "software.Name",
74
+ "Version": "software.Version",
75
+ "Time": "general.time"
76
+ }
77
+ }
78
+ }
@@ -1,6 +1,6 @@
1
1
  [
2
2
  {
3
- "identifier": "atmosphere",
3
+ "identifier": "std-atmosphere",
4
4
  "name": "atmosphere",
5
5
  "label": "Atmosphere",
6
6
  "field_type": "text",
@@ -20,7 +20,7 @@
20
20
  "source": "Standard"
21
21
  },
22
22
  {
23
- "identifier": "calibration",
23
+ "identifier": "std-calibration",
24
24
  "name": "calibration",
25
25
  "label": "Calibration",
26
26
  "field_type": "text",
@@ -40,7 +40,7 @@
40
40
  "source": "Standard"
41
41
  },
42
42
  {
43
- "identifier": "coating",
43
+ "identifier": "std-coating",
44
44
  "name": "coating",
45
45
  "label": "Coating",
46
46
  "field_type": "text",
@@ -60,7 +60,7 @@
60
60
  "source": "Standard"
61
61
  },
62
62
  {
63
- "identifier": "coating_material",
63
+ "identifier": "std-coating_material",
64
64
  "name": "coating_material",
65
65
  "label": "Coating Material",
66
66
  "field_type": "text",
@@ -80,7 +80,7 @@
80
80
  "source": "Standard"
81
81
  },
82
82
  {
83
- "identifier": "wavelength",
83
+ "identifier": "std-wavelength",
84
84
  "name": "wavelength",
85
85
  "label": "Wavelength",
86
86
  "field_type": "text",
@@ -1,8 +1,8 @@
1
1
  [
2
2
  {
3
3
  "id": 1,
4
- "identifier": "dateTime.create",
5
- "name": "Create Time",
4
+ "identifier": "dateTime-create",
5
+ "name": "create_time",
6
6
  "label": "Create Time",
7
7
  "field_type": "datetime",
8
8
  "opid": 9,
@@ -27,8 +27,8 @@
27
27
  },
28
28
  {
29
29
  "id": 2,
30
- "identifier": "dateTime.update",
31
- "name": "Update Time",
30
+ "identifier": "dateTime-update",
31
+ "name": "update_time",
32
32
  "label": "Update Time",
33
33
  "field_type": "datetime",
34
34
  "opid": 9,
@@ -53,9 +53,9 @@
53
53
  },
54
54
  {
55
55
  "id": 4,
56
- "identifier": "user.name",
56
+ "identifier": "user-name",
57
57
  "name": "creator",
58
- "label": "creator",
58
+ "label": "Creator",
59
59
  "field_type": "text",
60
60
  "opid": 9,
61
61
  "term_id": "NCIT_C42628",
@@ -79,8 +79,8 @@
79
79
  },
80
80
  {
81
81
  "id": 2,
82
- "identifier": "element.id",
83
- "name": "Element Id",
82
+ "identifier": "element-id",
83
+ "name": "element_id",
84
84
  "label": "Element Id",
85
85
  "field_type": "text",
86
86
  "opid": 9,
@@ -92,8 +92,8 @@
92
92
  },
93
93
  {
94
94
  "id": 5,
95
- "identifier": "element.name",
96
- "name": "Element Name",
95
+ "identifier": "element-name",
96
+ "name": "element_name",
97
97
  "label": "Element Name",
98
98
  "field_type": "text",
99
99
  "opid": 8,
@@ -105,8 +105,8 @@
105
105
  },
106
106
  {
107
107
  "id": 3,
108
- "identifier": "element.short_label",
109
- "name": "Element Short Label",
108
+ "identifier": "element-short_label",
109
+ "name": "element_short_label",
110
110
  "label": "Element Short Label",
111
111
  "field_type": "text",
112
112
  "opid": 9,
@@ -118,8 +118,8 @@
118
118
  },
119
119
  {
120
120
  "id": 3,
121
- "identifier": "element.class",
122
- "name": "Element Class",
121
+ "identifier": "element-class",
122
+ "name": "element_class",
123
123
  "label": "Element Class",
124
124
  "field_type": "text",
125
125
  "opid": 9,
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/utils/utils'
4
+ require 'labimotion/version'
5
+
6
+ module Labimotion
7
+ class DatasetBuilder
8
+ def self.build(container, content)
9
+ return unless valid_input?(container, content)
10
+
11
+ create_dataset_with_metadata(container, content)
12
+ end
13
+
14
+ private
15
+
16
+ def self.valid_input?(container, content)
17
+ container.present? &&
18
+ content.present? &&
19
+ content[:ols].present? &&
20
+ content[:metadata].present?
21
+ end
22
+
23
+ def self.create_dataset_with_metadata(container, content)
24
+ klass = find_dataset_klass(content[:ols])
25
+ return unless klass
26
+
27
+ dataset = create_dataset(container, klass)
28
+ build_result(dataset, content)
29
+ end
30
+
31
+ def self.find_dataset_klass(ols_term_id)
32
+ Labimotion::DatasetKlass.find_by(ols_term_id: ols_term_id)
33
+ end
34
+
35
+ def self.create_dataset(container, klass)
36
+ uuid = SecureRandom.uuid
37
+ props = prepare_properties(klass, uuid)
38
+
39
+ Labimotion::Dataset.create!(
40
+ uuid: uuid,
41
+ dataset_klass_id: klass.id,
42
+ element_type: 'Container',
43
+ element_id: container.id,
44
+ properties: props,
45
+ properties_release: klass.properties_release,
46
+ klass_uuid: klass.uuid
47
+ )
48
+ end
49
+
50
+ def self.prepare_properties(klass, uuid)
51
+ props = klass.properties_release
52
+ props['uuid'] = uuid
53
+ props['pkg'] = Labimotion::Utils.pkg(props['pkg'])
54
+ props['klass'] = 'Dataset'
55
+ props
56
+ end
57
+
58
+ def self.build_result(dataset, content)
59
+ {
60
+ dataset: dataset,
61
+ metadata: content[:metadata],
62
+ ols: content[:ols],
63
+ parameters: content[:parameters]
64
+ }
65
+ end
66
+
67
+ private_class_method :valid_input?, :create_dataset_with_metadata, :find_dataset_klass, :create_dataset,
68
+ :prepare_properties, :build_result
69
+ end
70
+ end