Module: PhiX

Defined in:
app/models/phi_x.rb

Overview

PhiX

PhiX is a well characterized bacteriophage with a small, known, genome. It is used to provide short DNA sequences which can get added to sequencing lanes for control and calibration purposes.

Process

PhiX samples arrive on site and have tags applied as required. These may single indexed (i7 only) or dual indexed (i5 & i7) as required. The single and dual indexed tag sets are fixed and are selected from the 'Control Tag Group 888' TagGroup.

Library information is filled in on the PhiXesController#show page and one or more library tubes are generated via StocksController#create and the Stock factory. These tubes are considered stocks, and get transferred to the sequencing teams.

Subsequently the sequencing team will split the contents of each LibraryTube into a number of SpikedBuffer tubes, adjusting the volume and concentration as required. This is achieved via a separate form on the PhiXesController#show page, followed by SpikedBuffersController#create and the SpikedBuffer factory.

Finally, during the processing of a SequencingPipeline the SpikedBuffer barcode is scanned in during the AddSpikedInControlTask. This adds the SpikedBuffer in as a parent of each Lane in the Batch, which in turn ensures the control can be found by batch.xml generation and Api::Messages::FlowcellIO.

Configuration

Configuration and values are stored in config/phi_x.yml tag_group_name: The name of the tag group to use tag_map_id: The default map_id for tags tag_options: Hash of available tag options, indexed by option name.

Values are hashes of i5 and i7 oligos. null indicates no tag.

default_tag_option: The option which will be initially selected

Defined Under Namespace

Classes: SpikedBuffer, SpikedBuffersController, Stock, StocksController

Class Method Summary collapse

Class Method Details

.configurationHash

Returns the configuration as defined in phi_x

Returns:

  • (Hash)

    Configuration. See above.


44
45
46
# File 'app/models/phi_x.rb', line 44

def self.configuration
  Rails.configuration.phi_x
end

.default_tag_optionString

Returns the default tag option which will be automatically selected when generating new PhiX stocks

Returns:

  • (String)

    The default tag option


64
65
66
# File 'app/models/phi_x.rb', line 64

def self.default_tag_option
  configuration[:default_tag_option]
end

.find_tag(tag_option, tag_type) ⇒ Tag?

Returns the appropriate tag or creates it if it doesn't exist.

Parameters:

  • tag_option (String)

    The selected tag_option from which the tags will be selected. eg. 'Single'

  • tag_type (:i7_oligo, :i5_oligo)

    The tag which will be applied

Returns:

  • (Tag, nil)

    The tag to apply, or nil if it is to be untagged


117
118
119
120
121
122
123
124
# File 'app/models/phi_x.rb', line 117

def self.find_tag(tag_option, tag_type)
  oligo = tag_options.dig(tag_option, tag_type)
  return nil if oligo.nil?

  tag_group.tags
           .create_with(map_id: configuration[:tag_map_id])
           .find_or_create_by!(oligo: oligo)
end

.sampleSample

Returns the sample the represents PhiX, creates it if it doesn't exist

Returns:


88
89
90
# File 'app/models/phi_x.rb', line 88

def self.sample
  Sample.find_or_create_by!(name: 'phiX_for_spiked_buffers')
end

.spiked_buffer_purposeTube::Purpose

Returns the purpose used to generate new PhiX SpikedBuffers creates it if it doesn't exist

Returns:


80
81
82
83
84
# File 'app/models/phi_x.rb', line 80

def self.spiked_buffer_purpose
  Tube::Purpose.create_with(
    target_type: 'SpikedBuffer'
  ).find_or_create_by(name: 'PhiX Spiked Buffer')
end

.stock_purposeTube::Purpose

Returns the purpose used to generate new PhiX Stocks creates it if it doesn't exist

Returns:


71
72
73
74
75
# File 'app/models/phi_x.rb', line 71

def self.stock_purpose
  Tube::Purpose.create_with(
    target_type: 'LibraryTube'
  ).find_or_create_by(name: 'PhiX Stock')
end

.tag_groupTagGroup

Returns the tag group for PhiX tags or creates it if it doesn't exist

Returns:

  • (TagGroup)

    The TagGroup for PhiX tags


94
95
96
# File 'app/models/phi_x.rb', line 94

def self.tag_group
  TagGroup.find_or_create_by!(name: configuration[:tag_group_name])
end

.tag_option_for(i7_oligo:, i5_oligo:) ⇒ String

Performs a lookup of the tag option matching the given oligo pair. If no option can be found returns: UNKOWN i7:i7_olgo i5:i5_oligo

Parameters:

  • i7_oligo (String)

    The i7 (tag) oligo sequence

  • i5_oligo (String)

    The i5 (tag2) oligo sequence

Returns:

  • (String)

    The named tag option.


106
107
108
109
# File 'app/models/phi_x.rb', line 106

def self.tag_option_for(i7_oligo:, i5_oligo:)
  tag_options.key('i7_oligo' => i7_oligo, 'i5_oligo' => i5_oligo) ||
    "UNKNOWN i7:#{i7_oligo || '-'} i5:#{i5_oligo || '-'}"
end

.tag_option_namesArray

Returns the names of valid tag options for creation of PhiX libraries.

Returns:

  • (Array)

    Valid tag options


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

def self.tag_option_names
  tag_options.keys
end

.tag_optionsHash

Returns the tag_options configured.

Returns:

  • (Hash)

    Hash of available tag options, indexed by option name. Values are hashes of i5 and i7 oligos. null indicates no tag.


51
52
53
# File 'app/models/phi_x.rb', line 51

def self.tag_options
  configuration[:tag_options]
end