Skip to content

Commit

Permalink
fix: attached research_plans in screens not being imported from colle…
Browse files Browse the repository at this point in the history
…ction

* fix: attached research_plans in screens not being imported from collection
wellplates not being imported from collection

* style: rubocop 

---------

Co-authored-by: Tasnim Mehzabin <[email protected]>
Refs: #1671
  • Loading branch information
2 people authored and PiTrem committed Dec 21, 2023
1 parent a08e6a1 commit b44edaa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
29 changes: 19 additions & 10 deletions lib/export/export_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def initialize(export_id, collection_ids, format = 'zip', nested = false, gate =
@nested = nested
@gt = gate

@file_path = Rails.public_path.join( format, "#{export_id}.#{format}")
@schema_file_path = Rails.public_path.join( 'json', 'schema.json')
@file_path = Rails.public_path.join(format, "#{export_id}.#{format}")
@schema_file_path = Rails.public_path.join('json', 'schema.json')

@data = {}
@uuids = {}
Expand Down Expand Up @@ -122,8 +122,8 @@ def prepare_data
collections.each do |collection|
# fetch collection
fetch_one(collection, {
'user_id' => 'User'
})
'user_id' => 'User',
})
fetch_samples collection
fetch_chemicals collection
fetch_reactions collection
Expand Down Expand Up @@ -154,11 +154,11 @@ def fetch_samples(collection)
'fingerprint_id' => 'Fingerprint',
'created_by' => 'User',
'user_id' => 'User',
})
})
fetch_many(collection.collections_samples, {
'collection_id' => 'Collection',
'sample_id' => 'Sample',
})
})

# loop over samples and fetch sample properties
samples.each do |sample|
Expand All @@ -167,10 +167,10 @@ def fetch_samples(collection)
fetch_one(sample.molecule_name, {
'molecule_id' => 'Molecule',
'user_id' => 'User',
})
})
fetch_many(sample.residues, {
'sample_id' => 'Sample',
})
})

segment, @attachments = Labimotion::Export.fetch_segments(sample, @attachments, &method(:fetch_one))
@segments += segment if segment.present?
Expand Down Expand Up @@ -224,7 +224,9 @@ def fetch_reactions(collection)
end

def fetch_elements(collection)
@segments, @attachments = Labimotion::Export.fetch_elements(collection, @segments, @attachments, method(:fetch_many), method(:fetch_one), method(:fetch_containers))
@segments, @attachments = Labimotion::Export.fetch_elements(collection, @segments, @attachments,
method(:fetch_many), method(:fetch_one),
method(:fetch_containers))
end

def fetch_wellplates(collection)
Expand Down Expand Up @@ -263,6 +265,11 @@ def fetch_screens(collection)
'wellplate_id' => 'Wellplate',
})

fetch_many(screen.research_plans_screens, {
'screen_id' => 'Screen',
'research_plan_id' => 'ResearchPlan',
})

segment, @attachments = Labimotion::Export.fetch_segments(screen, @attachments, &method(:fetch_one))
@segments += segment if segment.present?

Expand Down Expand Up @@ -339,7 +346,9 @@ def fetch_containers(containable)
'containable_id' => containable_type,
'parent_id' => 'Container',
})
@datasets += Labimotion::Export.fetch_datasets(attachment_container.dataset, &method(:fetch_one) ) if attachment_container.dataset.present?
if attachment_container.dataset.present?
@datasets += Labimotion::Export.fetch_datasets(attachment_container.dataset, &method(:fetch_one))
end
fetch_many(attachment_container.attachments, {
'attachable_id' => 'Container',
'created_by' => 'User',
Expand Down
12 changes: 7 additions & 5 deletions lib/import/import_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def import
import_residues
import_reactions
import_reactions_samples
# import_elements if @gt == false
# import_elements_samples if @gt == false
# import_elements if @gt == false
# import_elements_samples if @gt == false
import_wellplates if @gt == false
import_wells if @gt == false
import_screens if @gt == false
import_research_plans if @gt == false
import_screens if @gt == false
import_containers
import_segments
import_datasets
Expand Down Expand Up @@ -397,7 +397,6 @@ def import_reactions_samples
end
end


def import_elements
Labimotion::Import.import_elements(@data, @instances, @gt, @current_user_id, method(:fetch_many), &method(:update_instances!))
end
Expand Down Expand Up @@ -442,7 +441,7 @@ def import_wells
'updated_at',
).merge(
wellplate: @instances.fetch('Wellplate').fetch(fields.fetch('wellplate_id')),
sample: @instances.fetch('Sample').fetch(fields.fetch('sample_id'), nil),
sample: @instances.fetch('Sample', nil)&.fetch(fields.fetch('sample_id'), nil),
))

# add reaction to the @instances map
Expand Down Expand Up @@ -470,6 +469,9 @@ def import_screens
wellplates: fetch_many(
'Wellplate', 'ScreensWellplate', 'screen_id', 'wellplate_id', uuid
),
research_plans: fetch_many(
'ResearchPlan', 'ResearchPlansScreen', 'screen_id', 'research_plan_id', uuid
),
))

# create the root container like with samples
Expand Down

0 comments on commit b44edaa

Please sign in to comment.