forked from openSNP/snpr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vivek Rai <vivekrai.iitkgp@gmail.com>
- Loading branch information
Showing
7 changed files
with
262 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class PhenotypeSnp < ActiveRecord::Base | ||
include PgSearchCommon | ||
|
||
belongs_to :snp | ||
belongs_to :phenotype | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
class SnpToPhenotype | ||
include Sidekiq::Worker | ||
sidekiq_options :queue => :snp_phenotype, :retry => 5, :unique => true | ||
attr_reader :snp, :client | ||
|
||
def perform(snp_id) | ||
@snp = Snp.find(snp_id) | ||
if snp && valid_snp_names.include?(snp.name) && snp.phenotypes_updated < 31.days.ago | ||
score_pehnotype | ||
end | ||
end | ||
|
||
def score_phenotype | ||
# TODO: | ||
# - fetch papers metadata corresponding to the SNP | ||
# - fetch all the stored phenotypes | ||
# - search for each phenotype one by one in the papers' metadata | ||
# - maintain a hash of the phenotypes along with score | ||
# - return entire hash | ||
|
||
end | ||
|
||
def top_phenotypes(limit) | ||
# - return top phenotypes based on score from the hash | ||
end | ||
|
||
def perform_search | ||
# return an array of page-titles | ||
pages = client.list("#{snp.name}(") | ||
snpedia_updated = false | ||
(pages || []).each do |page| | ||
next unless page.include?('(') | ||
url = "http://www.snpedia.com/index.php/#{page}" | ||
# revision returns an int which grows with changes | ||
rev_id = client.revision(page).to_i | ||
snpedia_paper = SnpediaPaper.find_or_initialize_by(url: url) | ||
next if snpedia_paper.persisted? && snpedia_paper.revision == rev_id | ||
to_parse = client.get(page) | ||
next if to_parse.to_s.include?('#REDIRECT') | ||
/summary=(?<summary>.*)\}\}/m =~ to_parse | ||
snpedia_paper.update_attributes!( | ||
url: url, summary: summary, revision: rev_id) | ||
snpedia_paper.snps << snp unless snpedia_paper.snps.include? snp | ||
snpedia_updated = true | ||
end | ||
snp.snpedia_updated! if snpedia_updated | ||
if Rails.env == 'production' | ||
# Increase this value if the following error keeps on showing up | ||
# 'MediaWiki::APIError: API error: code 'internal_api_error_DBConnectionError', | ||
# info 'Exception Caught: DB connection error: Too many connections' | ||
sleep(10) | ||
end | ||
end | ||
|
||
def valid_snp_names | ||
Marshal.load(File.read(Rails.root.join('marshalled_snpedia_array'))) | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20160515212622_create_join_table_phenotype_snp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateJoinTablePhenotypeSnp < ActiveRecord::Migration | ||
def self.up | ||
# see rails naming convention for naming JOIN tables | ||
create_table :phenotype_snps do |t| | ||
t.references :snp | ||
t.references :phenotype | ||
t.float :score | ||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :phenotype_snps | ||
end | ||
end |
Oops, something went wrong.