Class: MbraveTagsCreator
- Inherits:
-
Object
- Object
- MbraveTagsCreator
- Extended by:
- StaticMethods
- Defined in:
- lib/mbrave_tags_creator.rb
Overview
Class to support creation of tag groups, tag layout templates and generation of the mbrave.yml config needed by limber to be able to generate the mbrave UMI file at the end of the bioscan process. rubocop:disable Metrics/ClassLength
Defined Under Namespace
Modules: StaticMethods
Constant Summary collapse
- YAML_FILENAME =
'mbrave.yml'
- TAG_IDENTIFIER =
'Bioscan'
Instance Attribute Summary collapse
-
#forward_filename ⇒ Object
readonly
Returns the value of attribute forward_filename.
-
#forward_group ⇒ Object
readonly
Returns the value of attribute forward_group.
-
#reverse_filename ⇒ Object
readonly
Returns the value of attribute reverse_filename.
-
#reverse_groups ⇒ Object
readonly
Returns the value of attribute reverse_groups.
-
#tag_identifier ⇒ Object
readonly
Returns the value of attribute tag_identifier.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#yaml_filename ⇒ Object
readonly
Returns the value of attribute yaml_filename.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_1_tag_group_forward ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
- #create_24_tag_groups_reverse ⇒ Object
-
#create_tag_layout_templates ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength.
- #forward_tag_group_name ⇒ Object
-
#initialize(params) ⇒ MbraveTagsCreator
constructor
A new instance of MbraveTagsCreator.
- #log_line ⇒ Object
- #reverse_tag_group_name(group) ⇒ Object
- #tag_layout_template_name(group) ⇒ Object
- #write_yaml(yaml_filename) ⇒ Object
Methods included from StaticMethods
create_tag_plates, process_create_tag_groups, process_create_tag_plates, text_code_for_tag_layout
Constructor Details
#initialize(params) ⇒ MbraveTagsCreator
Returns a new instance of MbraveTagsCreator.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mbrave_tags_creator.rb', line 18 def initialize(params) @forward_filename = params[:forward_filename] @reverse_filename = params[:reverse_filename] @tag_identifier = params[:tag_identifier] @version = params[:version] @yaml_filename = params[:yaml_filename] @forward_group = nil @reverse_groups = [] @yaml_contents = {} end |
Instance Attribute Details
#forward_filename ⇒ Object (readonly)
Returns the value of attribute forward_filename.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def forward_filename @forward_filename end |
#forward_group ⇒ Object (readonly)
Returns the value of attribute forward_group.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def forward_group @forward_group end |
#reverse_filename ⇒ Object (readonly)
Returns the value of attribute reverse_filename.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def reverse_filename @reverse_filename end |
#reverse_groups ⇒ Object (readonly)
Returns the value of attribute reverse_groups.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def reverse_groups @reverse_groups end |
#tag_identifier ⇒ Object (readonly)
Returns the value of attribute tag_identifier.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def tag_identifier @tag_identifier end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def version @version end |
#yaml_filename ⇒ Object (readonly)
Returns the value of attribute yaml_filename.
10 11 12 |
# File 'lib/mbrave_tags_creator.rb', line 10 def yaml_filename @yaml_filename end |
Class Method Details
.log_line ⇒ Object
34 35 36 37 38 39 |
# File 'lib/mbrave_tags_creator.rb', line 34 def self.log_line # We want to enforce that logs go to STDOUT while printing the barcodes # rubocop:disable Rails/Output puts yield # rubocop:enable Rails/Output end |
Instance Method Details
#create_1_tag_group_forward ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mbrave_tags_creator.rb', line 54 def create_1_tag_group_forward = [] = [] log_line { "Creating forward_tags from: #{forward_filename}" } CSV.foreach(forward_filename, headers: true) do |row| tag = Tag.new(map_id: row['Forward Index Number'], oligo: row['F index sequence']) .push(tag) .push(row['Forward Oligo Label']) end log_line { " - #{forward_tag_group_name}" } @forward_group = _create_tag_group(forward_tag_group_name, ) _add_to_yaml(yaml_filename, forward_tag_group_name, , version, 1) end |
#create_24_tag_groups_reverse ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/mbrave_tags_creator.rb', line 68 def create_24_tag_groups_reverse = [] = [] group = 1 log_line { "Creating reverse tags from: #{reverse_filename}" } CSV.foreach(reverse_filename, headers: true) do |row| _validate_reverse_row(row) map_id = row['Reverse Index Number'].to_i pos = ((map_id - 1) % 4) + 1 tag = Tag.new(map_id: pos, oligo: row['R index sequence']) .push(tag) .push(row['Reverse Oligo Label']) if pos == 4 log_line { " - #{reverse_tag_group_name(group)}" } @reverse_groups.push(_create_tag_group(reverse_tag_group_name(group), )) _add_to_yaml(yaml_filename, reverse_tag_group_name(group), , version, group) group += 1 = [] = [] end end end |
#create_tag_layout_templates ⇒ Object
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mbrave_tags_creator.rb', line 95 def create_tag_layout_templates log_line { 'Creating tag layout templates:' } @reverse_groups.each_with_index do |reverse_group, index| log_line { " - #{tag_layout_template_name(index)}" } TagLayoutTemplate.create( name: tag_layout_template_name(index), tag_group: @forward_group, tag2_group: reverse_group, direction_algorithm: 'TagLayout::InColumnsThenColumns', walking_algorithm: 'TagLayout::Quadrants', enabled: true ) end end |
#forward_tag_group_name ⇒ Object
114 115 116 |
# File 'lib/mbrave_tags_creator.rb', line 114 def forward_tag_group_name "#{tag_identifier}_forward_96_#{version}" end |
#log_line ⇒ Object
29 30 31 32 |
# File 'lib/mbrave_tags_creator.rb', line 29 def log_line(&) # We want to enforce that logs go to STDOUT while printing the barcodes self.class.log_line(&) end |
#reverse_tag_group_name(group) ⇒ Object
118 119 120 |
# File 'lib/mbrave_tags_creator.rb', line 118 def reverse_tag_group_name(group) "#{tag_identifier}_reverse_4_#{group}_#{version}" end |
#tag_layout_template_name(group) ⇒ Object
110 111 112 |
# File 'lib/mbrave_tags_creator.rb', line 110 def tag_layout_template_name(group) "#{tag_identifier}_384_template_#{group + 1}_#{version}" end |
#write_yaml(yaml_filename) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mbrave_tags_creator.rb', line 41 def write_yaml(yaml_filename) log_line { "Generating file #{yaml_filename}" } new_contents = {} new_contents['development'] = @yaml_contents new_contents['test'] = @yaml_contents new_contents['staging'] = @yaml_contents new_contents['training'] = @yaml_contents new_contents['production'] = @yaml_contents File.write(yaml_filename, new_contents.to_yaml) end |