Class: Accession::Sample

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

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


25
26
27
28
29
30
31
# File 'lib/accession/accession/sample.rb', line 25

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


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

def sample
  @sample
end

#serviceObject (readonly)

Returns the value of attribute service


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

def service
  @service
end

#standard_tagsObject (readonly)

Returns the value of attribute standard_tags


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

def standard_tags
  @standard_tags
end

#studiesObject (readonly)

Returns the value of attribute studies


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

def studies
  @studies
end

#tagsObject (readonly)

Returns the value of attribute tags


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

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


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

def ebi_alias
  sample.uuid
end

#nameObject


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

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

#titleObject


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

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

#to_xmlObject


41
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
# File 'lib/accession/accession/sample.rb', line 41

def to_xml
  tag_groups = tags.by_group
  xml = Builder::XmlMarkup.new
  xml.instruct!
  xml.SAMPLE_SET(XML_NAMESPACE) {
    xml.SAMPLE(alias: ebi_alias) {
      xml.TITLE title if title.present?
      xml.SAMPLE_NAME {
        tag_groups[:sample_name].each do |_k, tag|
          xml.tag!(tag.label, tag.value)
        end
      }
      xml.SAMPLE_ATTRIBUTES {
        tag_groups[:sample_attributes].each do |_k, tag|
          xml.SAMPLE_ATTRIBUTE {
            xml.TAG tag.label
            xml.VALUE tag.value
          }
        end
        if service.ena?
          tag_groups[:array_express].each do |_k, tag|
            xml.SAMPLE_ATTRIBUTE {
              xml.TAG tag.array_express_label
              xml.VALUE tag.value
            }
          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