Class: IlluminaC::Helper::TemplateConstructor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ TemplateConstructor

Returns a new instance of TemplateConstructor


30
31
32
33
34
35
36
37
# File 'lib/illumina_c/helper.rb', line 30

def initialize(params)
  self.name = params[:name]
  self.type = params[:type]
  self.role = params[:role]
  self.skip_cherrypick = params[:skip_cherrypick]
  self.sequencing = params[:sequencing] || ACCEPTABLE_SEQUENCING_REQUESTS
  self.catalogue = params[:catalogue]
end

Instance Attribute Details

#catalogueObject

Construct submission templates for the generic pipeline opts is a hash

:name => The Name for the Library Step
:sequencing => Optional array of sequencing request type keys. Default is all.
:role => The role that will be printed on barcodes
:type => 'illumina_c_pcr'||'illumina_c_nopcr'


27
28
29
# File 'lib/illumina_c/helper.rb', line 27

def catalogue
  @catalogue
end

#cherrypick_optionsObject (readonly)

Returns the value of attribute cherrypick_options


28
29
30
# File 'lib/illumina_c/helper.rb', line 28

def cherrypick_options
  @cherrypick_options
end

#nameObject

Construct submission templates for the generic pipeline opts is a hash

:name => The Name for the Library Step
:sequencing => Optional array of sequencing request type keys. Default is all.
:role => The role that will be printed on barcodes
:type => 'illumina_c_pcr'||'illumina_c_nopcr'


27
28
29
# File 'lib/illumina_c/helper.rb', line 27

def name
  @name
end

#roleObject

Construct submission templates for the generic pipeline opts is a hash

:name => The Name for the Library Step
:sequencing => Optional array of sequencing request type keys. Default is all.
:role => The role that will be printed on barcodes
:type => 'illumina_c_pcr'||'illumina_c_nopcr'


27
28
29
# File 'lib/illumina_c/helper.rb', line 27

def role
  @role
end

#sequencingObject

Returns the value of attribute sequencing


28
29
30
# File 'lib/illumina_c/helper.rb', line 28

def sequencing
  @sequencing
end

#typeObject

Construct submission templates for the generic pipeline opts is a hash

:name => The Name for the Library Step
:sequencing => Optional array of sequencing request type keys. Default is all.
:role => The role that will be printed on barcodes
:type => 'illumina_c_pcr'||'illumina_c_nopcr'


27
28
29
# File 'lib/illumina_c/helper.rb', line 27

def type
  @type
end

Class Method Details

.find_for(name, sequencing = nil) ⇒ Object


119
120
121
122
123
124
125
126
# File 'lib/illumina_c/helper.rb', line 119

def self.find_for(name, sequencing = nil)
  tc = TemplateConstructor.new(name: name, sequencing: sequencing)
  [true, false].map do |cherrypick|
    tc.sequencing.map do |sequencing_request_type|
      SubmissionTemplate.find_by!(name: tc.name_for(cherrypick, sequencing_request_type))
    end
  end.flatten
end

Instance Method Details

#build!Object


58
59
60
61
62
63
# File 'lib/illumina_c/helper.rb', line 58

def build!
  validate!
  each_submission_template do |config|
    SubmissionTemplate.create!(config)
  end
end

#cherrypick_request_typeObject


69
70
71
# File 'lib/illumina_c/helper.rb', line 69

def cherrypick_request_type
  RequestType.find_by!(key: 'cherrypick_for_illumina_c')
end

#each_submission_templateObject


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/illumina_c/helper.rb', line 89

def each_submission_template
  cherrypick_options.each do |cherrypick|
    sequencing.each do |sequencing_request_type|
      yield({
        name: name_for(cherrypick, sequencing_request_type),
        submission_class_name: 'LinearSubmission',
        submission_parameters: submission_parameters(cherrypick, sequencing_request_type),
        product_line_id: ProductLine.find_by(name: PIPELINE).id,
        product_catalogue: catalogue
      })
    end
  end
end

#library_request_typeObject


65
66
67
# File 'lib/illumina_c/helper.rb', line 65

def library_request_type
  @library_request_type ||= RequestType.find_by!(key: type)
end

#multiplexing_request_typeObject


73
74
75
# File 'lib/illumina_c/helper.rb', line 73

def multiplexing_request_type
  RequestType.find_by!(key: 'illumina_c_multiplexing')
end

#name_for(cherrypick, sequencing_request_type) ⇒ Object


54
55
56
# File 'lib/illumina_c/helper.rb', line 54

def name_for(cherrypick, sequencing_request_type)
  "#{PIPELINE} - #{cherrypick ? 'Cherrypicked - ' : ''}#{name} - #{sequencing_request_type.name.gsub("#{PIPELINE} ", '')}"
end

#request_type_ids(cherrypick, sequencing) ⇒ Object


77
78
79
80
81
82
83
# File 'lib/illumina_c/helper.rb', line 77

def request_type_ids(cherrypick, sequencing)
  ids = []
  ids << [cherrypick_request_type.id] if cherrypick
  ids << [library_request_type.id]
  ids << [multiplexing_request_type.id] unless library_request_type.for_multiplexing?
  ids << [sequencing.id]
end

#skip_cherrypick=(skip) ⇒ Object


85
86
87
# File 'lib/illumina_c/helper.rb', line 85

def skip_cherrypick=(skip)
  @cherrypick_options = skip ? [false] : [true, false]
end

#submission_parameters(cherrypick, sequencing) ⇒ Object


103
104
105
106
107
108
109
# File 'lib/illumina_c/helper.rb', line 103

def submission_parameters(cherrypick, sequencing)
  {
    request_type_ids_list: request_type_ids(cherrypick, sequencing),
    order_role_id: OrderRole.find_or_create_by(role: role).id,
    info_differential: 1
  }
end

#update!Object


111
112
113
114
115
116
117
# File 'lib/illumina_c/helper.rb', line 111

def update!
  each_submission_template do |options|
    next if options[:submission_parameters][:input_field_infos].nil?

    SubmissionTemplate.find_by!(name: options[:name]).update!(submission_parameters: options[:submission_parameters])
  end
end

#validate!Object


45
46
47
48
49
50
51
52
# File 'lib/illumina_c/helper.rb', line 45

def validate!
  [:name, :type, :role, :catalogue].each do |value|
    raise "Must provide a #{value}" if send(value).nil?
  end
  raise "Request Type should be #{ACCEPTABLE_REQUEST_TYPES.join(', ')}" unless ACCEPTABLE_REQUEST_TYPES.include?(type)

  true
end