Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin De Pelseneer committed Oct 10, 2023
1 parent c578d16 commit 242a30a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
20 changes: 12 additions & 8 deletions db/seeds/016_ena_upload.seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ def create_sample_controlled_vocab_terms_attributes(array)
description: 'The STUDY_TYPE presents a controlled vocabulary for expressing the overall purpose of the study.',
label: 'ENA Study Type')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'new_study_type', required: false,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'))
sample_attribute_type: SampleAttributeType.find_by(title: 'String'), label: 'New Study Type',
description: 'Specify a new Study Type here if "Other" was chosen as "ENA Study Type".')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ena_study_abstract', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'Text'), label: 'ENA study abstract',
description: 'Briefly describes the goals, purpose, and scope of the Study. This need not be listed if it can be inherited from a referenced publication.')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'assay_stream', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'),
description: 'This is the name that will be transferred to the ISA JSON. Example: "My assay" will be defined as "a_my_assay.txt" in the ISA JSON',
label: 'Name Assay Stream:')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ENA study alias prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'))
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ENA experiment prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'))
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ENA sample alias prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'))
label: 'Name Assay Stream')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ena_study_alias_prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'), label: 'ENA study alias prefix')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ena_experiment_alias_prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'), label: 'ENA experiment alias prefix')
cmt.extended_metadata_attributes << ExtendedMetadataAttribute.new(title: 'ena_sample_alias_prefix', required: true,
sample_attribute_type: SampleAttributeType.find_by(title: 'String'), label: 'ENA sample alias prefix')

cmt.save!
end
Expand Down
44 changes: 28 additions & 16 deletions lib/isa_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def convert_study(study)

publications = []
study.publications.each { |p| publications << convert_publication(p) }
study.assays.each do |assay|
assay.publications.each { |p| publications << convert_publication(p) }
end
isa_study[:publications] = publications

people = []
Expand Down Expand Up @@ -121,22 +124,27 @@ def convert_annotation(term_uri)
end

def convert_assay_comments(assays)
custom_metadata = []
extended_metadata = []
assay_streams = assays.select { |a| a.position.zero? }
assay_streams.map do |assay|
next if assay.custom_metadata.nil?
assay_stream_id = assays.pluck(:id).join('_')

json = JSON.parse(assay.custom_metadata&.json_metadata)
assay_streams.map do |assay|
next if assay.extended_metadata.nil?
json = JSON.parse(assay.extended_metadata&.json_metadata)
cm_attributes = assay.extended_metadata.extended_metadata_attributes
json.map do |key, val|
custom_metadata.push({
'@id': assay.custom_metadata.id,
study_id = assay.study_id
cm_id = assay&.extended_metadata&.id
cma_id = cm_attributes.detect { |cma| cma.title == key }&.id
extended_metadata.push({
'@id': "#assay_comment/#{[study_id, assay_stream_id, cm_id, cma_id].join('_')}",
'name': key,
'value': val
})
end
end

custom_metadata.compact
extended_metadata.compact
end

def convert_assays(assays)
Expand All @@ -146,14 +154,10 @@ def convert_assays(assays)

stream_name = 'a_assays.txt'
assay_comments = convert_assay_comments(assays)
assay_comments.delete_if do |c|
if c[:name] == 'assay_stream'
stream_name = c[:value]
true # True is returned comment is 'assay_stream'
else
false
end
end

# Retrieve assay_stream if
stream_name_comment = assay_comments.detect { |ac| ac[:name] == 'assay_stream' }
stream_name = stream_name_comment[:value] unless stream_name_comment.nil?

isa_assay = {}
isa_assay['@id'] = "#assay/#{assays.pluck(:id).join('_')}"
Expand Down Expand Up @@ -206,8 +210,16 @@ def convert_publication(publication)
isa_publication[:status] = status
isa_publication[:title] = publication.title
isa_publication[:author_list] = publication.authors.map(&:full_name).join(', ')
isa_publication[:comments] = [
{
"@id": nil,
"name": nil,
"value": nil
}
]

publication
# publication
isa_publication
end

def convert_ontologies
Expand Down

0 comments on commit 242a30a

Please sign in to comment.