Hi,
I am reading some floating point numbers from one excel column to other column. While it is pasting/inserting the value to new column of the excel, it is rounding the values to 1. How can I preserve the actual value?
My rake task:
desc 'pull gnome data in memory'
task :store_in_memory do
puts "Starts caching"
start_row = 2 # should be changed as per the sheet organization
last_row = 2244 # should be changed as per the sheet organization
CAID_CELL = 6
MAF_CELL = 18
sheet = Alleleregistry::SpreadSheet.new('POLG-gnomAD.xlsx')
sheet.each_row(start_row) do |row|
break if row.r > last_row
caid = sheet.read_from_cell(row, CAID_CELL)
maf = sheet.read_from_cell(row, MAF_CELL)
puts maf.inspect
break if row.r > 5
cache_store.put caid, maf.to_f
end
puts "Cache size is: #{cache_store.size}"
puts "Finshed caching"
end
And the SpreadSheet class is
require 'rubyXL'
module Alleleregistry
class SpreadSheet
HGVS_VELL_CELL = 12
CAID_CELL = 13
MAF_CELL = 14
CLIN_VAR_URL_CELL = 15
def initialize path_to_file
@workbook = RubyXL::Parser.parse(File.expand_path("../../data/#{path_to_file}", __dir__))
end
def write_to_cell row, col, val
worksheet.add_cell(row, col, val)
end
def read_from_cell row, col
row.cells[col].value
end
def each_row start_row = 1, &block
worksheet.each do |row|
next if row && row.r < start_row
yield row
end
ensure
@workbook.save
end
private
def worksheet
@worksheet ||= @workbook[0]
end
end
end
Here is the full repo of the code: https://gitlab.com/aruprakshit/alleleregistry
sample values when it reads from the excel column looks like:
arup@ror ~/Ruby/alleleregistry (master)$ rake spreadsheet:store_in_memory
Starts caching
3.229e-05
0.0003874
0.03139
6.456e-05
0.0001292
Cache size is: 4
Finshed caching
Thanks,
~A