Class: Accession::Sample

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Accessionable

#date, #ebi_alias_datestamped, #filename, #schema_type, #to_file, #to_xml

Constructor Details

#initialize(standard_tags, sample) ⇒ Sample

Returns a new instance of Sample.



26
27
28
29
30
31
32
# File 'lib/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(exactly_one_study? ? studies.keys.first : nil)
end

Instance Attribute Details

#sampleObject (readonly)

Returns the value of attribute sample.



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

def sample
  @sample
end

#serviceObject (readonly)

Returns the value of attribute service.



22
23
24
# File 'lib/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/sample.rb', line 22

def standard_tags
  @standard_tags
end

#studiesObject (readonly)

Returns the value of attribute studies.



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

def studies
  @studies
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#accessioned?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/accession/sample.rb', line 87

def accessioned?
  ebi_accession_number.present?
end

#build_xml(xml) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



42
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
71
72
73
# File 'lib/accession/sample.rb', line 42

def build_xml(xml) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  tag_groups = tags.by_group

  xml.SAMPLE_SET(XML_NAMESPACE) do # rubocop:disable Metrics/BlockLength
    xml.SAMPLE(alias: ebi_alias) do
      xml.TITLE title if title.present?
      xml.SAMPLE_NAME do
        tag_groups[:sample_name].each { |_k, tag| xml.tag!(tag.label.tr(' ', '_').upcase, tag.value) }
      end
      xml.SAMPLE_ATTRIBUTES do
        tag_groups[:sample_attributes].each do |_k, tag|
          xml.SAMPLE_ATTRIBUTE do
            xml.TAG tag.label
            if tag.label == 'gender'
              xml.VALUE tag.value.downcase
            else
              xml.VALUE tag.value
            end
          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
end

#ebi_aliasObject



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

def ebi_alias
  sample.uuid
end

#nameObject



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

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

#titleObject



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

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

#update_accession_number(accession_number, event_user) ⇒ Object

Updates the accession number, saving the sample and adding an event to the events table for viewing under sample history.



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

def update_accession_number(accession_number, event_user)
  sample..sample_ebi_accession_number = accession_number
  sample.save
  sample.events.assigned_accession_number!('sample', accession_number, event_user)
end