Skip to content

Commit

Permalink
better method names and rubocop #2134
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Mar 10, 2025
1 parent ae7b991 commit abdd5b3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/controllers/sample_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def build_sample_type_from_fair_ds_ttl
fds_sample = inv&.studies.first&.observation_units.first&.samples.first
end
end
if fds_sample && fds_sample.all_additional_metadata_annotations_for_type_details.any?
if fds_sample && fds_sample.all_additional_potential_annotation_details.any?
string_attribute_type = SampleAttributeType.where(title: 'String').first
@sample_type.sample_attributes.build({
title: 'Title',
Expand All @@ -228,7 +228,7 @@ def build_sample_type_from_fair_ds_ttl
pid: RDF::Vocab::SCHEMA.description,
sample_attribute_type: string_attribute_type
})
fds_sample.all_additional_metadata_annotations_for_type_details.each do |details|
fds_sample.all_additional_potential_annotation_details.each do |details|
@sample_type.sample_attributes.build({
title: details.label,
description: details.description,
Expand Down
14 changes: 7 additions & 7 deletions lib/seek/fair_data_station/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ def additional_metadata_annotation_details
end
end

def all_annotations_for_type
@all_annotations_for_type ||= query_all_annotations
def all_potential_annotation_predicates
@all_potential_annotation_predicates ||= query_all_annotations
end

def all_additional_metadata_annotations_for_type
all_annotations_for_type.reject do |annotation|
def all_additional_potential_annotation_predicates
all_potential_annotation_predicates.reject do |annotation|
core_annotations.include?(annotation)
end
end

def all_additional_metadata_annotations_for_type_details
all_additional_metadata_annotations_for_type.collect do |annotation|
def all_additional_potential_annotation_details
all_additional_potential_annotation_predicates.collect do |annotation|
annotation_details(annotation)
end
end
Expand All @@ -110,7 +110,7 @@ def to_extended_metadata_type_json
json['title'] = "FDS #{type_name.underscore.humanize} - #{package_name || UUID.generate}"
json['supported_type'] = type_name
json['enabled'] = true
seek_attributes = all_additional_metadata_annotations_for_type_details.collect(&:to_extended_metadata_attribute_json)
seek_attributes = all_additional_potential_annotation_details.collect(&:to_extended_metadata_attribute_json)
json['attributes'] = seek_attributes
json
end
Expand Down
2 changes: 1 addition & 1 deletion lib/seek/fair_data_station/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def to_extended_metadata_type_json(path)
obs_unit = study&.observation_units&.first
assay = study&.assays&.first
necessary = [inv, study, obs_unit, assay].compact.select do |type|
type.all_additional_metadata_annotations_for_type.any?
type.all_additional_potential_annotation_predicates.any?
end
necessary.collect(&:to_extended_metadata_type_json)
end
Expand Down
34 changes: 20 additions & 14 deletions test/unit/fair_data_station/fair_data_station_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class FairDataStationReaderTest < ActiveSupport::TestCase
# packageName not included
assay = study.assays.first
assert_equal 12, assay.additional_metadata_annotations.count
refute_includes assay.additional_metadata_annotations, ['http://fairbydesign.nl/ontology/packageName', 'Amplicon demultiplexed']
refute_includes assay.additional_metadata_annotations,
['http://fairbydesign.nl/ontology/packageName', 'Amplicon demultiplexed']
assert_equal 'Amplicon demultiplexed', assay.package_name
assert_nil study.package_name

Expand Down Expand Up @@ -222,48 +223,53 @@ class FairDataStationReaderTest < ActiveSupport::TestCase
study = inv.studies.first
details = study.additional_metadata_annotation_details
assert_equal 3, details.count
assert_equal ["end date of study", "experimental site name", "start date of study"], details.collect(&:label).sort
assert_equal ['end date of study', 'experimental site name', 'start date of study'], details.collect(&:label).sort

path = "#{Rails.root}/test/fixtures/files/fair_data_station/indpensim.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first
obs_unit = inv.studies.first.observation_units.first
details = obs_unit.additional_metadata_annotation_details
assert_equal 5, details.count
assert_equal ["brand", "fermentation", "ncbi taxonomy id", "scientific name", "volume"], details.collect(&:label).sort
assert_equal ['brand', 'fermentation', 'ncbi taxonomy id', 'scientific name', 'volume'],
details.collect(&:label).sort
end

test 'all_additional_metadata_annotations_for_type_details' do
test 'all_additional_potential_annotations_details' do
path = "#{Rails.root}/test/fixtures/files/fair_data_station/seek-fair-data-station-test-case-irregular.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first
study = inv.studies.first
details = study.all_additional_metadata_annotations_for_type_details
details = study.all_additional_potential_annotation_details
assert_equal 3, details.count
assert_equal ["end date of study", "experimental site name", "start date of study"], details.collect(&:label).sort
assert_equal ['end date of study', 'experimental site name', 'start date of study'], details.collect(&:label).sort

path = "#{Rails.root}/test/fixtures/files/fair_data_station/indpensim.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first
obs_unit = inv.studies.first.observation_units.first
details = obs_unit.all_additional_metadata_annotations_for_type_details
details = obs_unit.all_additional_potential_annotation_details
assert_equal 6, details.count
assert_equal ["brand", "data stream", "fermentation", "ncbi taxonomy id", "scientific name", "volume"], details.collect(&:label).sort
assert_equal ['brand', 'data stream', 'fermentation', 'ncbi taxonomy id', 'scientific name', 'volume'],
details.collect(&:label).sort
end

test 'get all additional annotations for type' do
test 'get all_additional_potential_annotation_predicates' do
path = "#{Rails.root}/test/fixtures/files/fair_data_station/seek-fair-data-station-test-case-irregular.ttl"
inv = Seek::FairDataStation::Reader.new.parse_graph(path).first
study = inv.studies.first
assert_equal ["http://fairbydesign.nl/ontology/end_date_of_study", "http://fairbydesign.nl/ontology/experimental_site_name", "http://fairbydesign.nl/ontology/start_date_of_study"], study.all_additional_metadata_annotations_for_type.sort
assert_equal ['http://fairbydesign.nl/ontology/end_date_of_study', 'http://fairbydesign.nl/ontology/experimental_site_name', 'http://fairbydesign.nl/ontology/start_date_of_study'],
study.all_additional_potential_annotation_predicates.sort
obs_unit = study.observation_units.first
assert_equal ["http://fairbydesign.nl/ontology/birth_weight", "http://fairbydesign.nl/ontology/date_of_birth", "https://w3id.org/mixs/0000811"], obs_unit.all_additional_metadata_annotations_for_type.sort
assert_equal ['http://fairbydesign.nl/ontology/birth_weight', 'http://fairbydesign.nl/ontology/date_of_birth', 'https://w3id.org/mixs/0000811'],
obs_unit.all_additional_potential_annotation_predicates.sort
sample = obs_unit.samples.first
assert_equal ["http://fairbydesign.nl/ontology/biosafety_level", "http://gbol.life/0.1/scientificName", "http://purl.uniprot.org/core/organism", "https://w3id.org/mixs/0000011"], sample.all_additional_metadata_annotations_for_type.sort
assert_equal ['http://fairbydesign.nl/ontology/biosafety_level', 'http://gbol.life/0.1/scientificName', 'http://purl.uniprot.org/core/organism', 'https://w3id.org/mixs/0000011'],
sample.all_additional_potential_annotation_predicates.sort
end

test 'to extended metadata types json' do
path = "#{Rails.root}/test/fixtures/files/fair_data_station/seek-fair-data-station-test-case.ttl"
jsons = Seek::FairDataStation::Reader.new.to_extended_metadata_type_json(path)
assert_equal 4, jsons.count
assert_equal ['Investigation', 'Study', 'ObservationUnit', 'Assay'], jsons.collect{|j| j['supported_type']}
assert_equal(%w[Investigation Study ObservationUnit Assay], jsons.collect { |j| j['supported_type'] })
jsons.each do |json|
assert_nothing_raised do
Seek::ExtendedMetadataType::ExtendedMetadataTypeExtractor.valid_emt_json?(json)
Expand All @@ -273,7 +279,7 @@ class FairDataStationReaderTest < ActiveSupport::TestCase
path = "#{Rails.root}/test/fixtures/files/fair_data_station/demo.ttl"
jsons = Seek::FairDataStation::Reader.new.to_extended_metadata_type_json(path)
assert_equal 2, jsons.count
assert_equal ['Study', 'Assay'], jsons.collect{|j| j['supported_type']}
assert_equal(%w[Study Assay], jsons.collect { |j| j['supported_type'] })
jsons.each do |json|
assert_nothing_raised do
Seek::ExtendedMetadataType::ExtendedMetadataTypeExtractor.valid_emt_json?(json)
Expand Down

0 comments on commit abdd5b3

Please sign in to comment.