Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in MANE preferred transcript from the allele registry #550

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions app/controllers/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class VariantsController < ApplicationController
include WithComment
include WithSoftDeletion

actions_without_auth :index, :show, :typeahead_results, :datatable, :gene_index, :entrez_gene_index, :variant_group_index, :myvariant_info_proxy, :allele_registry_proxy, :variant_navigation
skip_analytics :typeahead_results, :myvariant_info_proxy, :allele_registry_proxy
actions_without_auth :index, :show, :typeahead_results, :datatable, :gene_index, :entrez_gene_index, :variant_group_index, :myvariant_info_proxy, :allele_registry_proxy, :mane_preferred_transcript, :variant_navigation
skip_analytics :typeahead_results, :myvariant_info_proxy, :allele_registry_proxy, :mane_preferred_transcript

def index
variants = Variant.index_scope
Expand Down Expand Up @@ -78,6 +78,10 @@ def allele_registry_proxy
render json: AlleleRegistry.new(params[:variant_id]).response
end

def mane_preferred_transcript
render json: ManePreferredTranscript.new(params[:variant_id]).mane_preferred_transcript
end

private
def variant_params
params.permit(:name, :description, :genome_build, :chromosome, :start, :stop, :reference_bases, :variant_bases, :representative_transcript, :chromosome2, :start2, :stop2, :reference_build, :representative_transcript2, :ensembl_version, variant_types: [])
Expand Down
51 changes: 51 additions & 0 deletions app/models/mane_preferred_transcript.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class ManePreferredTranscript
attr_reader :variant

def initialize(variant_id)
@variant = Variant.find(variant_id)
end

def mane_preferred_transcript
Rails.cache.fetch(cache_key(variant), expires_in: 24.hours) do
if mane_preferred_ref_seq = get_mane_preferred_ref_seq(variant)
transcripts = get_allele_registry_transcripts(variant)
transcripts.find{ |t| t['hgvs'][0].start_with?(mane_preferred_ref_seq) }
end
end
end

def get_allele_registry_transcripts(variant)
allele_response = make_allele_request(variant.allele_registry_id)
JSON.parse(allele_response)['transcriptAlleles']
end

def get_mane_preferred_ref_seq(variant)
gene_response = make_gene_request(variant.gene.name)
JSON.parse(gene_response)[0]['externalRecords']['MANEPrefRefSeq']['id'] rescue nil
end

private
def make_gene_request(gene_name)
Scrapers::Util.make_get_request(gene_url(gene_name))
rescue StandardError
{}
susannasiebert marked this conversation as resolved.
Show resolved Hide resolved
end

def make_allele_request(allele_registry_id)
Scrapers::Util.make_get_request(allele_url(allele_registry_id))
rescue StandardError
susannasiebert marked this conversation as resolved.
Show resolved Hide resolved
{}
end

def gene_url(gene_name)
URI.encode("http://reg.genome.network/genes?name=#{gene_name}")
end

def allele_url(allele_registry_id)
URI.encode("http://reg.genome.network/allele/#{allele_registry_id}")
end

def cache_key(variant)
"mane_preferred_transcript_#{variant.id}_#{variant.hash}"
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
resources 'variants', except: [:edit] do
get 'myvariant_info_proxy' => 'variants#myvariant_info_proxy'
get 'allele_registry_proxy' => 'variants#allele_registry_proxy'
get 'mane_preferred_transcript' => 'variants#mane_preferred_transcript'
get 'evidence_items' => 'evidence_items#variant_index'
get 'variant_groups' => 'variant_groups#variant_index'
get 'assertions' => 'assertions#variant_index'
Expand Down