Skip to content

Improve transcript navigation, close popover on "Escape", etc. #358

New issue

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

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

Already on GitHub? # to your account

Merged
merged 16 commits into from
Aug 8, 2023
Merged
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
Binary file not shown.
Binary file not shown.
Binary file modified dist/data/cache/proteins/homo-sapiens-proteins.tsv.gz
Binary file not shown.
Binary file modified dist/data/cache/proteins/mus-musculus-proteins.tsv.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts/python/cache/gene_structure_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ def populate_by_org(self, organism):
structures = parse_structures(canonical_ids, gff_path, gff_url)

sorted_structures = sort_structures(structures, organism, canonical_ids)
refined_structures = compress_structures(sorted_structures)
# refined_structures = compress_structures(sorted_structures)

# sorted_slim_genes = sort_by_interest(slim_genes, organism)
self.write(refined_structures, organism, gff_url, bmtsv_url)
self.write(sorted_structures, organism, gff_url, bmtsv_url)

def populate(self):
"""Fill gene caches for all configured organisms
Expand Down
10 changes: 8 additions & 2 deletions scripts/python/cache/protein_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def merge_signalp(
if transcript_name not in features_by_transcript:
transcript_names_not_found.append(transcript_id)
continue
name = '_SP'
name = 'S'
parsed_feat, feature_names_by_id = parse_feature(
name, start, stop, name, feature_names_by_id
)
Expand Down Expand Up @@ -202,7 +202,13 @@ def merge_uniprot(organism, features_by_transcript, transcript_names_by_id, feat
continue

name = name.replace(';', ' ---')
name = "_UT_" + name
if name == 'Helical':
name = 'H'
elif name == 'Extracellular':
name = 'E'
elif name == 'Cytoplasmic':
name = 'C'
name = "_" + name
parsed_feat, feature_names_by_id = parse_feature(
name, start, stop, name, feature_names_by_id
)
Expand Down
15 changes: 14 additions & 1 deletion src/js/init/write-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ function getContainerSvgClass(ideo) {
return svgClass;
}

/** Hide tooltip upon pressing "esc" on keyboard */
function handleEscape(event) {
if (event.keyCode === 27) { // "Escape" key pressed
const tooltip = document.querySelector('#_ideogramTooltip');
if (!tooltip) return;
tooltip.style.opacity = 0;
}
}

/**
* Write tooltip div setup with default styling.
*/
Expand All @@ -62,7 +71,11 @@ function writeTooltipContainer(ideo) {
.style('background', 'white')
.style('border', '1px solid black')
.style('border-radius', '5px')
.style('z-index', '1000');
.style('z-index', '1000')
.style('margin-left', '-2px'); // Mitigate crowding, e.g. BRCA1 for RAD51

document.removeEventListener('keydown', handleEscape);
document.addEventListener('keydown', handleEscape);
}

function writeContainerDom(ideo) {
Expand Down
52 changes: 33 additions & 19 deletions src/js/kit/gene-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {tippyCss, tippyLightCss} from './tippy-styles';

import {d3} from '../lib';
import {getIcon} from '../annotations/legend';
import {getProteinSvg} from './protein';
import {getProtein, getHasTopology} from './protein';

const y = 15;

Expand Down Expand Up @@ -176,22 +176,22 @@ function addMenuListeners(ideo) {

// Go to next transcript on clicking down arrow icon, previous on up
if (Array.from(svgMaybe.classList).includes('_ideoMenuArrow')) {
const menuArrow = event.target;
const menuArrow = svgMaybe;
const direction = menuArrow.getAttribute('data-dir');
const offset = direction === 'down' ? 1 : -1;
updateGeneStructure(ideo, offset);
event.stopPropagation();
}
});

// Go to next transcript on pressing down arrow key, previous on up
document.addEventListener('keydown', (event) => {
const key = event.key;
if (['ArrowDown', 'ArrowUp'].includes(key)) {
const offset = key === 'ArrowDown' ? 1 : -1;
updateGeneStructure(ideo, offset);
}
});
// // Go to next transcript on pressing down arrow key, previous on up
// document.addEventListener('keydown', (event) => {
// const key = event.key;
// if (['ArrowDown', 'ArrowUp'].includes(key)) {
// const offset = key === 'ArrowDown' ? 1 : -1;
// updateGeneStructure(ideo, offset);
// }
// });
}

function toggleSpliceByKeyboard(event) {
Expand Down Expand Up @@ -995,25 +995,39 @@ function getSvg(geneStructure, ideo, spliceExons=false) {
`style="${sharedStyle} left: -10px;"`;
}

const structureName = geneStructure.name;
const gene = getGeneFromStructureName(structureName);
const menu = getMenu(gene, ideo, structureName).replaceAll('"', '\'');

const hasTopology = getHasTopology(gene, ideo);

const [proteinSvg, proteinLengthAa] =
getProtein(structureName, subparts, isPositiveStrand, hasTopology, ideo);

const transcriptLengthBp = getTranscriptLengthBp(subparts, spliceExons);
const prettyLength = transcriptLengthBp.toLocaleString();

const footerDetails = [
`${totalBySubpart['exon']} exons`,
`<span id='_ideoTranscriptLengthBp'>${prettyLength} bp</span> `
];

// Note protein length in amino acids (aa)
// TODO: This is a no-op; see note about phase in protein.js
if (proteinLengthAa) {
const prettyLengthAa = proteinLengthAa.toLocaleString();
footerDetails.push(
`<span id='_ideoProteinLengthAa'>${prettyLengthAa} aa</span> `
);
}

// Note if transcript is unusual type, e.g. nonsense mediated decay (NMD)
const biotypeText = geneStructure.biotype.replace(/_/g, ' ');
if (biotypeText !== 'protein coding') {
footerDetails.push(biotypeText);
}

const structureName = geneStructure.name;
const gene = getGeneFromStructureName(structureName);
const menu = getMenu(gene, ideo, structureName).replaceAll('"', '\'');
const footerData = menu + footerDetails.join(` ${pipe} `);

const [proteinSvg, hasTopology] =
getProteinSvg(structureName, subparts, isPositiveStrand, ideo);

let svgHeight = proteinSvg === '' ? '40' : '60';
if (hasTopology) svgHeight = '70';

Expand Down Expand Up @@ -1041,9 +1055,9 @@ function getMenuArrows() {
const upStyle = `style="${style}; margin-left: 2px;"`;
const cls = 'class="_ideoMenuArrow"';
const tippyPlace = 'data-tippy-placement="bottom-start"';
const downContent = 'Next transcript (down arrow)';
const downContent = 'Next transcript';
const downTippy = `data-tippy-content="${downContent}" ${tippyPlace}`;
const upContent = 'Previous transcript (up arrow)';
const upContent = 'Previous transcript';
const upTippy = `data-tippy-content="${upContent}" ${tippyPlace}`;
const downAttrs = `${downStyle} ${cls} data-dir="down" ${downTippy}`;
const upAttrs = `${upStyle} ${cls} data-dir="up" ${upTippy}`;
Expand Down
Loading