Skip to content

Commit

Permalink
Export Study extended metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin De Pelseneer committed Oct 12, 2023
1 parent 3bcb9b6 commit cad6a11
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/isa_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@ def convert_investigation
isa_investigation
end

def convert_study_comments(study)
study_comments = []
study_id = study.id

# Study Custom Metadata
unless study.extended_metadata.nil?
json = JSON.parse(study.extended_metadata.json_metadata)
extended_metadata_attributes = study.extended_metadata.extended_metadata_attributes
em_id = study.extended_metadata.id
json.map do |key, val|
ema_id = extended_metadata_attributes.detect { |ema| ema.title == key }&.id
study_comments.push({
'@id': "#study_comment/#{ [study_id, em_id, ema_id].join('_') }",
'name': key,
'value': val
})
end
end
###################################################

study_comments.append({
'@id': "#study_comment/#{ [study_id, UUID.new.generate].join('_') }",
'name': 'SEEK Study ID',
'value': study_id.to_s
})
study_comments.append({
'@id': "#study_comment/#{ [study_id, UUID.new.generate].join('_') }",
'name': 'SEEK creation date',
'value': study.created_at.utc.iso8601
})
end

def convert_study(study)
isa_study = {}
isa_study[:identifier] = '' # study.id
Expand All @@ -51,10 +83,7 @@ def convert_study(study)
isa_study[:submissionDate] = '' # study.created_at.to_date.iso8601
isa_study[:publicReleaseDate] = '' # study.created_at.to_date.iso8601
isa_study[:filename] = "#{study.title}.txt"
isa_study[:comments] = [
{ name: 'SEEK Study ID', value: study.id.to_s },
{ name: 'SEEK creation date', value: study.created_at.utc.iso8601 }
]
isa_study[:comments] = convert_study_comments(study)

publications = []
study.publications.each { |p| publications << convert_publication(p) }
Expand Down Expand Up @@ -131,12 +160,13 @@ def convert_assay_comments(assays)
linked_assays = assays.map { |assay| { 'id': assay.id, 'title': assay.title } }.to_json

assay_streams.map do |assay|
study_id = assay.study_id
next if assay.extended_metadata.nil?

json = JSON.parse(assay.extended_metadata&.json_metadata)
cm_attributes = assay.extended_metadata.extended_metadata_attributes
cm_id = assay.extended_metadata&.id
json.map do |key, val|
study_id = assay.study_id
cm_id = assay&.extended_metadata&.id
cma_id = cm_attributes.detect { |cma| cma.title == key }&.id
assay_comments.push({
'@id': "#assay_comment/#{[study_id, assay_stream_id, cm_id, cma_id].join('_')}",
Expand Down

0 comments on commit cad6a11

Please sign in to comment.