Class: CaTissue::AbstractSpecimen
- Inherits:
-
Object
- Object
- CaTissue::AbstractSpecimen
- Defined in:
- lib/catissue/domain/abstract_specimen.rb
Defined Under Namespace
Classes: SpecimenClass
Instance Method Summary collapse
-
#aliquot? ⇒ Boolean
Whether this specimen is an aliquot.
-
#aliquots ⇒ <AbstractSpecimen>
This specimen’s aliquots.
-
#closure ⇒ AbstractSpecimen
and all AbstractSpecimen in the derivation hierarcy.
-
#derive(opts = Hash::EMPTY_HASH) ⇒ AbstractSpecimen+
Derives a new specimen from this specimen.
-
#derived? ⇒ Boolean
Whether this specimen is derived from a parent specimen.
-
#fixed? ⇒ Boolean
Whether this specimen’s type starts with ‘Fixed’.
-
#fresh? ⇒ Boolean
Whether this specimen’s type is ‘Fresh Tissue’.
-
#frozen? ⇒ Boolean
Whether this specimen’s type starts with ‘Frozen’.
-
#initialize ⇒ AbstractSpecimen
constructor
Initializes this AbstractSpecimen.
-
#minimal_match?(other) ⇒ Boolean
Returns whether this AbstractSpecimen is minimally consistent with the other specimen.
-
#specimen_type=(value) ⇒ Object
Sets the specimen type to the specified value.
-
#standard_unit ⇒ Object
Returns the standard unit for this specimen.
Constructor Details
#initialize ⇒ AbstractSpecimen
Initializes this AbstractSpecimen. The default specimen_class is inferred from this AbstractSpecimen instance’s subclass.
81 82 83 84 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 81 def initialize super self.specimen_class ||= infer_specimen_class(self.class) end |
Instance Method Details
#aliquot? ⇒ Boolean
Returns whether this specimen is an aliquot.
92 93 94 95 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 92 def aliquot? lineage ||= default_lineage lineage == 'Aliquot' end |
#aliquots ⇒ <AbstractSpecimen>
Returns this specimen’s aliquots.
98 99 100 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 98 def aliquots children.filter { |child| child.aliquot? } end |
#closure ⇒ AbstractSpecimen
and all AbstractSpecimen in the derivation hierarcy.
119 120 121 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 119 def closure children.inject([self]) { |coll, spc| coll.concat(spc.closure) } end |
#derive(opts = Hash::EMPTY_HASH) ⇒ AbstractSpecimen+
Derives a new specimen from this specimen. The options are described in Specimen.create_specimen, with one addition:
-
:count(Integer) - the optional number of specimens to derive
If the :count option is greater than one and the :specimen_class, :specimen_type and :specimen_characteristics options are not set to values which differ from the respective values for this Specimen, then the specimen is aliquoted, otherwise the derived specimens are created independently, e.g.:
spc = Specimen.create_specimen(:specimen_class => :tissue, :specimen_type => :frozen)
spc.derive(:count => 1) #=> not aliquoted
spc.derive(:count => 2) #=> aliquoted
spc.derive(:specimen_type => 'Frozen Specimen') #=> two aliquots
The default derived initial_quantity is the parent specimen available_quantity divided by count for aliquots, zero otherwise. If the child specimen_class is the same as this Specimen class, then this parent Specimen’s available_quantity is decremented by the child initial_quantity, e.g.:
spc.available_quantity #=> 4
spc.derive(:initial_quantity => 1)
spc.available_quantity #=> 3
spc.derive(:count => 2, :specimen_type => 'Frozen Tissue')
spc.derive(:count => 2) #=> two aliquots with quantity 1 each
spc.available_quantity #=> 0
The default derived specimen label is label_n, where label is this specimen’s label and n is this specimen’s child count after including the new derived specimen, e.g. 3090_3 for the third child in the parent specimen with label 3090.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 162 def derive(opts=Hash::EMPTY_HASH) # add defaults add_defaults if specimen_class.nil? # copy the option hash opts = opts.dup # standardize the requirement param, if any rqmt = opts.delete(:requirement) opts[:specimen_requirement] ||= rqmt if rqmt # the default specimen parameters unless opts.has_key?(:specimen_requirement) then opts[:specimen_class] ||= self.specimen_class ||= infer_specimen_class opts[:specimen_type] ||= self.specimen_type end unless Class === opts[:specimen_class] then opts[:specimen_class] = infer_class(opts) end count = opts.delete(:count) count ||= 1 aliquot_flag = false if count > 1 and opts[:specimen_class] == self.class and opts[:specimen_type] == self.specimen_type then # aliquots share the specimen_characteristics child_chr = opts[:specimen_characteristics] ||= specimen_characteristics aliquot_flag = child_chr == specimen_characteristics end # set aliquot parameters if necessary if aliquot_flag then set_aliquot_parameters(opts, count) end # make the derived specimens count == 1 ? create_derived(opts) : Array.new(count) { create_derived(opts) } end |
#derived? ⇒ Boolean
Returns whether this specimen is derived from a parent specimen.
87 88 89 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 87 def derived? !!parent end |
#fixed? ⇒ Boolean
Returns whether this specimen’s type starts with ‘Fixed’.
108 109 110 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 108 def fixed? specimen_type =~ /^Fixed/ end |
#fresh? ⇒ Boolean
Returns whether this specimen’s type is ‘Fresh Tissue’.
103 104 105 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 103 def fresh? specimen_type == 'Fresh Tissue' end |
#frozen? ⇒ Boolean
Returns whether this specimen’s type starts with ‘Frozen’.
113 114 115 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 113 def frozen? specimen_type =~ /^Frozen/ end |
#minimal_match?(other) ⇒ Boolean
Returns whether this AbstractSpecimen is minimally consistent with the other specimen. This method augments the Jinx::Resource.minimal_match? with an additional restriction that the other specimen is the same type as this specimen and is a tolerant match on specimen class, specimen type and pathological status. A tolerant match condition holds if the other attribute value is equal to this AbstractSpecimen’s attribute value or the other value is the default ‘Not Specified’.
201 202 203 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 201 def minimal_match?(other) super and tolerant_match?(other, TOLERANT_MATCH_ATTRS) end |
#specimen_type=(value) ⇒ Object
Sets the specimen type to the specified value. The value can be a permissible caTissue String value or the shortcut symbols :fresh, :fixed and :frozen.
11 12 13 14 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 11 def specimen_type=(value) value = value.to_s.capitalize_first + ' Tissue' if Symbol === value setSpecimenType(value) end |
#standard_unit ⇒ Object
Returns the standard unit for this specimen
124 125 126 127 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 124 def standard_unit self.specimen_class ||= infer_specimen_class(self.class) SpecimenClass::UNIT_HASH[self.specimen_class] end |