Skip to content

Commit

Permalink
Hide unauthorized samples in assays
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed Nov 17, 2023
1 parent 64f2b16 commit 258efff
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions lib/isa_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ def convert_assays(assays)
isa_assay[:characteristicCategories] = convert_characteristic_categories(nil, assays)
isa_assay[:materials] = {
# Here, the first assay's samples will be enough
samples:
first_assay.samples.map { |s| find_sample_origin([s], 1) }.flatten.uniq.map { |s| { '@id': "#sample/#{s}" } }, # the samples from study level that are referenced in this assay's samples,
samples: assay_samples(first_assay), # the samples from study level that are referenced in this assay's samples,
otherMaterials: convert_other_materials(all_sample_types)
}
isa_assay[:processSequence] =
Expand Down Expand Up @@ -391,7 +390,7 @@ def convert_materials_samples(sample_type)

def convert_characteristics(sample, attributes)
attributes.map do |c|
value = sample.get_attribute_value(c) || ''
value = sample.can_view?(@current_user) ? (sample.get_attribute_value(c) || '') : ''
ontology = get_ontology_details(c, value, true)
{
category: {
Expand Down Expand Up @@ -482,12 +481,21 @@ def convert_data_files(sample_types)
return [] unless with_tag_data_file

st.samples.map do |s|
{
'@id': "#data_file/#{s.id}",
name: s.get_attribute_value(with_tag_data_file),
type: with_tag_data_file.title,
comments: with_tag_data_file_comment.map { |d| { name: d.title, value: s.get_attribute_value(d).to_s } }
}
if s.can_view?(@current_user)
{
'@id': "#data_file/#{s.id}",
name: s.get_attribute_value(with_tag_data_file),
type: with_tag_data_file.title,
comments: with_tag_data_file_comment.map { |d| { name: d.title, value: s.get_attribute_value(d).to_s } }
}
else
{
'@id': "#data_file/HIDDEN",
name: 'HIDDEN',
type: with_tag_data_file.title,
comments: []
}
end
end
end

Expand All @@ -513,20 +521,35 @@ def convert_other_materials(sample_types)
st
.samples
.map do |s|
{
'@id': "#other_material/#{s.id}",
name: s.get_attribute_value(with_tag_isa_other_material),
type: with_tag_isa_other_material.title,
characteristics: convert_characteristics(s, with_tag_isa_other_material_characteristics),
# It can sometimes be other_material or sample!!!! SHOULD BE DYNAMIC
derivesFrom: extract_sample_ids(s.get_attribute_value(seek_sample_multi_attribute), type)
}
if s.can_view?(@current_user)
{
'@id': "#other_material/#{s.id}",
name: s.get_attribute_value(with_tag_isa_other_material),
type: with_tag_isa_other_material.title,
characteristics: convert_characteristics(s, with_tag_isa_other_material_characteristics),
# It can sometimes be other_material or sample!!!! SHOULD BE DYNAMIC
derivesFrom: extract_sample_ids(s.get_attribute_value(seek_sample_multi_attribute), type)
}
else
{
'@id': "#other_material/HIDDEN",
name: 'HIDDEN',
type: with_tag_isa_other_material.title,
characteristics: convert_characteristics(s, with_tag_isa_other_material_characteristics),
# It can sometimes be other_material or sample!!!! SHOULD BE DYNAMIC
derivesFrom: extract_sample_ids(s.get_attribute_value(seek_sample_multi_attribute), type)
}
end
end
.flatten
end
other_materials
end

def assay_samples(first_assay)
first_assay.samples.map { |s| find_sample_origin([s], 1) }.flatten.uniq.map { |s| { '@id': "#sample/#{s}" } }
end

def export
convert_investigation
@OBJECT_MAP.to_json
Expand Down

0 comments on commit 258efff

Please sign in to comment.