Class: Accessionable::Sample
- Defined in:
- app/models/accessionable/sample.rb
Constant Summary collapse
- ARRAY_EXPRESS_FIELDS =
%w[ genotype phenotype strain_or_line developmental_stage sex cell_type disease_state compound dose immunoprecipitate growth_condition rnai organism_part species time_point age treatment ].freeze
Constants inherited from Base
Instance Attribute Summary collapse
-
#common_name ⇒ Object
readonly
Returns the value of attribute common_name.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#taxon_id ⇒ Object
readonly
Returns the value of attribute taxon_id.
Attributes inherited from Base
#accession_number, #date, #date_short, #name
Instance Method Summary collapse
-
#accessionable_id ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
- #alias ⇒ Object
-
#initialize(sample) ⇒ Sample
constructor
rubocop:todo Metrics/MethodLength, Metrics/AbcSize.
- #protect?(service) ⇒ Boolean
- #released? ⇒ Boolean
- #sample_element_attributes ⇒ Object
- #title ⇒ Object
-
#update_accession_number!(user, accession_number) ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#xml ⇒ Object
rubocop:todo Metrics/MethodLength.
Methods inherited from Base
#add_updated_event, #center_name, #errors, #extract_accession_number, #extract_array_express_accession_number, #file_name, #label_scope, #schema_type, #update_array_express_accession_number!
Constructor Details
#initialize(sample) ⇒ Sample
rubocop:todo Metrics/MethodLength, Metrics/AbcSize
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/accessionable/sample.rb', line 29 def initialize(sample) # rubocop:todo Metrics/CyclomaticComplexity @sample = sample super(sample.ebi_accession_number) sampname = sample..sample_public_name @name = sampname.presence || sample.name @name = @name.gsub(/[^a-z\d]/i, '_') if @name.present? @common_name = sample..sample_common_name @taxon_id = sample..sample_taxon_id # Tags from the 'ENA attributes' property group # NOTE[xxx]: This used to also look for 'ENA links' and push them to the 'data[:links]' value, but group was empty @links = [] @tags = sample..map { |datum| Tag.new(label_scope, datum.name, sample.[datum.tag], datum.downcase) } # TODO: maybe unify this with the previous loop # Don't send managed AE data to SRA unless sample.accession_service.private? ARRAY_EXPRESS_FIELDS.each do |datum| value = sample..send(datum) next if value.blank? @tags << ArrayExpressTag.new(label_scope, datum, value) end end sample_hold = sample..sample_sra_hold @hold = sample_hold.presence || 'hold' end |
Instance Attribute Details
#common_name ⇒ Object (readonly)
Returns the value of attribute common_name.
26 27 28 |
# File 'app/models/accessionable/sample.rb', line 26 def common_name @common_name end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
26 27 28 |
# File 'app/models/accessionable/sample.rb', line 26 def links @links end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
26 27 28 |
# File 'app/models/accessionable/sample.rb', line 26 def @tags end |
#taxon_id ⇒ Object (readonly)
Returns the value of attribute taxon_id.
26 27 28 |
# File 'app/models/accessionable/sample.rb', line 26 def taxon_id @taxon_id end |
Instance Method Details
#accessionable_id ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
63 64 65 |
# File 'app/models/accessionable/sample.rb', line 63 def accessionable_id @sample.id end |
#alias ⇒ Object
67 68 69 |
# File 'app/models/accessionable/sample.rb', line 67 def alias @sample.uuid end |
#protect?(service) ⇒ Boolean
108 109 110 |
# File 'app/models/accessionable/sample.rb', line 108 def protect?(service) service.sample_visibility(@sample) == AccessionService::Protect end |
#released? ⇒ Boolean
112 113 114 |
# File 'app/models/accessionable/sample.rb', line 112 def released? @sample.released? end |
#sample_element_attributes ⇒ Object
75 76 77 78 |
# File 'app/models/accessionable/sample.rb', line 75 def sample_element_attributes # In case the accession number is defined, we won't send the alias { alias: self.alias, accession: accession_number }.tap { |obj| obj.delete(:alias) if accession_number.present? } end |
#title ⇒ Object
71 72 73 |
# File 'app/models/accessionable/sample.rb', line 71 def title @sample..sample_public_name || @sample.sanger_sample_id end |
#update_accession_number!(user, accession_number) ⇒ Object
rubocop:enable Metrics/MethodLength
101 102 103 104 105 106 |
# File 'app/models/accessionable/sample.rb', line 101 def update_accession_number!(user, accession_number) @accession_number = accession_number add_updated_event(user, "Sample #{@sample.id}", @sample) if @accession_number @sample..sample_ebi_accession_number = accession_number @sample.save! end |
#xml ⇒ Object
rubocop:todo Metrics/MethodLength
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/accessionable/sample.rb', line 81 def xml # rubocop:todo Metrics/AbcSize xml = Builder::XmlMarkup.new xml.instruct! xml.SAMPLE_SET('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance') do xml.SAMPLE(sample_element_attributes) do xml.TITLE title unless title.nil? xml.SAMPLE_NAME do xml.COMMON_NAME common_name xml.TAXON_ID taxon_id end xml.SAMPLE_ATTRIBUTES { .each { |tag| xml.SAMPLE_ATTRIBUTE { tag.build(xml) } } } if .present? xml.SAMPLE_LINKS {} if links.present? end end xml.target! end |