Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/jobs/generate_tsvs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def ensure_downloads_directory_exists
end

def public_file_path(filename)
desination_filename = [filename_prefix, filename].join('-')
File.join(downloads_dir_path, desination_filename)
destination_filename = [filename_prefix, filename].join('-')
File.join(downloads_dir_path, destination_filename)
end

def downloads_dir_path
Expand Down
45 changes: 45 additions & 0 deletions app/jobs/generate_uniprot_mapping_tsv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class GenerateUniprotMappingTsv < ApplicationJob
def perform
ensure_downloads_directory_exists
p = UniprotMappingTsvPresenter
begin
tmp_file = tmp_file(p.file_name)
tmp_file.puts(p.headers.join("\t"))

Gene.joins(variants: :evidence_items).distinct.find_each do |gene|
rows = p.rows_from_object(gene)

rows.each do |r|
tmp_file.puts(r.join("\t"))
end
end
tmp_file.close
public_path = public_file_path(p.file_name)
FileUtils.cp(tmp_file.path, public_path)
File.chmod(0644, public_path)
ensure
tmp_file.unlink
end
end

private
def tmp_file(filename)
Tempfile.new(filename, File.join(Rails.root, 'tmp'))
end

def ensure_downloads_directory_exists
FileUtils.mkdir_p(downloads_dir_path)
end

def tsvs_to_generate
[UniprotMappingTsvPresenter]
end

def public_file_path(filename)
File.join(downloads_dir_path, filename)
end

def downloads_dir_path
TsvRelease.downloads_path
end
end
32 changes: 32 additions & 0 deletions app/presenters/uniprot_mapping_tsv_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class UniprotMappingTsvPresenter
def self.headers
[
'civic_name',
'uniprot_name',
'gene_overview'
]
end

def self.rows_from_object(gene)
swissprot_names = Array(Scrapers::MyGeneInfo.get_swissprot_name(gene))
formatted_overview = formatted_overview_col(gene)
swissprot_names.map do |n|
if n == "N/A"
nil
else
[gene.name, n, formatted_overview]
end
end.compact
end

def self.file_name
"UniprotMapping.tsv"
end

def self.formatted_overview_col(gene)
eid_count = EvidenceItem.joins(variant: [:gene]).where("evidence_items.status != 'rejected'").where(variants: {gene: gene}).distinct.count
variant_count = gene.variants.joins(:evidence_items).where("evidence_items.status != 'rejected'").distinct.count
assertion_count = gene.assertions.where("status != 'rejected'").distinct.count
"#{assertion_count} clinical assertion(s) and #{eid_count} evidence item(s) for #{variant_count} variant(s) curated from #{gene.sources.size} published source(s)"
end
end
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ test:
production:
<<: *default
pool: 20
database: civic
database: civic
6 changes: 6 additions & 0 deletions config/scheduled_tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ GenerateMonthlyTsvs:
queue: default
class: GenerateMonthlyTsvs

GenerateUniprotMappingTsv:
cron: '0 0 1 * *'
description: Update the UniprotMapping tsv
queue: default
class: GenerateUniprotMappingTsv

GenerateNightlyTsvs:
cron: '0 0 * * *'
description: Update the nightly TSV dumps
Expand Down
19 changes: 19 additions & 0 deletions lib/scrapers/my_gene_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,24 @@ def self.extract_entrez_id(data)
def self.extract_official_name(data)
data['hits'].first['name']
end

private
def self.url_for_uniprot(gene_symbol)
"http://mygene.info/v2/query/?q=symbol:#{gene_symbol}&species=human&entrezonly=1&limit=1&fields=uniprot"
end

def self.get_swissprot_name(gene)
resp = Util.make_get_request(url_for_uniprot(gene.name))
data = JSON.parse(resp)
extract_swissprot_name(data)
end

def self.extract_swissprot_name(data)
if data['hits'].first != nil and data['hits'].first['uniprot'] != nil
data['hits'].first['uniprot']['Swiss-Prot']
else
'N/A'
end
end
end
end
Loading