Class: CaTissue::AbstractSpecimen
- Inherits:
-
Object
- Object
- CaTissue::AbstractSpecimen
- Includes:
- Resource
- 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 ⇒ Object
This specimen’s aliquots.
-
#closure ⇒ AbstractSpecimen
and all AbstractSpecimen in the derivation hierarcy.
-
#derive(params = {}) ⇒ Object
Derives a 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(params = nil) ⇒ 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.
Methods included from Resource
#database, included, #tolerant_match?
Methods included from Annotatable
#annotation_proxy, #create_proxy, #method_missing
Constructor Details
#initialize(params = nil) ⇒ AbstractSpecimen
Initializes this AbstractSpecimen. The default specimen_class
is inferred from this AbstractSpecimen instance’s subclass.
76 77 78 79 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 76 def initialize(params=nil) super self.specimen_class ||= infer_specimen_class(self.class) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CaTissue::Annotatable
Instance Method Details
#aliquot? ⇒ Boolean
Returns whether this specimen is an aliquot.
87 88 89 90 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 87 def aliquot? lineage ||= default_lineage lineage == 'Aliquot' end |
#aliquots ⇒ Object
Returns this specimen’s aliquots.
93 94 95 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 93 def aliquots children.filter { |child| child.aliquot? } end |
#closure ⇒ AbstractSpecimen
and all AbstractSpecimen in the derivation hierarcy.
114 115 116 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 114 def closure children.inject([self]) { |coll, spc| coll.concat(spc.closure) } end |
#derive(params = {}) ⇒ Object
Derives a specimen from this specimen. The params are described in Specimen.create_specimen, with one addition: an optional :count, the optional number of specimens to derive.
If the :count parameter is greater than one and the :specimen_class, :specimen_type and :specimen_characteristics parameters 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 parent specimen with label 3090.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 154 def derive(params={}) # add defaults add_defaults if specimen_class.nil? # copy the parameters params = params.dup # standardize the requirement param, if any rqmt = params.delete(:requirement) params[:specimen_requirement] ||= rqmt if rqmt # the default specimen parameters unless params.has_key?(:specimen_requirement) then params[:specimen_class] ||= self.specimen_class ||= infer_specimen_class params[:specimen_type] ||= self.specimen_type end unless Class === params[:specimen_class] then params[:specimen_class] = infer_class(params) end count = params.delete(:count) count ||= 1 aliquot_flag = false if count > 1 and params[:specimen_class] == self.class and params[:specimen_type] == self.specimen_type then # aliquots share the specimen_characteristics child_chr = params[:specimen_characteristics] ||= self.specimen_characteristics aliquot_flag = child_chr == self.specimen_characteristics end # set aliquot parameters if necessary if aliquot_flag then set_aliquot_parameters(params, count) end # make the derived specimens count == 1 ? create_derived(params) : Array.new(count) { create_derived(params) } end |
#derived? ⇒ Boolean
Returns whether this specimen is derived from a parent specimen.
82 83 84 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 82 def derived? not parent.nil? end |
#fixed? ⇒ Boolean
Returns whether this specimen’s type starts with ‘Fixed’.
103 104 105 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 103 def fixed? specimen_type =~ /^Fixed/ end |
#fresh? ⇒ Boolean
Returns whether this specimen’s type is ‘Fresh Tissue’.
98 99 100 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 98 def fresh? specimen_type == 'Fresh Tissue' end |
#frozen? ⇒ Boolean
Returns whether this specimen’s type starts with ‘Frozen’.
108 109 110 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 108 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 CaRuby::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’.
193 194 195 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 193 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.
14 15 16 17 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 14 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
119 120 121 122 |
# File 'lib/catissue/domain/abstract_specimen.rb', line 119 def standard_unit self.specimen_class ||= infer_specimen_class(self.class) SpecimenClass::UNIT_HASH[self.specimen_class] end |