labimotion 2.3.0 → 2.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae2d21e32163f9242bb0228e21a9d691bf02873463b6165a5f1e8ad204393c32
4
- data.tar.gz: 1da451215fba4042ea72906285df462080d212a31017d55a3f0d9d43c970b91b
3
+ metadata.gz: 50d1572a0d16e5ac73fdf5aa6a22e5188c9fd2f008c671fc9705a310fbd090ac
4
+ data.tar.gz: 85631425352102b56f1c0c9998710c0e9af6c4f416b272cee3e05cffd6c4209e
5
5
  SHA512:
6
- metadata.gz: a5823f0eab2c94c8a76c1436f5596d0040c6931cdf486ad707456864ba1750efbc6e5897ebb4c137cba89cc1bfba349c7d9e7749d4c7b3c64b74c4115067b77e
7
- data.tar.gz: 62f356dfedee9fff2776797201fc1f72cc3aadaef9bbff9fd93b4d402c45367ab8f04f7a5c3b842ffce7d89eff25d47bdc28164b79688941fbf492b3faa8b6c4
6
+ metadata.gz: a8d4af5906da69a5ce49e100fb5ac4d63ea399bd4cc587af58dff73b2563eebe196d7658aa0257665b439be486b5f1d2bc851226bc265cd14b309e04120ae842
7
+ data.tar.gz: 57e90440bc487d8fc950bb408e5c8794fa0566bad76d3a731f3cc92460623234a4893fdd1f6e61ed9f2730a1ec2b045b78ff940556fa49f6e92a6bc73c7475e6
@@ -28,5 +28,11 @@ module Labimotion
28
28
  DATASET = 'DatasetKlass'
29
29
  ALL = [ELEMENT, SEGMENT, DATASET].freeze
30
30
  end
31
+
32
+ module Tpa
33
+ # Segments and layers sent along with reaction variations to a third-party
34
+ # app (see ExportTpaSegments), as segment-klass label => layer keys.
35
+ SEGMENT_LAYERS = { 'Mol interactions' => %w[binding_props bind_partners].freeze }.freeze
36
+ end
31
37
  end
32
38
  end
@@ -29,7 +29,10 @@ module Labimotion
29
29
  dsr = []
30
30
  ols = nil
31
31
  Zip::File.open(att.attachment_attacher.file.url) do |zip_file|
32
- res = Labimotion::Converter.collect_metadata(zip_file, current_user) if att.filename.split('.')&.last == 'zip'
32
+ if att.filename.split('.')&.last == 'zip'
33
+ res = Labimotion::Converter.collect_metadata(zip_file, current_user)
34
+ Labimotion::Converter.collect_reaction_converter_metadata(att, zip_file)
35
+ end
33
36
  ols = res[:o] unless res&.dig(:o).nil?
34
37
  dsr.push(res[:d]) unless res&.dig(:d).nil?
35
38
  end
@@ -93,6 +96,33 @@ module Labimotion
93
96
  { a: oa, f: folder }
94
97
  end
95
98
 
99
+ def self.collect_reaction_converter_metadata(oat, zip_file)
100
+ zip_file.each do |entry|
101
+ next unless entry.name == 'metadata/reaction_variation.json'
102
+
103
+ # Create temp file
104
+ tmp_file = Tempfile.new(['reaction_variation', '.json'])
105
+ tmp_file.binmode
106
+
107
+ # Write ZIP entry content into temp file
108
+ entry.extract(tmp_file.path) { true }
109
+
110
+ # Create attachment
111
+ att = Attachment.create!(
112
+ filename: 'reaction_variation.json',
113
+ file_path: tmp_file.path,
114
+ content_type: 'application/json',
115
+ attachable_id: oat.attachable_id,
116
+ attachable_type: 'Container',
117
+ con_state: Labimotion::ConState::CONVERTED,
118
+ created_by: oat.created_by,
119
+ created_for: oat.created_for
120
+ )
121
+
122
+ att.save! if att.valid?
123
+ end
124
+ end
125
+
96
126
  def self.collect_metadata(zip_file, current_user = {}) # rubocop: disable Metrics/PerceivedComplexity
97
127
  dsr = []
98
128
  ols = nil
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'labimotion/constants'
4
+
5
+ module Labimotion
6
+ ## ExportTpaSegments
7
+ # Builds the `segment` section of the reaction-variations payload handed to a
8
+ # third-party app (TPA). Segment values are element-wide -- one set per
9
+ # element, not per variation -- so they travel once, next to the variations.
10
+ #
11
+ # Only the segments and layers named in `segment_layers` (by default
12
+ # Constants::Tpa::SEGMENT_LAYERS) are exported, each field reduced to what the
13
+ # app needs:
14
+ #
15
+ # { "<segment klass label>" => { "<layer key>" => { "<field>" => { label:, value:, unit:, type: } } } }
16
+ #
17
+ # A segment the element does not carry, or a layer its segment does not carry,
18
+ # is left out.
19
+ class ExportTpaSegments
20
+ # Mirrors Labimotion::Prop::LAYERS / ::FIELDS. Held locally because
21
+ # requiring `labimotion/utils/prop` here would race the gem's autoload.
22
+ LAYERS = 'layers'
23
+ FIELDS = 'fields'
24
+
25
+ class << self
26
+ def call(element, segment_layers: Labimotion::Constants::Tpa::SEGMENT_LAYERS)
27
+ segment_layers.each_with_object({}) do |(segment_label, layer_keys), payload|
28
+ segment = element.segments.detect { |s| s.segment_klass&.label == segment_label }
29
+ next unless segment
30
+
31
+ payload[segment_label] = layers(segment, layer_keys)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def layers(segment, layer_keys)
38
+ stored = segment.properties&.dig(LAYERS) || {}
39
+ Array(layer_keys).each_with_object({}) do |layer_key, acc|
40
+ layer = stored[layer_key]
41
+ acc[layer_key] = fields(layer) if layer
42
+ end
43
+ end
44
+
45
+ def fields(layer)
46
+ Array(layer[FIELDS]).to_h do |field|
47
+ [field['field'],
48
+ { label: field['label'], value: field['value'], unit: field['value_system'], type: field['type'] }]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -41,9 +41,10 @@ module Labimotion
41
41
 
42
42
  def process(att)
43
43
  config = Labimotion::MapperUtils.load_brucker_config
44
- return if config.nil?
45
-
46
44
  attacher = att&.attachment_attacher
45
+ return Labimotion::MapperUtils.check_if_bagit(attacher&.file&.url) if config.nil?
46
+
47
+
47
48
  extracted_data = Labimotion::MapperUtils.extract_data_from_zip(attacher&.file&.url, config['sourceMap'])
48
49
  return if extracted_data.nil?
49
50
 
@@ -46,6 +46,22 @@ module Labimotion
46
46
  nil
47
47
  end
48
48
 
49
+ def check_if_bagit(zip_file_url)
50
+ return nil if zip_file_url.nil?
51
+ Zip::File.open(zip_file_url) do |zip_file|
52
+ zip_file.each do |entry|
53
+ return { is_bagit: true, metadata: nil } if bagit_metadata_file?(entry)
54
+ end
55
+ end
56
+
57
+ rescue Zip::Error => e
58
+ Rails.logger.error "Zip file error: #{e.message}"
59
+ nil
60
+ rescue StandardError => e
61
+ Rails.logger.error "Unexpected error extracting metadata: #{e.message}"
62
+ nil
63
+ end
64
+
49
65
  def extract_parameters(file_content, parameter_names)
50
66
  return nil if file_content.blank? || parameter_names.blank?
51
67
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  ## Labimotion Version
4
4
  module Labimotion
5
- VERSION = '2.3.0'
5
+ VERSION = '2.3.1'
6
6
  end
data/lib/labimotion.rb CHANGED
@@ -96,6 +96,7 @@ module Labimotion
96
96
  autoload :ElementVariationHeader, 'labimotion/libs/element_variation_header'
97
97
  autoload :ExportElementVariations, 'labimotion/libs/export_element_variations'
98
98
  autoload :ImportElementVariations, 'labimotion/libs/import_element_variations'
99
+ autoload :ExportTpaSegments, 'labimotion/libs/export_tpa_segments'
99
100
 
100
101
  ######## Utils
101
102
  autoload :Prop, 'labimotion/utils/prop'
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: 2.3.0
4
+ version: 2.3.1
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: 2026-08-26 00:00:00.000000000 Z
12
+ date: 2026-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: caxlsx
@@ -135,6 +135,7 @@ files:
135
135
  - lib/labimotion/libs/export_dataset.rb
136
136
  - lib/labimotion/libs/export_element.rb
137
137
  - lib/labimotion/libs/export_element_variations.rb
138
+ - lib/labimotion/libs/export_tpa_segments.rb
138
139
  - lib/labimotion/libs/import_element_variations.rb
139
140
  - lib/labimotion/libs/nmr_mapper.rb
140
141
  - lib/labimotion/libs/properties_handler.rb