Class: Accession::Sample

Inherits:
Object
  • Object
show all
Includes:
Accessionable, ActiveModel::Model
Defined in:
lib/accession/accession/sample.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

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(standard_tags, sample)
  @standard_tags = standard_tags
  @sample = sample
  @studies = set_studies
  @tags = standard_tags.extract(sample.)
  @service = Service.new(studies_valid? ? studies.keys.first : nil)
end

Instance Attribute Details

#sampleObject (readonly)

Returns the value of attribute sample.


22
23
24
# File 'lib/accession/accession/sample.rb', line 22

def sample
  @sample
end

#serviceObject (readonly)

Returns the value of attribute service.


22
23
24
# File 'lib/accession/accession/sample.rb', line 22

def service
  @service
end

#standard_tagsObject (readonly)

Returns the value of attribute standard_tags.


22
23
24
# File 'lib/accession/accession/sample.rb', line 22

def standard_tags
  @standard_tags
end

#studiesObject (readonly)

Returns the value of attribute studies.


22
23
24
# File 'lib/accession/accession/sample.rb', line 22

def studies
  @studies
end

#tagsObject (readonly)

Returns the value of attribute tags.


22
23
24
# File 'lib/accession/accession/sample.rb', line 22

def tags
  @tags
end

Instance Method Details

#accessioned?Boolean

Returns:

  • (Boolean)

83
84
85
# File 'lib/accession/accession/sample.rb', line 83

def accessioned?
  ebi_accession_number.present?
end

#ebi_aliasObject

rubocop:enable Metrics/MethodLength


74
75
76
# File 'lib/accession/accession/sample.rb', line 74

def ebi_alias
  sample.uuid
end

#nameObject


34
35
36
# File 'lib/accession/accession/sample.rb', line 34

def name
  @name ||= (sample..sample_public_name || sample.name).sanitize
end

#titleObject


38
39
40
# File 'lib/accession/accession/sample.rb', line 38

def title
  @title ||= (sample..sample_public_name || sample.sanger_sample_id)
end

#to_xmlObject

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 = tags.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