Class: Parsers::PbmcCountParser

Inherits:
Object
  • Object
show all
Defined in:
app/models/parsers/pbmc_count_parser.rb

Overview

A parser for the cardinal and scrna pipeline qc files

Constant Summary collapse

HEADERS =
[
  'Well Name',
  'Live Count',
  'Live Cells/mL',
  'Live Mean Size',
  'Viability',
  'Dead Count',
  'Dead Cells/mL',
  'Dead Mean Size',
  'Total Count',
  'Total Cells/mL',
  'Total Mean Size',
  'Note:',
  'Errors:'
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ PbmcCountParser

Returns a new instance of PbmcCountParser.



32
33
34
# File 'app/models/parsers/pbmc_count_parser.rb', line 32

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



30
31
32
# File 'app/models/parsers/pbmc_count_parser.rb', line 30

def content
  @content
end

Class Method Details

.parses?(content) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/parsers/pbmc_count_parser.rb', line 26

def self.parses?(content)
  content.split('\r\n')[0][0] == HEADERS
end

Instance Method Details

#each_well_and_parametersObject



64
65
66
# File 'app/models/parsers/pbmc_count_parser.rb', line 64

def each_well_and_parameters(&)
  qc_data.each(&)
end

#empty_row?(row) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/parsers/pbmc_count_parser.rb', line 56

def empty_row?(row)
  row[0].blank?
end

#get_well_location(cell) ⇒ Object



60
61
62
# File 'app/models/parsers/pbmc_count_parser.rb', line 60

def get_well_location(cell)
  cell.split(':')[1]
end

#qc_dataObject

0 - well name 2 - live cell count 4 - viability 9 - total cell count



44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/parsers/pbmc_count_parser.rb', line 44

def qc_data
  @qc_data ||=
    {}.tap do |qc_data|
      rows.each do |row|
        next if empty_row?(row)

        well = get_well_location(row[0])
        qc_data[well] = qc_metrics_hash(row)
      end
    end
end

#qc_metrics_hash(row) ⇒ Object



68
69
70
71
72
73
74
75
# File 'app/models/parsers/pbmc_count_parser.rb', line 68

def qc_metrics_hash(row)
  {}.tap do |hash|
    hash[:live_cell_count] = Unit.new(row[2], 'cells')
    hash[:total_cell_count] = Unit.new(row[9], 'cells')
    viability = row[4]
    hash[:viability] = Unit.new(viability) unless viability == 'NaN'
  end
end

#rowsObject



36
37
38
# File 'app/models/parsers/pbmc_count_parser.rb', line 36

def rows
  @rows ||= content.drop(1)
end