labimotion 1.0.6 → 1.0.11
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.
- checksums.yaml +4 -4
- data/lib/labimotion/{utils → collection}/export.rb +22 -11
- data/lib/labimotion/{utils → collection}/import.rb +53 -71
- data/lib/labimotion/entities/element_entity.rb +1 -0
- data/lib/labimotion/libs/converter.rb +36 -10
- data/lib/labimotion/libs/nmr_mapper.rb +35 -11
- data/lib/labimotion/models/concerns/attachment_converter.rb +16 -3
- data/lib/labimotion/models/element.rb +13 -6
- data/lib/labimotion/models/segment_klass.rb +1 -0
- data/lib/labimotion/utils/import_utils.rb +116 -0
- data/lib/labimotion/version.rb +6 -2
- data/lib/labimotion.rb +5 -2
- metadata +7 -7
- data/lib/labimotion/api.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7059d7bb80a3d629ddacc3ef633f4c2b039120b6a6a6754761a84de37a5aa6a0
|
4
|
+
data.tar.gz: 842ad058f7563befe7d7bf34a909aab07c97d8c406cd0f5b7f601d79f3af0ea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b03a6c2bc5592268ab5aef1e68a146c23c17e15d0d134a7f965d864dd38538b81051853c6b1d914df84d0f2697e0a8c7623bdbe5d9a548c0ee3a298994a7fba
|
7
|
+
data.tar.gz: f314a546d4b70cc3dc042b9e0977b918f984f2b573e512bc6385fe2611001c2e061b15226e2f7e99153db0bdaf0420b36c8b579246d3c5c7bea4cc9f2c60c59a
|
@@ -23,17 +23,20 @@ module Labimotion
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.fetch_elements(collection, segments, attachments, fetch_many, fetch_one, fetch_containers)
|
26
|
-
fetch_many.call(collection.elements, {
|
27
|
-
|
28
|
-
|
29
|
-
})
|
30
|
-
fetch_many.call(collection.collections_elements, {
|
31
|
-
|
32
|
-
|
33
|
-
})
|
26
|
+
# fetch_many.call(collection.elements, {
|
27
|
+
# 'element_klass_id' => 'Labimotion::ElementKlass',
|
28
|
+
# 'created_by' => 'User',
|
29
|
+
# })
|
30
|
+
# fetch_many.call(collection.collections_elements, {
|
31
|
+
# 'collection_id' => 'Collection',
|
32
|
+
# 'element_id' => 'Labimotion::Element',
|
33
|
+
# })
|
34
34
|
collection.elements.each do |element|
|
35
|
-
|
36
|
-
|
35
|
+
element, attachments = Labimotion::Export.fetch_properties(data, element, attachments, &fetch_one)
|
36
|
+
fetch_one.call(element, {
|
37
|
+
'element_klass_id' => 'Labimotion::ElementKlass',
|
38
|
+
'created_by' => 'User',
|
39
|
+
})
|
37
40
|
fetch_containers.call(element)
|
38
41
|
segment, @attachments = Labimotion::Export.fetch_segments(element, attachments, &fetch_one)
|
39
42
|
segments += segment if segment.present?
|
@@ -91,6 +94,15 @@ module Labimotion
|
|
91
94
|
mol = Molecule.find(id) unless id.nil?
|
92
95
|
properties['layers'][key]['fields'][idx]['value']['el_id'] = fetch_one.call(mol) unless mol.nil?
|
93
96
|
end
|
97
|
+
|
98
|
+
field_samples = layer['fields'].select { |ss| ss['type'] == 'drag_sample' }
|
99
|
+
field_samples.each do |field|
|
100
|
+
# idx = properties['layers'][key]['fields'].index(field)
|
101
|
+
# id = field["value"] && field["value"]["el_id"] unless idx.nil?
|
102
|
+
# ss = Sample.find(id) unless id.nil?
|
103
|
+
# properties['layers'][key]['fields'][idx]['value']['el_id'] = fetch_one.call(ss) unless ss.nil?
|
104
|
+
end
|
105
|
+
|
94
106
|
field_uploads = layer['fields'].select { |ss| ss['type'] == 'upload' }
|
95
107
|
field_uploads.each do |upload|
|
96
108
|
idx = properties['layers'][key]['fields'].index(upload)
|
@@ -123,7 +135,6 @@ module Labimotion
|
|
123
135
|
end
|
124
136
|
end
|
125
137
|
end
|
126
|
-
|
127
138
|
end
|
128
139
|
instance.properties = properties
|
129
140
|
[instance, attachments]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'labimotion/utils/import_utils'
|
3
4
|
module Labimotion
|
4
5
|
class Import
|
5
6
|
|
@@ -50,7 +51,7 @@ module Labimotion
|
|
50
51
|
element_type = fields.fetch('element_type')
|
51
52
|
element = instances.fetch(element_type).fetch(element_uuid)
|
52
53
|
|
53
|
-
dataset_klass = Labimotion::DatasetKlass.find_by(identifier: dk_id)
|
54
|
+
dataset_klass = Labimotion::DatasetKlass.find_by(identifier: dk_id) if dk_id.present?
|
54
55
|
next if gt == true && dataset_klass.nil?
|
55
56
|
|
56
57
|
dkr = Labimotion::DatasetKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
|
@@ -88,33 +89,21 @@ module Labimotion
|
|
88
89
|
ek_obj = data.fetch('Labimotion::ElementKlass').fetch(sk_obj["element_klass_id"])
|
89
90
|
element_klass = Labimotion::ElementKlass.find_by(name: ek_obj['name']) if ek_obj.present?
|
90
91
|
next if element_klass.nil? || ek_obj.nil? || ek_obj['is_generic'] == true
|
92
|
+
|
91
93
|
element_uuid = fields.fetch('element_id')
|
92
94
|
element_type = fields.fetch('element_type')
|
93
95
|
element = instances.fetch(element_type).fetch(element_uuid)
|
94
|
-
segment_klass = Labimotion::SegmentKlass.find_by(identifier: sk_id)
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# 'place',
|
106
|
-
# 'properties_release',
|
107
|
-
# 'uuid',
|
108
|
-
# 'identifier',
|
109
|
-
# 'sync_time'
|
110
|
-
# ).merge(
|
111
|
-
# element_klass: element_klass,
|
112
|
-
# created_by: current_user_id,
|
113
|
-
# released_at: DateTime.now
|
114
|
-
# )
|
115
|
-
# ) if segment_klass.nil?
|
116
|
-
|
117
|
-
next if segment_klass.nil?
|
96
|
+
segment_klass = Labimotion::SegmentKlass.find_by(identifier: sk_id) if sk_id.present?
|
97
|
+
segment_klass = Labimotion::SegmentKlass.find_by(uuid: fields.fetch('klass_uuid')) if segment_klass.nil?
|
98
|
+
|
99
|
+
if segment_klass.nil?
|
100
|
+
skr = Labimotion::SegmentKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
|
101
|
+
segment_klass = skr.segment_klass if segment_klass.nil? && skr.present?
|
102
|
+
end
|
103
|
+
|
104
|
+
next if segment_klass.nil? || element.nil?
|
105
|
+
|
106
|
+
## segment_klass = Labimotion::ImportUtils.create_segment_klass(sk_obj, segment_klass, element_klass, current_user_id)
|
118
107
|
|
119
108
|
segment = Labimotion::Segment.create!(
|
120
109
|
fields.slice(
|
@@ -128,52 +117,7 @@ module Labimotion
|
|
128
117
|
)
|
129
118
|
)
|
130
119
|
|
131
|
-
properties = segment.properties
|
132
|
-
properties['layers'].keys.each do |key|
|
133
|
-
layer = properties['layers'][key]
|
134
|
-
field_molecules = layer['fields'].select { |ss| ss['type'] == 'drag_molecule' }
|
135
|
-
field_molecules.each do |field|
|
136
|
-
idx = properties['layers'][key]['fields'].index(field)
|
137
|
-
id = field["value"] && field["value"]["el_id"] unless idx.nil?
|
138
|
-
mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
|
139
|
-
unless mol.nil?
|
140
|
-
properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
|
141
|
-
properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
|
142
|
-
properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
field_tables = layer['fields'].select { |ss| ss['type'] == 'table' }
|
147
|
-
field_tables&.each do |field|
|
148
|
-
tidx = layer['fields'].index(field)
|
149
|
-
next unless field['sub_values'].present? && field['sub_fields'].present?
|
150
|
-
|
151
|
-
field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
|
152
|
-
if field_table_molecules.present?
|
153
|
-
col_ids = field_table_molecules.map { |x| x.values[0] }
|
154
|
-
col_ids.each do |col_id|
|
155
|
-
field['sub_values'].each_with_index do |sub_value, vdx|
|
156
|
-
next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
|
157
|
-
|
158
|
-
svalue = sub_value[col_id]['value']
|
159
|
-
next unless svalue['el_id'].present? && svalue['el_inchikey'].present?
|
160
|
-
|
161
|
-
tmol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[svalue['el_id']]['molfile']) unless svalue['el_id'].nil?
|
162
|
-
unless tmol.nil?
|
163
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_id'] = tmol.id
|
164
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_tip'] = "#{tmol.inchikey}@@#{tmol.cano_smiles}"
|
165
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_label'] = tmol.cano_smiles
|
166
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_smiles'] = tmol.cano_smiles
|
167
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_iupac'] = tmol.iupac_name
|
168
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_inchikey'] = tmol.inchikey
|
169
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_svg'] = File.join('/images', 'molecules', tmol.molecule_svg_file)
|
170
|
-
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_molecular_weight'] = tmol.molecular_weight
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
120
|
+
properties = Labimotion::ImportUtils.properties_handler(data, segment.properties)
|
177
121
|
segment.update!(properties: properties)
|
178
122
|
update_instances.call(uuid, segment)
|
179
123
|
end
|
@@ -182,5 +126,43 @@ module Labimotion
|
|
182
126
|
raise
|
183
127
|
end
|
184
128
|
end
|
129
|
+
|
130
|
+
def self.import_elements(data, instances, gt, current_user_id, fetch_many, &update_instances)
|
131
|
+
data.fetch('Labimotion::Element', {}).each do |uuid, fields|
|
132
|
+
klass_id = fields["element_klass_id"]
|
133
|
+
ek_obj = data.fetch('Labimotion::ElementKlass', {})[klass_id]
|
134
|
+
ek_id = ek_obj["identifier"]
|
135
|
+
element_klass = Labimotion::ElementKlass.find_by(identifier: ek_id) if ek_id.present?
|
136
|
+
element_klass = Labimotion::ElementKlass.find_by(uuid: fields.fetch('klass_uuid')) if element_klass.nil?
|
137
|
+
|
138
|
+
if element_klass.nil?
|
139
|
+
ekr = Labimotion::ElementKlassesRevision.find_by(uuid: fields.fetch('klass_uuid'))
|
140
|
+
element_klass = ekr.element_klass if element_klass.nil? && ekr.present?
|
141
|
+
end
|
142
|
+
next if element_klass.nil?
|
143
|
+
|
144
|
+
element = Labimotion::Element.create!(
|
145
|
+
fields.slice(
|
146
|
+
'name', 'properties', 'properties_release'
|
147
|
+
).merge(
|
148
|
+
created_by: current_user_id,
|
149
|
+
element_klass: element_klass,
|
150
|
+
collections: fetch_many.call(
|
151
|
+
'Collection', 'Labimotion::CollectionsElement', 'element_id', 'collection_id', uuid
|
152
|
+
),
|
153
|
+
uuid: SecureRandom.uuid,
|
154
|
+
klass_uuid: ekr&.uuid || element_klass.uuid
|
155
|
+
)
|
156
|
+
)
|
157
|
+
|
158
|
+
properties = Labimotion::ImportUtils.properties_handler(data, element.properties)
|
159
|
+
element.update!(properties: properties)
|
160
|
+
update_instances.call(uuid, element)
|
161
|
+
element.container = Container.create_root_container
|
162
|
+
end
|
163
|
+
rescue StandardError => e
|
164
|
+
Rails.logger.error(e.backtrace)
|
165
|
+
raise
|
166
|
+
end
|
185
167
|
end
|
186
168
|
end
|
@@ -14,11 +14,35 @@ require 'labimotion/utils/utils'
|
|
14
14
|
|
15
15
|
module Labimotion
|
16
16
|
class Converter
|
17
|
-
|
18
17
|
def self.logger
|
19
18
|
@@converter_logger ||= Logger.new(Rails.root.join('log/converter.log')) # rubocop:disable Style/ClassVars
|
20
19
|
end
|
21
20
|
|
21
|
+
def self.process_ds(id, current_user = {})
|
22
|
+
att = Attachment.find_by(attachable_id: id, con_state: Labimotion::ConState::CONVERTED)
|
23
|
+
return if att.nil?
|
24
|
+
|
25
|
+
dsr = []
|
26
|
+
ols = nil
|
27
|
+
|
28
|
+
Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
|
29
|
+
res = Labimotion::Converter.collect_metadata(zip_file) if att.filename.split('.')&.last == 'zip'
|
30
|
+
ols = res[:o] unless res&.dig(:o).nil?
|
31
|
+
dsr.push(res[:d]) unless res&.dig(:d).nil?
|
32
|
+
end
|
33
|
+
dsr.flatten!
|
34
|
+
|
35
|
+
dataset = build_ds(id, ols)
|
36
|
+
update_ds(dataset, dsr, current_user) if dataset.present?
|
37
|
+
|
38
|
+
|
39
|
+
rescue StandardError => e
|
40
|
+
Labimotion::Converter.logger.error ["Att ID: #{att&.id}, OLS: #{ols}", "DSR: #{dsr}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
|
41
|
+
raise e
|
42
|
+
ensure
|
43
|
+
## tmp_file&.close
|
44
|
+
end
|
45
|
+
|
22
46
|
def self.uri(api_name)
|
23
47
|
url = Rails.configuration.converter.url
|
24
48
|
"#{url}#{api_name}"
|
@@ -126,15 +150,17 @@ module Labimotion
|
|
126
150
|
att.update!(storage: primary_store)
|
127
151
|
end
|
128
152
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
153
|
+
if Labimotion::IS_RAILS5 == true
|
154
|
+
Zip::File.open(tmp_file.path) do |zip_file|
|
155
|
+
res = Labimotion::Converter.collect_metadata(zip_file) if name.split('.')&.last == 'zip'
|
156
|
+
ols = res[:o] unless res&.dig(:o).nil?
|
157
|
+
dsr.push(res[:d]) unless res&.dig(:d).nil?
|
158
|
+
end
|
134
159
|
|
135
|
-
|
136
|
-
|
137
|
-
|
160
|
+
dsr.flatten!
|
161
|
+
if dsr.length.positive? && name.split('.')&.last == 'zip'
|
162
|
+
Labimotion::Converter.ts('write', att.attachable_id, ols: ols, info: dsr)
|
163
|
+
end
|
138
164
|
end
|
139
165
|
rescue StandardError => e
|
140
166
|
raise e
|
@@ -197,7 +223,7 @@ module Labimotion
|
|
197
223
|
begin
|
198
224
|
return unless dsr_info && dsr_info[:info]&.length.positive?
|
199
225
|
dataset = Labimotion::Converter.build_ds(att_id, dsr_info[:ols])
|
200
|
-
Labimotion::Converter.update_ds(dataset, dsr_info[:info], current_user)
|
226
|
+
Labimotion::Converter.update_ds(dataset, dsr_info[:info], current_user) if dataset.present?
|
201
227
|
rescue StandardError => e
|
202
228
|
Labimotion::Converter.logger.error ["Att ID: #{att_id}, OLS: #{dsr_info[:ols]}", "DSR: #{dsr_info[:info]}", e.message, *e.backtrace].join($INPUT_RECORD_SEPARATOR)
|
203
229
|
ensure
|
@@ -6,8 +6,22 @@ require 'labimotion/utils/utils'
|
|
6
6
|
module Labimotion
|
7
7
|
## NmrMapper
|
8
8
|
class NmrMapper
|
9
|
-
def self.
|
10
|
-
att = Attachment.
|
9
|
+
def self.process_ds(id, current_user = {})
|
10
|
+
att = Attachment.find_by(attachable_id: id, con_state: Labimotion::ConState::NMR)
|
11
|
+
return if att.nil?
|
12
|
+
|
13
|
+
content = is_brucker_binary(id, att)
|
14
|
+
if content.nil?
|
15
|
+
att.update_column(:con_state, Labimotion::ConState::NONE)
|
16
|
+
else
|
17
|
+
data = process(att, id, content)
|
18
|
+
generate_ds(id, data, current_user)
|
19
|
+
att.update_column(:con_state, Labimotion::ConState::PROCESSED)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.is_brucker_binary(id, att)
|
24
|
+
# att = Attachment.find(id)
|
11
25
|
if Labimotion::IS_RAILS5 == true
|
12
26
|
Zip::File.open(att.store.path) do |zip_file|
|
13
27
|
zip_file.each do |entry|
|
@@ -32,8 +46,9 @@ module Labimotion
|
|
32
46
|
nil
|
33
47
|
end
|
34
48
|
|
35
|
-
def self.process(id, content)
|
36
|
-
att
|
49
|
+
def self.process(att, id, content)
|
50
|
+
return if att.nil? || content.nil?
|
51
|
+
|
37
52
|
lines = content.split("\n").reject(&:empty?)
|
38
53
|
metadata = {}
|
39
54
|
lines.map do |ln|
|
@@ -42,18 +57,27 @@ module Labimotion
|
|
42
57
|
end
|
43
58
|
ols = 'CHMO:0000593' if metadata['NUC1'] == '1H'
|
44
59
|
ols = 'CHMO:0000595' if metadata['NUC1'] == '13C'
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
60
|
+
|
61
|
+
{ content: { metadata: metadata, ols: ols } }
|
62
|
+
# if content.present? && att.present?
|
63
|
+
# Labimotion::NmrMapper.ts('write', att.attachable_id,
|
64
|
+
# content: { metadata: metadata, ols: ols })
|
65
|
+
# end
|
49
66
|
end
|
50
67
|
|
51
68
|
def self.fetch_content(id)
|
52
|
-
|
69
|
+
atts = Attachment.where(attachable_id: id)
|
70
|
+
return if atts.nil?
|
71
|
+
|
72
|
+
atts.each do |att|
|
73
|
+
content = Labimotion::NmrMapper.ts('read', att.id)
|
74
|
+
return content if content.present?
|
75
|
+
end
|
53
76
|
end
|
54
77
|
|
55
|
-
|
56
|
-
|
78
|
+
|
79
|
+
def self.generate_ds(id, data, current_user = {})
|
80
|
+
# data = Labimotion::NmrMapper.fetch_content(id)
|
57
81
|
return if data.nil?
|
58
82
|
|
59
83
|
obj = Labimotion::NmrMapper.build_ds(id, data[:content])
|
@@ -22,15 +22,28 @@ module Labimotion
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def exec_converter
|
25
|
+
return if self.has_attribute?(:con_state) == false || con_state.present?
|
26
|
+
|
25
27
|
#return if attachable_id.nil?
|
26
|
-
return if
|
28
|
+
return if Labimotion::IS_RAILS5 == false && self.con_state != Labimotion::ConState::WAIT
|
29
|
+
|
30
|
+
return if self.has_attribute?(:con_state) == false || self.con_state.nil? || self.con_state == Labimotion::ConState::NONE
|
31
|
+
|
27
32
|
case con_state
|
28
33
|
when Labimotion::ConState::NMR
|
29
|
-
|
34
|
+
if Labimotion::IS_RAILS5 == true
|
35
|
+
content = Labimotion::NmrMapperRepo.is_brucker_binary(id)
|
36
|
+
else
|
37
|
+
content = Labimotion::NmrMapper.is_brucker_binary(id)
|
38
|
+
end
|
30
39
|
if content.nil?
|
31
40
|
self.con_state = Labimotion::ConState::NONE
|
32
41
|
else
|
33
|
-
Labimotion::
|
42
|
+
if Labimotion::IS_RAILS5 == true
|
43
|
+
Labimotion::NmrMapperRepo.process(id, content)
|
44
|
+
else
|
45
|
+
Labimotion::NmrMapper.process(id, content)
|
46
|
+
end
|
34
47
|
self.con_state = Labimotion::ConState::PROCESSED
|
35
48
|
end
|
36
49
|
when Labimotion::ConState::WAIT
|
@@ -101,13 +101,20 @@ module Labimotion
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def thumb_svg
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
if Labimotion::IS_RAILS5 == true
|
105
|
+
image_atts = attachments.select do |a_img|
|
106
|
+
a_img&.content_type&.match(Regexp.union(%w[jpg jpeg png tiff tif]))
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
attachment = image_atts[0] || attachments[0]
|
110
|
+
preview = attachment.read_thumbnail if attachment
|
111
|
+
preview && Base64.encode64(preview) || 'not available'
|
112
|
+
else
|
113
|
+
image_atts = attachments.select(&:type_image?)
|
114
|
+
attachment = image_atts[0] || attachments[0]
|
115
|
+
preview = attachment&.read_thumbnail
|
116
|
+
(preview && Base64.encode64(preview)) || 'not available'
|
117
|
+
end
|
111
118
|
end
|
112
119
|
|
113
120
|
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Labimotion
|
4
|
+
## Import Utils
|
5
|
+
class ImportUtils
|
6
|
+
def self.proc_sample(layer, key, data, properties)
|
7
|
+
field_samples = layer['fields'].select { |ss| ss['type'] == 'drag_sample' }
|
8
|
+
field_samples.each do |field|
|
9
|
+
idx = properties['layers'][key]['fields'].index(field)
|
10
|
+
id = field["value"] && field["value"]["el_id"] unless idx.nil?
|
11
|
+
|
12
|
+
# mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
|
13
|
+
# unless mol.nil?
|
14
|
+
# properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
|
15
|
+
# properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
|
16
|
+
# properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
properties
|
20
|
+
rescue StandardError => e
|
21
|
+
Rails.logger.error(e.backtrace)
|
22
|
+
raise
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.proc_molecule(layer, key, data, properties)
|
26
|
+
field_molecules = layer['fields'].select { |ss| ss['type'] == 'drag_molecule' }
|
27
|
+
field_molecules.each do |field|
|
28
|
+
idx = properties['layers'][key]['fields'].index(field)
|
29
|
+
id = field["value"] && field["value"]["el_id"] unless idx.nil?
|
30
|
+
mol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[id]['molfile']) unless id.nil?
|
31
|
+
unless mol.nil?
|
32
|
+
properties['layers'][key]['fields'][idx]['value']['el_id'] = mol.id
|
33
|
+
properties['layers'][key]['fields'][idx]['value']['el_tip'] = "#{mol.inchikey}@@#{mol.cano_smiles}"
|
34
|
+
properties['layers'][key]['fields'][idx]['value']['el_label'] = mol.iupac_name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
properties
|
38
|
+
rescue StandardError => e
|
39
|
+
Rails.logger.error(e.backtrace)
|
40
|
+
raise
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.proc_table(layer, key, data, properties)
|
44
|
+
field_tables = layer['fields'].select { |ss| ss['type'] == 'table' }
|
45
|
+
field_tables&.each do |field|
|
46
|
+
tidx = layer['fields'].index(field)
|
47
|
+
next unless field['sub_values'].present? && field['sub_fields'].present?
|
48
|
+
|
49
|
+
field_table_molecules = field['sub_fields'].select { |ss| ss['type'] == 'drag_molecule' }
|
50
|
+
if field_table_molecules.present?
|
51
|
+
col_ids = field_table_molecules.map { |x| x.values[0] }
|
52
|
+
col_ids.each do |col_id|
|
53
|
+
field['sub_values'].each_with_index do |sub_value, vdx|
|
54
|
+
next unless sub_value[col_id].present? && sub_value[col_id]['value'].present? && sub_value[col_id]['value']['el_id'].present?
|
55
|
+
|
56
|
+
svalue = sub_value[col_id]['value']
|
57
|
+
next unless svalue['el_id'].present? && svalue['el_inchikey'].present?
|
58
|
+
|
59
|
+
tmol = Molecule.find_or_create_by_molfile(data.fetch('Molecule')[svalue['el_id']]['molfile']) unless svalue['el_id'].nil?
|
60
|
+
unless tmol.nil?
|
61
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_id'] = tmol.id
|
62
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_tip'] = "#{tmol.inchikey}@@#{tmol.cano_smiles}"
|
63
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_label'] = tmol.cano_smiles
|
64
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_smiles'] = tmol.cano_smiles
|
65
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_iupac'] = tmol.iupac_name
|
66
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_inchikey'] = tmol.inchikey
|
67
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_svg'] = File.join('/images', 'molecules', tmol.molecule_svg_file)
|
68
|
+
properties['layers'][key]['fields'][tidx]['sub_values'][vdx][col_id]['value']['el_molecular_weight'] = tmol.molecular_weight
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
properties
|
75
|
+
rescue StandardError => e
|
76
|
+
Rails.logger.error(e.backtrace)
|
77
|
+
raise
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.properties_handler(data, properties)
|
81
|
+
properties && properties['layers'] && properties['layers'].keys&.each do |key|
|
82
|
+
layer = properties['layers'][key]
|
83
|
+
properties = proc_molecule(layer, key, data, properties)
|
84
|
+
properties = proc_table(layer, key, data, properties)
|
85
|
+
# properties = proc_sample(layer, key, data, properties)
|
86
|
+
end
|
87
|
+
properties
|
88
|
+
rescue StandardError => e
|
89
|
+
Rails.logger.error(e.backtrace)
|
90
|
+
raise
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.create_segment_klass(sk_obj, segment_klass, element_klass, current_user_id)
|
94
|
+
return if segment_klass.present? || element_klass.nil? || sk_obj.nil?
|
95
|
+
|
96
|
+
segment_klass = Labimotion::SegmentKlass.create!(sk_obj.slice(
|
97
|
+
'label',
|
98
|
+
'desc',
|
99
|
+
'properties_template',
|
100
|
+
'is_active',
|
101
|
+
'place',
|
102
|
+
'properties_release',
|
103
|
+
'uuid',
|
104
|
+
'identifier',
|
105
|
+
'sync_time'
|
106
|
+
).merge(
|
107
|
+
element_klass: element_klass,
|
108
|
+
created_by: current_user_id,
|
109
|
+
released_at: DateTime.now
|
110
|
+
)
|
111
|
+
)
|
112
|
+
|
113
|
+
segment_klass
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/labimotion/version.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
## Labimotion Version
|
3
4
|
module Labimotion
|
4
5
|
IS_RAILS5 = false
|
5
|
-
|
6
|
-
|
6
|
+
VERSION_ELN = '1.0.11'
|
7
|
+
VERSION_REPO = '0.3.1'
|
8
|
+
|
9
|
+
VERSION = Labimotion::VERSION_REPO if Labimotion::IS_RAILS5 == true
|
10
|
+
VERSION = Labimotion::VERSION_ELN if Labimotion::IS_RAILS5 == false
|
7
11
|
end
|
data/lib/labimotion.rb
CHANGED
@@ -61,8 +61,11 @@ module Labimotion
|
|
61
61
|
autoload :ConState, 'labimotion/utils/con_state'
|
62
62
|
autoload :Serializer, 'labimotion/utils/serializer'
|
63
63
|
autoload :Search, 'labimotion/utils/search'
|
64
|
-
|
65
|
-
|
64
|
+
|
65
|
+
|
66
|
+
######## Collection
|
67
|
+
autoload :Export, 'labimotion/collection/export'
|
68
|
+
autoload :Import, 'labimotion/collection/import'
|
66
69
|
|
67
70
|
######## Models
|
68
71
|
autoload :Element, 'labimotion/models/element'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: labimotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chia-Lin Lin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-09-
|
12
|
+
date: 2023-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,12 +34,13 @@ extensions: []
|
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
36
|
- lib/labimotion.rb
|
37
|
-
- lib/labimotion/api.rb
|
38
37
|
- lib/labimotion/apis/converter_api.rb
|
39
38
|
- lib/labimotion/apis/generic_dataset_api.rb
|
40
39
|
- lib/labimotion/apis/generic_element_api.rb
|
41
40
|
- lib/labimotion/apis/labimotion_hub_api.rb
|
42
41
|
- lib/labimotion/apis/segment_api.rb
|
42
|
+
- lib/labimotion/collection/export.rb
|
43
|
+
- lib/labimotion/collection/import.rb
|
43
44
|
- lib/labimotion/entities/application_entity.rb
|
44
45
|
- lib/labimotion/entities/dataset_entity.rb
|
45
46
|
- lib/labimotion/entities/dataset_klass_entity.rb
|
@@ -90,15 +91,14 @@ files:
|
|
90
91
|
- lib/labimotion/models/segment_klasses_revision.rb
|
91
92
|
- lib/labimotion/models/segments_revision.rb
|
92
93
|
- lib/labimotion/utils/con_state.rb
|
93
|
-
- lib/labimotion/utils/
|
94
|
-
- lib/labimotion/utils/import.rb
|
94
|
+
- lib/labimotion/utils/import_utils.rb
|
95
95
|
- lib/labimotion/utils/search.rb
|
96
96
|
- lib/labimotion/utils/serializer.rb
|
97
97
|
- lib/labimotion/utils/utils.rb
|
98
98
|
- lib/labimotion/version.rb
|
99
|
-
homepage: https://
|
99
|
+
homepage: https://gitlab.kit.edu/kit/labimotion/labimotion
|
100
100
|
licenses:
|
101
|
-
-
|
101
|
+
- GPL-3.0
|
102
102
|
metadata: {}
|
103
103
|
post_install_message:
|
104
104
|
rdoc_options: []
|
data/lib/labimotion/api.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
## This is the first version of the dataset class
|
4
|
-
module Labimotion
|
5
|
-
## This is the first version of the dataset class
|
6
|
-
class Api
|
7
|
-
def initialize
|
8
|
-
# Initialization code
|
9
|
-
end
|
10
|
-
|
11
|
-
def gget_data
|
12
|
-
'Hello, worlddddddddddddddddddddd!'
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.hello
|
16
|
-
'Hellooooooooooooooooooooo!'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|