Skip to content

Commit

Permalink
gene names are now in the positional overview window (implementation …
Browse files Browse the repository at this point in the history
…for #37); added clickable links and revised the related variants in the positional overview window
  • Loading branch information
laurensvdwiel committed Apr 17, 2019
1 parent 457299b commit 59fa0ed
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
21 changes: 21 additions & 0 deletions metadome/domain/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ class MalformedAARegionException(Exception):

class GeneRepository:

@staticmethod
def retrieve_gene_names_for_multiple_transcript_ids(_transcript_ids):
"""Retrieves all gene names for a given set of gencode transcripts
based on multiple Gene objects as {gencode_transcription_id: gene_name}"""
# Open as session
_session = db.create_scoped_session()

try:
_gene_name_per_gencode_transcription_id = {}
for gene in _session.query(Gene).filter(Gene.gencode_transcription_id.in_(_transcript_ids)).all():
_gene_name_per_gencode_transcription_id[gene.gencode_transcription_id] = gene.gene_name
return _gene_name_per_gencode_transcription_id
except (AlchemyResourceClosedError, AlchemyOperationalError, PsycopOperationalError) as e:
raise RecoverableError(str(e))
except:
_log.error(traceback.format_exc())
raise
finally:
# Close this session, thus all items are cleared and memory usage is kept at a minimum
_session.remove()

@staticmethod
def retrieve_transcript_id_for_multiple_gene_ids(_gene_ids):
"""Retrieves all gencode transcripts for multiple Gene objects as {gene_id: gencode_transcription_id}"""
Expand Down
30 changes: 15 additions & 15 deletions metadome/presentation/web/templates/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ function createClinVarTableHeader(){
// Define the header
html_table += '<table class="table is-hoverable is-narrow">';
html_table += '<thead><tr style="border-style:hidden;">';
html_table += '<th><abbr title="Chromosome">Chr</abbr></th>';
html_table += '<th><abbr title="Chromosome poition">Pos</abbr></th>';
html_table += '<th><abbr title="Change of codon">Codon change</abbr></th>';
html_table += '<th><abbr title="Gene Symbol">Gene</abbr></th>';
html_table += '<th><abbr title="Chromosomal position">Position</abbr></th>';
html_table += '<th><abbr title="Change of nucleotide">Variant</abbr></th>';
html_table += '<th><abbr title="Change of residue">Residue change</abbr></th>';
html_table += '<th><abbr title="Type of mutation">Type</abbr></th>';
html_table += '<th><abbr title="ClinVar Identifier">ClinVar ID</abbr></th>';
Expand All @@ -800,9 +800,9 @@ function createClinVarTableBody(ClinvarVariants){
for (var index = 0; index < ClinvarVariants.length; index++){
var variant = ClinvarVariants[index];
html_table += '<tr>';
html_table += '<td>'+variant.chr+'</td>';
html_table += '<td>'+variant.chr_positions+'</td>';
html_table += '<td>'+variant.ref_codon+'>'+variant.alt_codon+'</td>';
html_table += '<td>'+variant.gene_name+'</td>';
html_table += '<td><a href="http://grch37.ensembl.org/Homo_sapiens/Location/View?db=core;r='+variant.chr.substr(3)+':'+variant.pos+'" target="_blank">'+variant.chr+':'+variant.pos+'</a></td>';
html_table += '<td>'+variant.ref+'>'+variant.alt+'</td>';
html_table += '<td>'+variant.ref_aa_triplet+'>'+variant.alt_aa_triplet+'</td>';
html_table += '<td>'+variant.type+'</td>';
html_table += '<td><a href="https://www.ncbi.nlm.nih.gov/clinvar/variation/' + variant.clinvar_ID + '/" target="_blank">' + variant.clinvar_ID + '</a></td>';
Expand All @@ -817,12 +817,12 @@ function createGnomADTableHeader(){
// Define the header
html_table += '<table class="table is-hoverable is-narrow">';
html_table += '<thead><tr style="border-style:hidden;">';
html_table += '<th><abbr title="Chromosome">Chr</abbr></th>';
html_table += '<th><abbr title="Chromosome poition">Pos</abbr></th>';
html_table += '<th><abbr title="Change of codon">Codon change</abbr></th>';
html_table += '<th><abbr title="Gene Symbol">Gene</abbr></th>';
html_table += '<th><abbr title="Chromosomal position">Position</abbr></th>';
html_table += '<th><abbr title="Change of nucleotide">Variant</abbr></th>';
html_table += '<th><abbr title="Change of residue">Residue change</abbr></th>';
html_table += '<th><abbr title="Type of mutation">Type</abbr></th>';
html_table += '<th><abbr title="Allele frequency">Allele Frequency</abbr></th>';
html_table += '<th><abbr title="Allele frequency">gnomAD Allele Frequency</abbr></th>';
html_table += '</tr></thead><tfoot></tfoot><tbody>';
return html_table;
}
Expand All @@ -833,12 +833,12 @@ function createGnomADTableBody(gnomADVariants){
for (var index = 0; index < gnomADVariants.length; index++){
var variant = gnomADVariants[index];
html_table += '<tr>';
html_table += '<td>'+variant.chr+'</td>';
html_table += '<td>'+variant.chr_positions+'</td>';
html_table += '<td>'+variant.ref_codon+'>'+variant.alt_codon+'</td>';
html_table += '<td>'+variant.gene_name+'</td>';
html_table += '<td><a href="http://grch37.ensembl.org/Homo_sapiens/Location/View?db=core;r='+variant.chr.substr(3)+':'+variant.pos+'" target="_blank">'+variant.chr+':'+variant.pos+'</a></td>';
html_table += '<td>'+variant.ref+'>'+variant.alt+'</td>';
html_table += '<td>'+variant.ref_aa_triplet+'>'+variant.alt_aa_triplet+'</td>';
html_table += '<td>'+variant.type+'</td>';
html_table += '<td>' + parseFloat(variant.allele_count/variant.allele_number).toFixed(6) + '</td>';
html_table += '<td>'+variant.type+'</td>';
html_table += '<td><a href="https://gnomad.broadinstitute.org/variant/'+variant.chr+'-'+variant.pos+'-'+variant.ref+'-'+variant.alt +'" target="_blank">'+parseFloat(variant.allele_count/variant.allele_number).toFixed(6)+'</a></td>';
html_table += '</tr>';
}

Expand Down
17 changes: 16 additions & 1 deletion metadome/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
UnsupportedMetaDomainIdentifier
from metadome.domain.services.computation.gene_region_computations import compute_tolerance_landscape
from metadome.domain.services.annotation.gene_region_annotators import annotateTranscriptWithClinvarData
from metadome.domain.services.annotation.annotation import annotateSNVs
from metadome.domain.services.annotation.annotation import annotateSNVs,\
convertNucleotide
from metadome.controllers.job import store_error, store_visualization
from metadome.domain.error import RecoverableError
import numpy as np
Expand All @@ -18,6 +19,7 @@
import json
import os
import logging
from metadome.domain.models.gene import Strand

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -147,6 +149,11 @@ def retrieve_metadomain_annotation(transcript_id, protein_position, domain_posit
# Retrieve the meta SNVs for this position
meta_snvs = meta_domain.get_annotated_SNVs_for_consensus_position(consensus_position)

# Retrieve the matching gene names for the transcripts
transcript_ids = [meta_snvs[meta_snv_repr][0]['gencode_transcription_id'] for meta_snv_repr in meta_snvs.keys()]
transcripts_to_gene = GeneRepository.retrieve_gene_names_for_multiple_transcript_ids(transcript_ids)

# hier ergens iets doen: retrieve_gene_names_for_multiple_transcript_ids???
# iterate over meta_codons and add to metadom_entry
for meta_snv_repr in meta_snvs.keys():
if not current_codon.unique_str_representation() in meta_snv_repr:
Expand All @@ -156,9 +163,17 @@ def retrieve_metadomain_annotation(transcript_id, protein_position, domain_posit
# initiate the SNV variant
snv_variant = SingleNucleotideVariant.initializeFromDict(meta_snv)

# Convert to the original nucleotide
if snv_variant.strand == Strand.minus:
snv_variant.ref_nucleotide = convertNucleotide(snv_variant.ref_nucleotide)
snv_variant.alt_nucleotide = convertNucleotide(snv_variant.alt_nucleotide)

# start the variant entry and add the codon based information
variant_entry = snv_variant.toCodonJson()

# Add the gene name
variant_entry['gene_name'] = transcripts_to_gene[snv_variant.gencode_transcription_id]

# Add the variant specific information
if meta_snv['variant_source'] == 'gnomAD':
# convert the variant to the expected format
Expand Down

0 comments on commit 59fa0ed

Please sign in to comment.