Files
snpr/app/workers/frequency.rb
Helge Rausch 906eef5403 Update gems (#338)
* Passwords now need to be 8 characters long (new default in authlogic).
* To login to the Sidekiq web interface, log in to opensnp.org, if you
  have the `admin` flag set, you will find it at the usual place.
* I finally found out why Rubocop didn't complain about the frozen string literal pragma missing and added all of them.
* Rubocop complained about keyword arguments, which is only relevant for Rails 5, so I disabled the cop.
* I removed the `inherit_from: .rubocop_todo.yml` from `.rubocop.yml`, so Hound does complain about **all** the issues. I also added a few tasks for running Rubocop.
2017-01-04 15:30:22 +01:00

42 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class Frequency
include Sidekiq::Worker
sidekiq_options queue: :frequency, retry: 5, unique: true
def perform(snp_id)
Snp.reset_counters(snp_id, :user_snps)
s = Snp.find(snp_id)
s.allele_frequency ||= { "A" => 0, "T" => 0, "G" => 0, "C" => 0}
s.genotype_frequency ||= {}
s.user_snps.find_each do |us|
if s.allele_frequency.has_key?(us.local_genotype[0].chr)
s.allele_frequency[us.local_genotype[0].chr] += 1
else
s.allele_frequency[us.local_genotype[0].chr] = 1
end
if us.local_genotype.length > 1
if s.allele_frequency.has_key?(us.local_genotype[1].chr)
s.allele_frequency[us.local_genotype[1].chr] += 1
else
s.allele_frequency[us.local_genotype[1].chr] = 1
end
end
if s.genotype_frequency.has_key?(us.local_genotype.rstrip)
s.genotype_frequency[us.local_genotype.rstrip] += 1
elsif us.local_genotype.length > 1
if s.genotype_frequency.has_key?(us.local_genotype[1].chr+us.local_genotype[0].chr)
s.genotype_frequency[us.local_genotype[1].chr+us.local_genotype[0].chr] += 1
else
s.genotype_frequency[us.local_genotype.rstrip] = 1
end
else
s.genotype_frequency[us.local_genotype.rstrip] = 1
end
end
s.save
end
end