Class: Import::Descriptors::ModifyGeneDescriptorInterpreter

Inherits:
BatchLoad::Import
  • Object
show all
Defined in:
lib/batch_load/import/descriptors/modify_gene_descriptor_interpreter.rb

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ModifyGeneDescriptorInterpreter

Returns a new instance of ModifyGeneDescriptorInterpreter.

Parameters:

  • args (Hash)


5
6
7
8
# File 'lib/batch_load/import/descriptors/modify_gene_descriptor_interpreter.rb', line 5

def initialize(**args)
  @descriptors = {}
  super(args)
end

Instance Method Details

#buildBoolean

Returns:

  • (Boolean)


66
67
68
69
70
71
# File 'lib/batch_load/import/descriptors/modify_gene_descriptor_interpreter.rb', line 66

def build
  if valid?
    build_descriptors
    @processed = true
  end
end

#build_descriptorsInteger

Returns:

  • (Integer)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/batch_load/import/descriptors/modify_gene_descriptor_interpreter.rb', line 11

def build_descriptors
  @total_data_lines = 0
  i = 0

  # loop through rows
  csv.each do |row|
    i += 1

    parse_result = BatchLoad::RowParse.new
    parse_result.objects[:descriptor] = []

    @processed_rows[i] = parse_result

    begin # processing
      # Find gene descriptor
      gene_name = row['gene_name']
      gene_descriptor = Descriptor::Gene.find_by(name: gene_name)
      next if gene_descriptor.blank?

      # Store gene attribute logic for each primer
      primers_logic = { "forward_primers": [], "reverse_primers": [] }

      # Find each forward/reverse primers and store their gene attribute logic
      ['forward_primers', 'reverse_primers'].each do |primer_type|
        primers = row[primer_type]
        next if primers.blank?
        sequence_relationship_type = 'SequenceRelationship::' + primer_type.singularize.camelize

        primers.split(', ').each do |primer_name|
          primer_sequence = Sequence.with_any_value_for(:name, primer_name).take
          next if primer_sequence.blank?

          gene_attribute = GeneAttribute.find_by(descriptor: gene_descriptor, sequence: primer_sequence, sequence_relationship_type: sequence_relationship_type)
          next if gene_attribute.blank?

          primers_logic[primer_type.to_sym].push(gene_attribute.to_logic_literal)
        end
      end

      gene_descriptor_logic = ''
      gene_descriptor_logic += '(' + primers_logic[:forward_primers].join(' OR ') + ')'
      gene_descriptor_logic += ' AND '
      gene_descriptor_logic += '(' + primers_logic[:reverse_primers].join(' OR ') + ')'
      gene_descriptor.gene_attribute_logic = gene_descriptor_logic
      parse_result.objects[:descriptor].push(gene_descriptor)
      @total_data_lines += 1
    # rescue
    end
  end


  @total_lines = i
end