Class: CaTissue::AbstractSpecimen

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/catissue/domain/abstract_specimen.rb

Defined Under Namespace

Classes: SpecimenClass

Instance Method Summary collapse

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.

Parameters:

  • params ({Symbol => Object}) (defaults to: nil)

    the specimen attribute => value hash



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.

Returns:

  • (Boolean)

    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

#aliquotsObject

Returns this specimen’s aliquots.

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

#closureAbstractSpecimen

and all AbstractSpecimen in the derivation hierarcy.

Returns:

  • (AbstractSpecimen)

    the transitive closure consisting of this AbstractSpecimen



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.

Returns:

  • the new derived specimen if count is one, otherwise an Array of count derived specimens

Raises:

  • (ValidationError)

    if an aliquoted parent available quantity is not greater than zero or the derived specimen quantities exceed the parent available quantity



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.

Returns:

  • (Boolean)

    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’.

Returns:

  • (Boolean)

    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’.

Returns:

  • (Boolean)

    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’.

Returns:

  • (Boolean)

    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’.

Returns:

  • (Boolean)


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.

Parameters:

  • value (String, Symbol, nil)

    the value to set



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_unitObject

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