jbrowse-plugin-protein3d 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  import { SimpleFeature } from '@jbrowse/core/util';
2
- import { getCodonRange } from 'g2p_mapper';
3
2
  import { action, computed, makeObservable, observable } from 'mobx';
4
- import { genomeToTranscriptSeqMapping } from '../mappings';
3
+ import { codonGenomeSpan, genomeToTranscriptSeqMapping } from '../mappings';
5
4
  class Protein1DViewRegistry {
6
5
  views = observable.map();
7
6
  constructor() {
@@ -53,13 +52,9 @@ class Protein1DViewRegistry {
53
52
  if (!mapping) {
54
53
  return undefined;
55
54
  }
56
- const { p2g, strand, refName } = mapping;
57
- const result = getCodonRange(p2g, proteinPos, strand);
58
- if (!result) {
59
- return undefined;
60
- }
61
- const [start, end] = result;
62
- return { refName, start, end };
55
+ const { p2gCodon, refName } = mapping;
56
+ const span = codonGenomeSpan(p2gCodon, proteinPos);
57
+ return span ? { refName, start: span[0], end: span[1] } : undefined;
63
58
  }
64
59
  }
65
60
  export const protein1DViewRegistry = new Protein1DViewRegistry();
@@ -29,16 +29,30 @@ const ProteinAlignment = observer(function ProteinAlignment({ model, }) {
29
29
  const containerRef = useRef(null);
30
30
  const scrolledToSelectionRef = useRef(false);
31
31
  const { data: featureData, isLoading: featureLoading, error: featureError, } = useProteinFeatureTrackData(model, uniprotId);
32
+ // Follow the hovered column, but only when it has scrolled off-screen, and
33
+ // then only far enough to bring it back to the nearest edge. Re-centering on
34
+ // every hover (the old behavior) made the panel drift continuously as the
35
+ // cursor moved; scroll-into-view keeps it still whenever the column is
36
+ // already visible.
32
37
  useEffect(() => autorun(() => {
33
38
  const container = containerRef.current;
34
39
  if (model.autoScrollAlignment &&
35
40
  !model.isMouseInAlignment &&
36
41
  model.alignmentHoverPos !== undefined &&
37
42
  container) {
38
- container.scrollTo({
39
- left: model.alignmentHoverPos * CHAR_WIDTH - container.clientWidth / 2,
40
- behavior: 'smooth',
41
- });
43
+ const x = model.alignmentHoverPos * CHAR_WIDTH;
44
+ const margin = CHAR_WIDTH * 4;
45
+ const viewStart = container.scrollLeft;
46
+ const viewEnd = viewStart + container.clientWidth;
47
+ if (x < viewStart + margin) {
48
+ container.scrollTo({ left: x - margin, behavior: 'smooth' });
49
+ }
50
+ else if (x > viewEnd - margin) {
51
+ container.scrollTo({
52
+ left: x - container.clientWidth + margin,
53
+ behavior: 'smooth',
54
+ });
55
+ }
42
56
  }
43
57
  }), [model]);
44
58
  // Scroll the persistent selection into view once it first resolves, so a
@@ -47,7 +47,7 @@ function getDisplayToggles(model) {
47
47
  },
48
48
  },
49
49
  {
50
- label: 'Auto-scroll features',
50
+ label: 'Auto-scroll alignment',
51
51
  checked: model.autoScrollAlignment,
52
52
  onToggle: () => {
53
53
  model.setAutoScrollAlignment(!model.autoScrollAlignment);
@@ -426,7 +426,7 @@ function stateModelFactory() {
426
426
  },
427
427
  },
428
428
  {
429
- label: 'Auto-scroll protein feature view on hover',
429
+ label: 'Auto-scroll alignment to hovered position',
430
430
  type: 'checkbox',
431
431
  checked: self.autoScrollAlignment,
432
432
  onClick: () => {
@@ -2,7 +2,7 @@ import type { PairwiseAlignment } from '../mappings';
2
2
  import type { IAnyStateTreeNode } from '@jbrowse/mobx-state-tree';
3
3
  import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view';
4
4
  interface GenomeToTranscriptSeqMapping {
5
- p2g: Record<number, number>;
5
+ p2gCodon: Record<number, number[]>;
6
6
  strand: number;
7
7
  refName: string;
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import { getSession } from '@jbrowse/core/util';
2
- import { getCodonRange } from 'g2p_mapper';
2
+ import { codonGenomeSpan } from '../mappings';
3
3
  /**
4
4
  * Maps a protein structure position to genome coordinates
5
5
  * @returns [start, end] tuple of genome coordinates, or undefined if mapping fails
@@ -9,12 +9,11 @@ export function proteinToGenomeMapping({ model, structureSeqPos, }) {
9
9
  if (!genomeToTranscriptSeqMapping || !pairwiseAlignment) {
10
10
  return undefined;
11
11
  }
12
- const { p2g, strand } = genomeToTranscriptSeqMapping;
12
+ const { p2gCodon } = genomeToTranscriptSeqMapping;
13
13
  const transcriptPos = structureSeqToTranscriptSeqPosition?.[structureSeqPos];
14
- if (transcriptPos === undefined) {
15
- return undefined;
16
- }
17
- return getCodonRange(p2g, transcriptPos, strand);
14
+ return transcriptPos === undefined
15
+ ? undefined
16
+ : codonGenomeSpan(p2gCodon, transcriptPos);
18
17
  }
19
18
  /**
20
19
  * Maps a protein structure range to genome coordinates
@@ -63,7 +62,11 @@ export async function navigateToProteinPosition({ model, structureSeqPos, struct
63
62
  }
64
63
  const [start, end] = result;
65
64
  if (zoomToBaseLevel) {
66
- await connectedView.navToLocString(`${refName}:${start}-${end}${strand === -1 ? '[rev]' : ''}`, undefined, 0.2);
65
+ // start/end are 0-based half-open (from getCodonRanges). navToLocString
66
+ // parses a 1-based locString (parseLocString does start -= 1), so the start
67
+ // must be shifted to 1-based; the half-open end already equals the 1-based
68
+ // inclusive end. Passing the raw 0-based start landed the view 1bp 5'.
69
+ await connectedView.navToLocString(`${refName}:${start + 1}-${end}${strand === -1 ? '[rev]' : ''}`, undefined, 0.2);
67
70
  }
68
71
  else {
69
72
  const { assemblyManager } = session;