Skip to content

Commit

Permalink
issue #758 - configure quick links via settings
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed May 13, 2024
1 parent e2e6fb5 commit f208b94
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
9 changes: 4 additions & 5 deletions snpdb/variant_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ def variant_link_info(variant: Variant, genome_build: GenomeBuild) -> dict[str,
link_data['variant_string'] = str(variant)
link_data['variant_svlen'] = variant.svlen
link_data['genome_build'] = genome_build.name
link_data['canonical_c_hgvs'] = variant.get_canonical_c_hgvs(genome_build)

if cta := variant.get_canonical_transcript_annotation(genome_build):
link_data['canonical_c_hgvs'] = cta.get_hgvs_c_with_symbol()
link_data['gene_symbol'] = cta.symbol

# If we can include these in link_data we'll get more links
#
# SpecialEKeys.C_HGVS,
# SpecialEKeys.VARIANT_COORDINATE,
# SpecialEKeys.GENE_SYMBOL,
# SpecialEKeys.REFSEQ_TRANSCRIPT_ID,
# SpecialEKeys.P_HGVS,
#
# SpecialEKeys.CLINGEN_ALLELE_ID,
# SpecialEKeys.GENOME_BUILD,
# SpecialEKeys.UNIPROT_ID,
# SpecialEKeys.CLINVAR_VARIANTION_ID,
# SpecialEKeys.HGNC_ID,
Expand Down
5 changes: 5 additions & 0 deletions variantgrid/settings/components/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@
VARIANT_DETAILS_SHOW_SAMPLES = True
VARIANT_DETAILS_NEARBY_RANGE = 50
VARIANT_DETAILS_NEARBY_SHOW_GENE = False

# Can only use block or allow list. Use "text" value of link (see vc_links.js)
VARIANT_DETAILS_QUICK_LINKS_ALLOW_LIST = []
VARIANT_DETAILS_QUICK_LINKS_BLOCK_LIST = []

VARIANT_VCF_DB_PREFIX = "vg"
VARIANT_MANUAL_CREATE = True
VARIANT_MANUAL_CREATE_BY_NON_ADMIN = True
Expand Down
41 changes: 32 additions & 9 deletions variantgrid/static_files/default_static/js/vc_links.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let VCLink = (function() {
this.missing = params.missing;
this.title = params.title;
this.build = params.build;
this.geneLink = Boolean(params.geneLink);
};

VCLink.prototype = {
Expand Down Expand Up @@ -59,7 +60,8 @@ EMPTY_LINK = new VCLink({
href: null,
missing: true,
title: null,
build: null
build: null,
geneLink: false,
});

let VCLinks = (function() {
Expand Down Expand Up @@ -142,6 +144,24 @@ let VCLinks = (function() {
return links;
},

filterLinks(links, allowMissing, allowList, blockList) {
const allowSet = new Set(allowList);
const blockSet = new Set(blockList);
if (allowSet.size && blockSet.size) {
throw new Error("filterLinks: can only pass EITHER allowList OR blockList not both")
}
if (!allowMissing) {
links = links.filter(link => !link.isMissing());
}
if (allowSet.size) {
links = links.filter(link => allowSet.has(link.text));
}
if (blockSet.size) {
links = links.filter(link => !blockSet.has(link.text));
}
return links;
},

buildName() {
let genome_build = this.data[SpecialEKeys.GENOME_BUILD];
if (genome_build) {
Expand All @@ -164,36 +184,38 @@ let VCLinks = (function() {
generateMonarchLink() {
let hgnc_id = this.hgncIdSafe();
if (hgnc_id) {
return new VCLink({text: 'Monarch Phen.', title:"Monarch Phenotype (Gene)", href: `https://monarchinitiative.org/gene/${hgnc_id}`});
return new VCLink({text: 'Monarch Phen.', title:"Monarch Phenotype (Gene)", href: `https://monarchinitiative.org/gene/${hgnc_id}`, geneLink: true});
}
let gene_symbol = this.data[SpecialEKeys.GENE_SYMBOL];
if (gene_symbol) {
return new VCLink({text: 'Monarch Phen,', title:"Monarch Phenotype (Gene)", href: `https://monarchinitiative.org/search/${gene_symbol}`});
return new VCLink({text: 'Monarch Phen,', title:"Monarch Phenotype (Gene)", href: `https://monarchinitiative.org/search/${gene_symbol}`, geneLink: true});
}

return new VCLink({
text: 'Monarch Phen',
href: 'https://monarchinitiative.org',
missing: this.eKeys.key(SpecialEKeys.HGNC_ID).label
missing: this.eKeys.key(SpecialEKeys.HGNC_ID).label,
geneLink: true
});
},

generateClingenKb() {
let hgnc_id = this.hgncIdSafe();
if (hgnc_id) {
let link = `https://search.clinicalgenome.org/kb/genes/${hgnc_id}`;
return new VCLink({text: 'ClinGen KB', href: link});
return new VCLink({text: 'ClinGen KB', href: link, geneLink: true});
}
let gene_symbol = this.data[SpecialEKeys.GENE_SYMBOL];
if (gene_symbol) {
let link = `https://search.clinicalgenome.org/kb/genes?search=${gene_symbol}`;
return new VCLink({text: 'ClinGen KB', href: link});
return new VCLink({text: 'ClinGen KB', href: link, geneLink: true});
}

return new VCLink({
text: 'ClinGen KB',
href: 'https://search.clinicalgenome.org/kb/genes',
missing: this.eKeys.key(SpecialEKeys.HGNC_ID).label
missing: this.eKeys.key(SpecialEKeys.HGNC_ID).label,
geneLink: true,
});
},

Expand Down Expand Up @@ -344,12 +366,13 @@ let VCLinks = (function() {
},

makeLink(text, link, param, key, title) {
let geneLink = key == SpecialEKeys.GENE_SYMBOL;
let val = this.data[key];
if (val) {
link = link + param.replace('@@', encodeURIComponent(val));
return new VCLink({text:text, href:link, title: title});
return new VCLink({text:text, href:link, title: title, geneLink: geneLink});
} else {
return new VCLink({text:text, href:link, missing:this.eKeys.key(key).label, title: title});
return new VCLink({text:text, href:link, missing:this.eKeys.key(key).label, title: title, geneLink: geneLink});
}
}
};
Expand Down
9 changes: 7 additions & 2 deletions variantopedia/templates/variantopedia/variant_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@
}

EKeys.load().then(eKeys => {
const allowList = {{ quick_lists_allow_list | jsonify }};
const blockList = {{ quick_links_block_list | jsonify }};
let vcLinks = new VCLinks(eKeys);
let links = vcLinks.generateLinks(data.link_data);
let anchors = links.filter(link => !link.isMissing()).map(link => link.asAnchor("bootstrap"));
$('#quick-links').html($("<ul>", {class:"list-group", html:anchors}));
links = vcLinks.filterLinks(links, false, allowList, blockList);

let variantLinks = links.filter(link => !link.geneLink);
let variantAnchors = variantLinks.map(link => link.asAnchor("bootstrap"));
$('#quick-links').html($("<ul>", {class:"list-group", html:variantAnchors}));
});
}

Expand Down
2 changes: 2 additions & 0 deletions variantopedia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ def variant_details_annotation_version(request, variant_id, annotation_version_i
"variant_allele": variant_allele_data,
"variant_annotation": variant_annotation,
"vts": vts,
"quick_links_allow_list": settings.VARIANT_DETAILS_QUICK_LINKS_ALLOW_LIST,
"quick_links_block_list": settings.VARIANT_DETAILS_QUICK_LINKS_BLOCK_LIST,
}
if extra_context:
context.update(extra_context)
Expand Down

0 comments on commit f208b94

Please sign in to comment.