Class: PcrBatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/pcr_batching.rb

Overview

Pcrbatcher uses a nearest neighbor chain algorithm to batch pcr operations with their nearest neighbors by extension time until cycler_count groups remain. These groups are marked by the maximum extension they contain. Then, for each thermocycler group, the operations within that group are clustered again with a nearest neighbor chain algorithm by temperature, that refuses to make temp groups of larger than @column_count until @row_count temp groups remain. each row-grouping is marked with its average temperature. range of temp gradient is determined by the highest and lowest temp groups. Groups are placed into the rows that have nearest temperature to their average, rounding up always.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PcrBatcher

Initialize the important fields needed to batch some pcr operations.

Parameters:

  • opts (Hash) (defaults to: {})

    initialization options, will use defaults when option is not supplied

Options Hash (opts):

  • :cycler_count (Integer)

    number of thermocyclers available for batching

  • :row_count (Integer)

    number of rows per thermocycler

  • :column_count (Integer)

    number of columns per thermocycler

  • :temp_range (Float)

    degree C allowable gradient temperature range in one thermocycler

  • :mand_ext_comb_diff (Float)

    the mandatory extension combination difference at which pcr operations will be placed into the same thermocycler and use the same extension time, even if it will leave some thermocyclers open

  • :max_ext_comb_diff (Float)

    the extension difference at which pcr operations will be disallowed from being placed into the same thermocycler and using the same extension time, even if there will be more pcr batches than thermocyclers

  • :mand_tanneal_comb_diff (Float)

    the mandatory tanneal combination difference at which pcr operations will be placed into the same thermocycler row, even that means some rows of the thermocylcer will be empty

  • :max_tanneal_comb_diff (Float)

    the tanneal difference at which pcr operations will be disallowed from being grouped into the same thermocycler row



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pcr_batching.rb', line 45

def initialize opts = {}
    opts = defaults.merge opts
    @cycler_count           = opts[:cycler_count]
    @row_count              = opts[:row_count]
    @column_count           = opts[:column_count]
    @temp_range             = opts[:temp_range]
    @mand_ext_comb_diff     = opts[:mand_ext_comb_diff]
    @mand_tanneal_comb_diff = opts[:mand_tanneal_comb_diff]
    @max_ext_comb_diff      = opts[:max_ext_comb_diff]
    @max_tanneal_comb_diff  = opts[:max_tanneal_comb_diff]
    @pcr_operations         = []
end

Instance Method Details

#add_pcr_operation(opts = {}) ⇒ Object

Make a brand new pcr operation representation and add it to the list of pcr operations to be batched.

Parameters:

  • opts (Hash) (defaults to: {})

    pcr operation definition options

Options Hash (opts):

  • :extension_time (Float)

    extension time for this pcr operation

  • :anneal_temp (Float)

    the annealing temperature for this pcr operation

  • :extension_group (Integer)

    a group id for this operation, shared with other pcr operations who could be run together in a reaction with the same extension time

  • :tanneal_group (Integer)

    a group id for this operation, shared with other pcr operations who could be run together

    in a reaction with the same annealing temperature
    
  • :unique_id (Integer)

    identifier to track a pcr operation through its being batched



89
90
91
92
93
94
95
# File 'lib/pcr_batching.rb', line 89

def add_pcr_operation opts = {}
    @pcr_operations << PcrOperation.new(
        extension_time:  opts[:extension_time],
        anneal_temp:     opts[:anneal_temp],
        unique_id:       opts[:unique_id],
    )
end

#batch(use_checkrep = false) ⇒ Hash<ExtensionCluster, Set<TannealCluster>>

Batches pcr_operations into cycler_count reaction groups, and within each reaction group, batches operations into @row_count temperature groups.

Parameters:

  • use_checkrep (Boolean) (defaults to: false)

    whether or not to check representation invariants during clustering; very slow and only necessary while testing

Returns:

  • (Hash<ExtensionCluster, Set<TannealCluster>>)

    a mapping from a group of pcr operations with similar extension time to the set of

    sub-groups of that group which have similar anneal temperature.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/pcr_batching.rb', line 106

def batch(use_checkrep = false)
    extension_cluster_to_tanneal_clusters = Hash.new

    extension_graph = ExtensionClusterGraph.new(
                pcr_operations:               @pcr_operations,
                thermocycler_quantity:        @cycler_count,
                thermocycler_rows:            @row_count,
                thermocycler_columns:         @column_count,
                thermocycler_temp_range:      @temp_range,
                force_combination_distance:   @mand_ext_comb_diff,
                prevent_combination_distance: @max_ext_comb_diff
            ) # O(n^2)

    extension_clusters = extension_graph.perform_clustering use_checkrep # O(n^2)
    extension_clusters.each do |extension_cluster| # m clusters =>  O(m) 
        tanneal_graph = TannealClusterGraph.new(  # q pcr operations per cluster => O(q^2) 
                    pcr_operations:               extension_cluster.members,
                    thermocycler_rows:            @row_count,
                    thermocycler_columns:         @column_count,
                    force_combination_distance:   @mand_tanneal_comb_diff,
                    prevent_combination_distance: @max_tanneal_comb_diff
                )

        tanneal_clusters = tanneal_graph.perform_clustering use_checkrep #O(q^2)
        extension_cluster_to_tanneal_clusters[extension_cluster] = tanneal_clusters
    end # m * q = n => O(2 * n^2) 

    extension_cluster_to_tanneal_clusters
end

#defaultsObject

Batching settings that work well for the UW BIOFAB PCR workflow which uses 4 X thermocyclers



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pcr_batching.rb', line 60

def defaults
    {
        cycler_count: 4,
        row_count: 8,
        column_count: 12,
        temp_range: 17,
        mand_ext_comb_diff: 30.0,
        mand_tanneal_comb_diff: 0.3,
        max_ext_comb_diff: 300.0,
        max_tanneal_comb_diff: 3.0,
    }
end