Class: Accession::Sample
- Inherits:
-
Object
- Object
- Accession::Sample
- Includes:
- Accessionable, ActiveModel::Model
- Defined in:
- lib/accession/accession/sample.rb
Instance Attribute Summary collapse
-
#sample ⇒ Object
readonly
Returns the value of attribute sample.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#standard_tags ⇒ Object
readonly
Returns the value of attribute standard_tags.
-
#studies ⇒ Object
readonly
Returns the value of attribute studies.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #accessioned? ⇒ Boolean
-
#ebi_alias ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#initialize(standard_tags, sample) ⇒ Sample
constructor
A new instance of Sample.
- #name ⇒ Object
- #title ⇒ Object
-
#to_xml ⇒ Object
rubocop:todo Metrics/MethodLength.
- #update_accession_number(accession_number) ⇒ Object
Methods included from Accessionable
#date, #ebi_alias_datestamped, #filename, #schema_type, #to_file
Constructor Details
#initialize(standard_tags, sample) ⇒ Sample
Returns a new instance of Sample.
26 27 28 29 30 31 32 |
# File 'lib/accession/accession/sample.rb', line 26 def initialize(, sample) @standard_tags = @sample = sample @studies = set_studies @tags = .extract(sample.) @service = Service.new(studies_valid? ? studies.keys.first : nil) end |
Instance Attribute Details
#sample ⇒ Object (readonly)
Returns the value of attribute sample.
22 23 24 |
# File 'lib/accession/accession/sample.rb', line 22 def sample @sample end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
22 23 24 |
# File 'lib/accession/accession/sample.rb', line 22 def service @service end |
#standard_tags ⇒ Object (readonly)
Returns the value of attribute standard_tags.
22 23 24 |
# File 'lib/accession/accession/sample.rb', line 22 def @standard_tags end |
#studies ⇒ Object (readonly)
Returns the value of attribute studies.
22 23 24 |
# File 'lib/accession/accession/sample.rb', line 22 def studies @studies end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
22 23 24 |
# File 'lib/accession/accession/sample.rb', line 22 def @tags end |
Instance Method Details
#accessioned? ⇒ Boolean
83 84 85 |
# File 'lib/accession/accession/sample.rb', line 83 def accessioned? ebi_accession_number.present? end |
#ebi_alias ⇒ Object
rubocop:enable Metrics/MethodLength
74 75 76 |
# File 'lib/accession/accession/sample.rb', line 74 def ebi_alias sample.uuid end |
#name ⇒ Object
34 35 36 |
# File 'lib/accession/accession/sample.rb', line 34 def name @name ||= (sample..sample_public_name || sample.name).sanitize end |
#title ⇒ Object
38 39 40 |
# File 'lib/accession/accession/sample.rb', line 38 def title @title ||= sample..sample_public_name || sample.sanger_sample_id end |
#to_xml ⇒ Object
rubocop:todo Metrics/MethodLength
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/accession/accession/sample.rb', line 43 def to_xml # rubocop:todo Metrics/AbcSize tag_groups = .by_group xml = Builder::XmlMarkup.new xml.instruct! xml.SAMPLE_SET(XML_NAMESPACE) do xml.SAMPLE(alias: ebi_alias) do xml.TITLE title if title.present? xml.SAMPLE_NAME { tag_groups[:sample_name].each { |_k, tag| xml.tag!(tag.label, tag.value) } } xml.SAMPLE_ATTRIBUTES do tag_groups[:sample_attributes].each do |_k, tag| xml.SAMPLE_ATTRIBUTE do xml.TAG tag.label xml.VALUE tag.value end end if service.ena? tag_groups[:array_express].each do |_k, tag| xml.SAMPLE_ATTRIBUTE do xml.TAG tag.array_express_label xml.VALUE tag.value end end end end end end xml.target! end |
#update_accession_number(accession_number) ⇒ Object
78 79 80 81 |
# File 'lib/accession/accession/sample.rb', line 78 def update_accession_number(accession_number) sample..sample_ebi_accession_number = accession_number sample.save end |