Class: PhiX::SpikedBuffer

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/phi_x/spiked_buffer.rb

Overview

PhiX is a short DNA fragment of known sequence which gets added into lanes of sequencing to provide a control. PhiX arrives on site in bulk where it is tagged with a fixed i7 tag, or fixed i5 and i7 tags.

This controller handles the rendering of the two forms for creating the LibraryTube and the SpikedBuffer. Actual creation is handled by the respective controllers. Stock and SpikedBuffer act as factories

PhiX::SpikedBuffer acts as a factory to generate the required spiked buffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#concentrationFloat

Returns The concentration of the created library in nM

Returns:

  • (Float)

    The concentration of the created library in nM


17
18
19
# File 'app/models/phi_x/spiked_buffer.rb', line 17

def concentration
  @concentration
end

#nameString

Returns the base name for the created library tubes Will be appended with #n to distinguish multiple tubes. eg. ('Tube name #1', 'Tube name #2')

Returns:

  • (String)

    the base name for the created library tubes Will be appended with #n to distinguish multiple tubes. eg. ('Tube name #1', 'Tube name #2')


12
13
14
# File 'app/models/phi_x/spiked_buffer.rb', line 12

def name
  @name
end

#numberInteger

Returns The number of library tubes to create

Returns:


21
22
23
# File 'app/models/phi_x/spiked_buffer.rb', line 21

def number
  @number
end

#parentTube

Returns the provided parent, or the matching tube found via the parent_barcode

Returns:

  • (Tube)

    The parent tube


56
57
58
# File 'app/models/phi_x/spiked_buffer.rb', line 56

def parent
  @parent ||= Tube.includes(aliquots: %i[sample tag tag2]).find_by_barcode(parent_barcode)
end

#parent_barcodeString

has been created

Returns:

  • (String)

    The barcode of the LibraryTube from which the SpikedBuffer


15
16
17
# File 'app/models/phi_x/spiked_buffer.rb', line 15

def parent_barcode
  @parent_barcode
end

#volumeFloat

Returns The volume of the created library in ul

Returns:

  • (Float)

    The volume of the created library in ul


19
20
21
# File 'app/models/phi_x/spiked_buffer.rb', line 19

def volume
  @volume
end

Instance Method Details

#created_spiked_buffersArray

Returns the spiked_buffers that were create as part of #save Will be an empty array if called before the #save method

Returns:

  • (Array)

    Array of the spiked_buffers created by the factory.


48
49
50
# File 'app/models/phi_x/spiked_buffer.rb', line 48

def created_spiked_buffers
  @created_spiked_buffers || []
end

#parent_contains_phi_xObject

Validates the contents of the parent The parent MUST contain one aliquot, and it MUST be a PhiX sample This MAY be a stock, or a previously created spiked buffer


63
64
65
66
67
68
# File 'app/models/phi_x/spiked_buffer.rb', line 63

def parent_contains_phi_x
  return true if parent.aliquots.one? &&
                 parent.aliquots.all? { |aliquot| aliquot.sample == PhiX.sample }

  errors.add(:parent_barcode, 'does not contain PhiX')
end

#saveBoolean

Generates spiked buffers if the factory is valid, otherwise returns false and does nothing

Returns:

  • (Boolean)

    true if the operation completed successfully, false otherwise


36
37
38
39
40
41
# File 'app/models/phi_x/spiked_buffer.rb', line 36

def save
  return false unless valid?

  @created_spiked_buffers = generate_spiked_buffers
  true
end

#tagsObject


70
71
72
73
# File 'app/models/phi_x/spiked_buffer.rb', line 70

def tags
  i7_oligo, i5_oligo = parent.aliquots.first.tags_combination
  PhiX.tag_option_for(i7_oligo: i7_oligo, i5_oligo: i5_oligo)
end