Skip to content

Commit f5be65a

Browse files
authored
feat: enhance collection import with SMILES support and conditional attachment handling. (#2692)
**Better Molecule Handling** - Added support for importing molecules from SMILES strings when molecule data(Molfile) is missing - Improved fallback system: tries molecular structure first, then SMILES, then creates a placeholder if needed **Attachment post processing** - Attachments now get different handling based on their source - Local "smart-add" attachments are marked differently from regular imports
1 parent ae3a815 commit f5be65a

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

lib/import/import_collections.rb

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,25 @@ def import_samples
255255
# look for the molecule for this sample and add the molecule name
256256
# neither the Molecule or the MoleculeName are created if they already exist
257257
molfile = fields.fetch('molfile')
258-
molecule = if fields.fetch('decoupled',
259-
nil) && molfile.blank?
260-
Molecule.find_or_create_dummy
261-
else
258+
259+
# Check the associated Molecule for cano_smiles
260+
cano_smiles = nil
261+
if fields.fetch('molecule_id').present?
262+
molecule_uuid = fields.fetch('molecule_id')
263+
molecule_data = @data.fetch('Molecule', {}).fetch(molecule_uuid, {})
264+
cano_smiles = molecule_data.fetch('cano_smiles', nil) if molecule_data.present?
265+
end
266+
267+
# Priority: molfile > cano_smiles > dummy (if decoupled and both blank)
268+
molecule = if molfile.present?
269+
# Always use molfile if available (highest priority)
262270
Molecule.find_or_create_by_molfile(molfile)
271+
elsif cano_smiles.present?
272+
# Use cano_smiles if molfile is missing but cano_smiles is available
273+
Molecule.find_or_create_by_cano_smiles(cano_smiles)
274+
elsif fields.fetch('decoupled', nil)
275+
# Create dummy only for decoupled samples with no structure data
276+
Molecule.find_or_create_dummy
263277
end
264278
unless (fields.fetch('decoupled', nil) && molfile.blank?) || molecule_name_name.blank?
265279
molecule.create_molecule_name_by_user(molecule_name_name, @current_user_id)
@@ -597,10 +611,21 @@ def import_attachments
597611
).first
598612

599613
if attachable.present? && attachment.present?
614+
# Check source field to determine transferred status
615+
source_value = @data['source'] || ''
616+
transferred_status = source_value != 'smart-add'
617+
618+
# For ZIP files, reset aasm_state to allow processing if from smart-add
619+
aasm_state = if attachment.content_type == 'application/zip' && source_value == 'smart-add'
620+
'queueing'
621+
else
622+
fields.fetch('aasm_state')
623+
end
624+
600625
attachment.update!(
601626
attachable: attachable,
602-
transferred: true,
603-
aasm_state: fields.fetch('aasm_state'),
627+
transferred: transferred_status,
628+
aasm_state: aasm_state,
604629
filename: fields.fetch('filename'),
605630
# checksum: fields.fetch('checksum'),
606631
# created_at: fields.fetch('created_at'),

0 commit comments

Comments
 (0)