@jbrowse/plugin-linear-genome-view 2.8.0 → 2.9.0

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.
Files changed (31) hide show
  1. package/dist/BasicTrack/configSchema.d.ts +5 -0
  2. package/dist/FeatureTrack/configSchema.d.ts +5 -0
  3. package/dist/LaunchLinearGenomeView/index.js +16 -14
  4. package/dist/LinearGenomeView/components/CenterLine.js +1 -1
  5. package/dist/LinearGenomeView/components/ImportForm.js +26 -74
  6. package/dist/LinearGenomeView/components/ImportFormRefNameAutocomplete.d.ts +12 -0
  7. package/dist/LinearGenomeView/components/ImportFormRefNameAutocomplete.js +29 -0
  8. package/dist/LinearGenomeView/components/OverviewScalebar.js +1 -1
  9. package/dist/LinearGenomeView/components/SearchBox.js +19 -56
  10. package/dist/LinearGenomeView/model.d.ts +12 -1
  11. package/dist/LinearGenomeView/model.js +16 -0
  12. package/dist/index.d.ts +702 -6
  13. package/dist/index.js +2 -2
  14. package/dist/searchUtils.d.ts +26 -0
  15. package/dist/searchUtils.js +90 -0
  16. package/esm/BasicTrack/configSchema.d.ts +5 -0
  17. package/esm/FeatureTrack/configSchema.d.ts +5 -0
  18. package/esm/LaunchLinearGenomeView/index.js +16 -14
  19. package/esm/LinearGenomeView/components/CenterLine.js +1 -1
  20. package/esm/LinearGenomeView/components/ImportForm.js +26 -74
  21. package/esm/LinearGenomeView/components/ImportFormRefNameAutocomplete.d.ts +12 -0
  22. package/esm/LinearGenomeView/components/ImportFormRefNameAutocomplete.js +24 -0
  23. package/esm/LinearGenomeView/components/OverviewScalebar.js +1 -1
  24. package/esm/LinearGenomeView/components/SearchBox.js +20 -57
  25. package/esm/LinearGenomeView/model.d.ts +12 -1
  26. package/esm/LinearGenomeView/model.js +16 -0
  27. package/esm/index.d.ts +702 -6
  28. package/esm/index.js +2 -2
  29. package/esm/searchUtils.d.ts +26 -0
  30. package/esm/searchUtils.js +79 -0
  31. package/package.json +2 -2
@@ -58,6 +58,11 @@ declare const configSchema: (pluginManager: PluginManager) => import("@jbrowse/c
58
58
  defaultValue: number;
59
59
  description: string;
60
60
  };
61
+ maxDepth: {
62
+ type: string;
63
+ defaultValue: number;
64
+ description: string;
65
+ };
61
66
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
62
67
  formatAbout: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
63
68
  config: {
@@ -58,6 +58,11 @@ declare const configSchema: (pluginManager: PluginManager) => import("@jbrowse/c
58
58
  defaultValue: number;
59
59
  description: string;
60
60
  };
61
+ maxDepth: {
62
+ type: string;
63
+ defaultValue: number;
64
+ description: string;
65
+ };
61
66
  }, import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaOptions<undefined, undefined>>;
62
67
  formatAbout: import("@jbrowse/core/configuration/configurationSchema").ConfigurationSchemaType<{
63
68
  config: {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const util_1 = require("@jbrowse/core/util");
4
+ const searchUtils_1 = require("..//searchUtils");
4
5
  exports.default = (pluginManager) => {
5
6
  pluginManager.addToExtensionPoint('LaunchView-LinearGenomeView',
6
7
  // @ts-expect-error
@@ -16,21 +17,9 @@ exports.default = (pluginManager) => {
16
17
  if (!asm) {
17
18
  throw new Error(`Assembly "${assembly}" not found when launching linear genome view`);
18
19
  }
19
- await view.navToLocString(loc, assembly);
20
+ await (0, searchUtils_1.handleSelectedRegion)({ input: loc, model: view, assembly: asm });
20
21
  const idsNotFound = [];
21
- tracks.forEach(track => {
22
- try {
23
- view.showTrack(track);
24
- }
25
- catch (e) {
26
- if (`${e}`.match('Could not resolve identifier')) {
27
- idsNotFound.push(track);
28
- }
29
- else {
30
- throw e;
31
- }
32
- }
33
- });
22
+ tracks.forEach(track => tryTrack(view, track, idsNotFound));
34
23
  if (idsNotFound.length) {
35
24
  throw new Error(`Could not resolve identifiers: ${idsNotFound.join(',')}`);
36
25
  }
@@ -41,3 +30,16 @@ exports.default = (pluginManager) => {
41
30
  }
42
31
  });
43
32
  };
33
+ function tryTrack(model, trackId, idsNotFound) {
34
+ try {
35
+ model.showTrack(trackId);
36
+ }
37
+ catch (e) {
38
+ if (`${e}`.match('Could not resolve identifier')) {
39
+ idsNotFound.push(trackId);
40
+ }
41
+ else {
42
+ throw e;
43
+ }
44
+ }
45
+ }
@@ -30,7 +30,7 @@ const useStyles = (0, mui_1.makeStyles)()(theme => ({
30
30
  centerLineContainer: {
31
31
  background: 'transparent',
32
32
  height: '100%',
33
- zIndex: 5,
33
+ zIndex: 5, // above the track but under menu
34
34
  position: 'absolute',
35
35
  border: `1px ${theme.palette.action.active} dashed`,
36
36
  borderTop: 'none',
@@ -34,9 +34,8 @@ const material_1 = require("@mui/material");
34
34
  const ui_1 = require("@jbrowse/core/ui");
35
35
  // icons
36
36
  const Close_1 = __importDefault(require("@mui/icons-material/Close"));
37
- // locals
38
- const RefNameAutocomplete_1 = __importDefault(require("./RefNameAutocomplete"));
39
- const util_2 = require("./util");
37
+ const searchUtils_1 = require("../../searchUtils");
38
+ const ImportFormRefNameAutocomplete_1 = __importDefault(require("./ImportFormRefNameAutocomplete"));
40
39
  const useStyles = (0, mui_1.makeStyles)()(theme => ({
41
40
  importFormContainer: {
42
41
  padding: theme.spacing(2),
@@ -52,11 +51,10 @@ const LinearGenomeViewImportForm = (0, mobx_react_1.observer)(function ({ model,
52
51
  var _a;
53
52
  const { classes } = useStyles();
54
53
  const session = (0, util_1.getSession)(model);
55
- const { assemblyNames, assemblyManager, textSearchManager } = session;
56
- const { rankSearchResults, error } = model;
54
+ const { assemblyNames, assemblyManager } = session;
55
+ const { error } = model;
57
56
  const [selectedAsm, setSelectedAsm] = (0, react_1.useState)(assemblyNames[0]);
58
57
  const [option, setOption] = (0, react_1.useState)();
59
- const searchScope = model.searchScope(selectedAsm);
60
58
  const assembly = assemblyManager.get(selectedAsm);
61
59
  const assemblyError = assemblyNames.length
62
60
  ? assembly === null || assembly === void 0 ? void 0 : assembly.error
@@ -74,74 +72,37 @@ const LinearGenomeViewImportForm = (0, mobx_react_1.observer)(function ({ model,
74
72
  (0, react_1.useEffect)(() => {
75
73
  setValue(r0);
76
74
  }, [r0, selectedAsm]);
77
- async function navToOption(option) {
78
- const location = option.getLocation();
79
- const trackId = option.getTrackId();
80
- if (location) {
81
- await model.navToLocString(location, selectedAsm);
82
- if (trackId) {
83
- model.showTrack(trackId);
84
- }
85
- }
86
- }
87
- // gets a string as input, or use stored option results from previous query,
88
- // then re-query and
89
- // 1) if it has multiple results: pop a dialog
90
- // 2) if it's a single result navigate to it
91
- // 3) else assume it's a locstring and navigate to it
92
- async function handleSelectedRegion(input) {
93
- var _a;
94
- try {
95
- if ((option === null || option === void 0 ? void 0 : option.getDisplayString()) === input && option.hasLocation()) {
96
- await navToOption(option);
97
- }
98
- else if ((_a = option === null || option === void 0 ? void 0 : option.results) === null || _a === void 0 ? void 0 : _a.length) {
99
- model.setSearchResults(option.results, option.getLabel(), selectedAsm);
100
- }
101
- else {
102
- const [ref, rest] = (0, util_2.splitLast)(input, ':');
103
- const allRefs = (assembly === null || assembly === void 0 ? void 0 : assembly.allRefNamesWithLowerCase) || [];
104
- if (allRefs.includes(input) ||
105
- (allRefs.includes(ref) && !Number.isNaN(Number.parseInt(rest, 10)))) {
106
- await model.navToLocString(input, selectedAsm);
107
- }
108
- else {
109
- const results = await (0, util_2.fetchResults)({
110
- queryString: input,
111
- searchType: 'exact',
112
- searchScope,
113
- rankSearchResults,
114
- textSearchManager,
115
- assembly,
116
- });
117
- if (results.length > 1) {
118
- model.setSearchResults(results, input.toLowerCase(), selectedAsm);
119
- }
120
- else if (results.length === 1) {
121
- await navToOption(results[0]);
122
- }
123
- else {
124
- await model.navToLocString(input, selectedAsm);
125
- }
126
- }
127
- }
128
- }
129
- catch (e) {
130
- console.error(e);
131
- session.notify(`${e}`, 'warning');
132
- }
133
- }
134
75
  // implementation notes:
135
76
  // having this wrapped in a form allows intuitive use of enter key to submit
136
77
  return (react_1.default.createElement("div", { className: classes.container },
137
78
  displayError ? react_1.default.createElement(ui_1.ErrorMessage, { error: displayError }) : null,
138
79
  react_1.default.createElement(material_1.Container, { className: classes.importFormContainer },
139
80
  react_1.default.createElement("form", { onSubmit: async (event) => {
81
+ var _a;
140
82
  event.preventDefault();
141
83
  model.setError(undefined);
142
84
  if (value) {
143
85
  // has it's own error handling
144
- await handleSelectedRegion(value);
86
+ try {
87
+ if ((option === null || option === void 0 ? void 0 : option.getDisplayString()) === value &&
88
+ option.hasLocation()) {
89
+ await (0, searchUtils_1.navToOption)({
90
+ option,
91
+ model,
92
+ assemblyName: selectedAsm,
93
+ });
94
+ }
95
+ else if ((_a = option === null || option === void 0 ? void 0 : option.results) === null || _a === void 0 ? void 0 : _a.length) {
96
+ model.setSearchResults(option.results, option.getLabel(), selectedAsm);
97
+ }
98
+ else if (assembly) {
99
+ await (0, searchUtils_1.handleSelectedRegion)({ input: value, assembly, model });
100
+ }
101
+ }
102
+ catch (e) {
103
+ console.error(e);
104
+ session.notify(`${e}`, 'warning');
105
+ }
145
106
  }
146
107
  } },
147
108
  react_1.default.createElement(material_1.Grid, { container: true, spacing: 1, justifyContent: "center", alignItems: "center" },
@@ -149,16 +110,7 @@ const LinearGenomeViewImportForm = (0, mobx_react_1.observer)(function ({ model,
149
110
  react_1.default.createElement(material_1.FormControl, null,
150
111
  react_1.default.createElement(ui_1.AssemblySelector, { onChange: val => setSelectedAsm(val), localStorageKey: "lgv", session: session, selected: selectedAsm }))),
151
112
  react_1.default.createElement(material_1.Grid, { item: true }, selectedAsm ? (assemblyError ? (react_1.default.createElement(Close_1.default, { style: { color: 'red' } })) : assemblyLoaded ? (react_1.default.createElement(material_1.FormControl, null,
152
- react_1.default.createElement(RefNameAutocomplete_1.default, { fetchResults: queryString => (0, util_2.fetchResults)({
153
- queryString,
154
- assembly,
155
- textSearchManager,
156
- rankSearchResults,
157
- searchScope,
158
- }), model: model, assemblyName: selectedAsm, value: value, minWidth: 270, onChange: str => setValue(str), onSelect: val => setOption(val), TextFieldProps: {
159
- variant: 'outlined',
160
- helperText: 'Enter sequence name, feature name, or location',
161
- } }))) : (react_1.default.createElement(material_1.CircularProgress, { size: 20, disableShrink: true }))) : null),
113
+ react_1.default.createElement(ImportFormRefNameAutocomplete_1.default, { value: value, setValue: setValue, selectedAsm: selectedAsm, setOption: setOption, model: model }))) : (react_1.default.createElement(material_1.CircularProgress, { size: 20, disableShrink: true }))) : null),
162
114
  react_1.default.createElement(material_1.Grid, { item: true },
163
115
  react_1.default.createElement(material_1.FormControl, null,
164
116
  react_1.default.createElement(material_1.Button, { type: "submit", disabled: !value, className: classes.button, variant: "contained", color: "primary" }, "Open")),
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import BaseResult from '@jbrowse/core/TextSearch/BaseResults';
3
+ import { LinearGenomeViewModel } from '..';
4
+ type LGV = LinearGenomeViewModel;
5
+ declare const ImportFormRefNameAutocomplete: ({ model, selectedAsm, value, setValue, setOption, }: {
6
+ value: string;
7
+ setValue: (arg: string) => void;
8
+ model: LGV;
9
+ selectedAsm: string;
10
+ setOption: (arg: BaseResult) => void;
11
+ }) => React.JSX.Element;
12
+ export default ImportFormRefNameAutocomplete;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const mobx_react_1 = require("mobx-react");
8
+ const util_1 = require("@jbrowse/core/util");
9
+ // locals
10
+ const RefNameAutocomplete_1 = __importDefault(require("./RefNameAutocomplete"));
11
+ const util_2 = require("./util");
12
+ const ImportFormRefNameAutocomplete = (0, mobx_react_1.observer)(function ({ model, selectedAsm, value, setValue, setOption, }) {
13
+ const session = (0, util_1.getSession)(model);
14
+ const { assemblyManager, textSearchManager } = session;
15
+ const { rankSearchResults } = model;
16
+ const searchScope = model.searchScope(selectedAsm);
17
+ const assembly = assemblyManager.get(selectedAsm);
18
+ return (react_1.default.createElement(RefNameAutocomplete_1.default, { fetchResults: queryString => (0, util_2.fetchResults)({
19
+ queryString,
20
+ assembly,
21
+ textSearchManager,
22
+ rankSearchResults,
23
+ searchScope,
24
+ }), model: model, assemblyName: selectedAsm, value: value, minWidth: 270, onChange: str => setValue(str), onSelect: val => setOption(val), TextFieldProps: {
25
+ variant: 'outlined',
26
+ helperText: 'Enter sequence name, feature name, or location',
27
+ } }));
28
+ });
29
+ exports.default = ImportFormRefNameAutocomplete;
@@ -225,7 +225,7 @@ const OverviewScalebar = (0, mobx_react_1.observer)(function ({ model, children,
225
225
  overview.showAllRegions();
226
226
  return overview;
227
227
  }, [
228
- JSON.stringify(displayedRegions),
228
+ JSON.stringify(displayedRegions), // eslint-disable-line react-hooks/exhaustive-deps
229
229
  model.minimumBlockWidth,
230
230
  modWidth,
231
231
  displayedRegions,
@@ -12,16 +12,12 @@ const util_1 = require("@jbrowse/core/util");
12
12
  const RefNameAutocomplete_1 = __importDefault(require("./RefNameAutocomplete"));
13
13
  const util_2 = require("./util");
14
14
  const __1 = require("..");
15
+ const searchUtils_1 = require("../../searchUtils");
15
16
  const useStyles = (0, mui_1.makeStyles)()(() => ({
16
17
  headerRefName: {
17
18
  minWidth: 100,
18
19
  },
19
20
  }));
20
- function checkRef(str, allRefs) {
21
- const [ref, rest] = (0, util_2.splitLast)(str, ':');
22
- return (allRefs.includes(str) ||
23
- (allRefs.includes(ref) && !Number.isNaN(Number.parseInt(rest, 10))));
24
- }
25
21
  const SearchBox = (0, mobx_react_1.observer)(function ({ model, showHelp, }) {
26
22
  const { classes } = useStyles();
27
23
  const theme = (0, material_1.useTheme)();
@@ -31,61 +27,28 @@ const SearchBox = (0, mobx_react_1.observer)(function ({ model, showHelp, }) {
31
27
  const assemblyName = assemblyNames[0];
32
28
  const assembly = assemblyManager.get(assemblyName);
33
29
  const searchScope = model.searchScope(assemblyName);
34
- async function navToOption(option) {
35
- const location = option.getLocation();
36
- const trackId = option.getTrackId();
37
- if (location) {
38
- await model.navToLocString(location, assemblyName);
39
- if (trackId) {
40
- model.showTrack(trackId);
41
- }
42
- }
43
- }
44
- // gets a string as input, or use stored option results from previous query,
45
- // then re-query and
46
- // 1) if it has multiple results: pop a dialog
47
- // 2) if it's a single result navigate to it
48
- // 3) else assume it's a locstring and navigate to it
49
- async function handleSelectedRegion(option) {
50
- var _a;
51
- try {
52
- const input = option.getLabel();
53
- const allRefs = (assembly === null || assembly === void 0 ? void 0 : assembly.allRefNamesWithLowerCase) || [];
54
- if (option.hasLocation()) {
55
- await navToOption(option);
56
- }
57
- else if ((_a = option.results) === null || _a === void 0 ? void 0 : _a.length) {
58
- model.setSearchResults(option.results, option.getLabel());
59
- }
60
- else if (input.split(' ').every(entry => checkRef(entry, allRefs))) {
61
- await model.navToLocString(input, assemblyName);
62
- }
63
- else {
64
- const results = await (0, util_2.fetchResults)({
65
- queryString: input,
66
- searchType: 'exact',
67
- searchScope,
68
- rankSearchResults,
69
- textSearchManager,
70
- assembly,
71
- });
72
- if (results.length > 1) {
73
- model.setSearchResults(results, input.toLowerCase());
30
+ return (react_1.default.createElement(RefNameAutocomplete_1.default, { showHelp: showHelp, onSelect: async (option) => {
31
+ var _a;
32
+ try {
33
+ if (option.hasLocation()) {
34
+ await (0, searchUtils_1.navToOption)({ option, model, assemblyName });
74
35
  }
75
- else if (results.length === 1) {
76
- await navToOption(results[0]);
36
+ else if ((_a = option.results) === null || _a === void 0 ? void 0 : _a.length) {
37
+ model.setSearchResults(option.results, option.getLabel());
77
38
  }
78
- else {
79
- await model.navToLocString(input, assemblyName);
39
+ else if (assembly) {
40
+ await (0, searchUtils_1.handleSelectedRegion)({
41
+ input: option.getLabel(),
42
+ assembly,
43
+ model,
44
+ });
80
45
  }
81
46
  }
82
- }
83
- catch (e) {
84
- console.error(e);
85
- session.notify(`${e}`, 'warning');
86
- }
87
- }
88
- return (react_1.default.createElement(RefNameAutocomplete_1.default, { showHelp: showHelp, onSelect: handleSelectedRegion, assemblyName: assemblyName, fetchResults: queryString => (0, util_2.fetchResults)({
47
+ catch (e) {
48
+ console.error(e);
49
+ (0, util_1.getSession)(model).notify(`${e}`, 'warning');
50
+ }
51
+ }, assemblyName: assemblyName, fetchResults: queryString => (0, util_2.fetchResults)({
89
52
  queryString,
90
53
  searchScope,
91
54
  rankSearchResults,
@@ -6,6 +6,7 @@ import BaseResult from '@jbrowse/core/TextSearch/BaseResults';
6
6
  import { BlockSet, BaseBlock } from '@jbrowse/core/util/blockTypes';
7
7
  import { Instance } from 'mobx-state-tree';
8
8
  import PluginManager from '@jbrowse/core/PluginManager';
9
+ import { Assembly } from '@jbrowse/core/assemblyManager/assembly';
9
10
  export interface BpOffset {
10
11
  refName?: string;
11
12
  index: number;
@@ -292,7 +293,7 @@ export declare function stateModelFactory(pluginManager: PluginManager): import(
292
293
  /**
293
294
  * #action
294
295
  */
295
- toggleTrack(trackId: string): void;
296
+ toggleTrack(trackId: string): boolean;
296
297
  /**
297
298
  * #action
298
299
  */
@@ -463,6 +464,16 @@ export declare function stateModelFactory(pluginManager: PluginManager): import(
463
464
  * navigating to the locstring
464
465
  */
465
466
  navToLocString(input: string, optAssemblyName?: string): Promise<void>;
467
+ /**
468
+ * #action
469
+ * Performs a text index search, and navigates to it immediately if a
470
+ * single result is returned. Will pop up a search dialog if multiple
471
+ * results are returned
472
+ */
473
+ navToSearchString({ input, assembly, }: {
474
+ input: string;
475
+ assembly: Assembly;
476
+ }): Promise<void>;
466
477
  /**
467
478
  * #action
468
479
  * Similar to `navToLocString`, but accepts parsed location objects
@@ -53,6 +53,7 @@ const MenuOpen_1 = __importDefault(require("@mui/icons-material/MenuOpen"));
53
53
  const MiniControls_1 = __importDefault(require("./components/MiniControls"));
54
54
  const Header_1 = __importDefault(require("./components/Header"));
55
55
  const util_2 = require("./util");
56
+ const searchUtils_1 = require("../searchUtils");
56
57
  // lazies
57
58
  const ReturnToImportFormDialog = (0, react_1.lazy)(() => Promise.resolve().then(() => __importStar(require('@jbrowse/core/ui/ReturnToImportFormDialog'))));
58
59
  const SequenceSearchDialog = (0, react_1.lazy)(() => Promise.resolve().then(() => __importStar(require('./components/SequenceSearchDialog'))));
@@ -624,7 +625,9 @@ function stateModelFactory(pluginManager) {
624
625
  // if none had that configuration, turn one on
625
626
  if (!hiddenCount) {
626
627
  self.showTrack(trackId);
628
+ return true;
627
629
  }
630
+ return false;
628
631
  },
629
632
  /**
630
633
  * #action
@@ -1106,6 +1109,19 @@ function stateModelFactory(pluginManager) {
1106
1109
  }
1107
1110
  return this.navToLocations((0, util_2.parseLocStrings)(input, assemblyName, isValidRefName), assemblyName);
1108
1111
  },
1112
+ /**
1113
+ * #action
1114
+ * Performs a text index search, and navigates to it immediately if a
1115
+ * single result is returned. Will pop up a search dialog if multiple
1116
+ * results are returned
1117
+ */
1118
+ async navToSearchString({ input, assembly, }) {
1119
+ await (0, searchUtils_1.handleSelectedRegion)({
1120
+ input,
1121
+ assembly,
1122
+ model: self,
1123
+ });
1124
+ },
1109
1125
  /**
1110
1126
  * #action
1111
1127
  * Similar to `navToLocString`, but accepts parsed location objects