Class: Pipeline::BSI::Importer::AddBatch

Inherits:
DataEntryBatch show all
Defined in:
lib/bsi-pipeline/importer.rb

Instance Attribute Summary collapse

Attributes inherited from DataEntryBatch

#client, #id, #properties, #specimens

Instance Method Summary collapse

Constructor Details

#initialize(client, batch_properties) ⇒ AddBatch

Returns a new instance of AddBatch.



19
20
21
# File 'lib/bsi-pipeline/importer.rb', line 19

def initialize(client, batch_properties)
  super client, 'A', batch_properties
end

Instance Attribute Details

#seminal_parentsObject

Returns the value of attribute seminal_parents.



17
18
19
# File 'lib/bsi-pipeline/importer.rb', line 17

def seminal_parents
  @seminal_parents
end

Instance Method Details

#add_specimens(specimens) ⇒ Object



27
28
29
30
31
32
# File 'lib/bsi-pipeline/importer.rb', line 27

def add_specimens(specimens)
  @specimens = specimens
  format
  @bsi.batch.addVials( @id, @specimens.map{ |s| s.to_bfh } )
  nil
end

#commitObject



76
77
78
# File 'lib/bsi-pipeline/importer.rb', line 76

def commit
  @bsi.batch.commit(@id)
end

#formatObject



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
64
65
66
67
68
69
70
71
# File 'lib/bsi-pipeline/importer.rb', line 34

def format
  # Find out how many seminal parents there are

  # Old way of estimating number of seminal parents, different now that we import in groups.
  # num_seminal_parents = @specimens.select{|s| ['N/A', ''].include?( s.parent_id.to_s )}.length

  num_seminal_parents = @specimens.map{|s| [s.date_drawn, s.specimen_type]}.uniq.length

  fails = 0
  begin
  # Reserve Sample ID's for all the seminal parent's
  # Returns and array of strings with both the sampleID and the sequence number in the format: AAA000000 0000
    # Only keep first 6 characters which represent the sample id's (remove the sequence suffix)
    @sample_id_pool = @bsi.batch.reserveAvailableBsiIds( @id, 'LAA000000', num_seminal_parents ).map{|i| i[0..-6]} if num_seminal_parents > 0
  # Not sure why I've been getting this error periodically, but it happens
  rescue NoMethodError
    fails += 1
    retry if fails < 3
  end

  collection_dates = @specimens.map{|s| s.date_drawn}.uniq
  specimen_types   = @specimens.map{|s| s.specimen_type}.uniq
  collection_dates.each do |date|
    specimen_types.each do |type|
      specimen_family = @specimens.select{|s| s.date_drawn == date && s.specimen_type == type}
      family_sample_id = @sample_id_pool.pop
      specimen_family.each_with_index do |spec, i|
        # Assign sample and sequence numbers
        spec.sample_id  = family_sample_id
        unless specimen_family.length == 1
          spec.sequence   = i+1
        else
          spec.sequence   = 0
        end
      end
    end
  end
end

#perform_edit_checksObject



73
74
# File 'lib/bsi-pipeline/importer.rb', line 73

def perform_edit_checks
end

#typeObject



23
24
25
# File 'lib/bsi-pipeline/importer.rb', line 23

def type
  'Add'
end