Skip to content

Commit

Permalink
Add phenotype_updated column to snps table
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Rai <vivekrai.iitkgp@gmail.com>
  • Loading branch information
raivivek committed Jun 20, 2016
1 parent 286900f commit 9e0d8b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/models/phenotype.rb
Expand Up @@ -4,7 +4,6 @@ class Phenotype < ActiveRecord::Base
has_many :user_phenotypes, dependent: :destroy
has_many :phenotype_comments, dependent: :destroy
has_and_belongs_to_many :phenotype_sets
has_and_belongs_to_many :snps

has_many :phenotype_snps
has_many :snps, through: :phenotype_snps
Expand Down
9 changes: 9 additions & 0 deletions app/models/snp.rb
Expand Up @@ -46,6 +46,15 @@ def self.update_frequencies
end
end

def self.update_phenotypes
max_age = 31.days.ago

Snp.select([:id, :phenotype_updated]).where(phenotype_updated < max_age)
.find_each do |snp|
Sidekiq::Client.enqueue(SnpToPhenotype, snp.id)
end
end

%w(snpedia mendeley genome_gov plos).each do |source|
define_method(:"#{source}_papers") do
klass = "#{source.camelize}Paper".constantize
Expand Down
Expand Up @@ -4,8 +4,9 @@ class SnpToPhenotype
attr_reader :snp, :client

def perform(snp_id)
# could possible use the max_age limit here
@snp = Snp.find(snp_id)
if snp && valid_snp_names.include?(snp.name) && snp.phenotypes_updated < 31.days.ago
if snp && valid_snp_names.include?(snp.name)
score_pehnotype
end
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20160517034748_add_phenotype_updated_to_snps.rb
@@ -0,0 +1,5 @@
class AddPhenotypeUpdatedToSnps < ActiveRecord::Migration
def change
add_column :snps, :phenotype_updated, :timestamp
end
end

0 comments on commit 9e0d8b8

Please sign in to comment.