Skip to content

Commit

Permalink
Merge branch 'release/0.9.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
abought committed May 28, 2022
2 parents eb10524 + d43d526 commit 84215bf
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 148 deletions.
275 changes: 152 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "localzoom",
"version": "0.9.5",
"version": "0.9.6",
"license": "MIT",
"engines": {
"node": ">=10.13.0"
Expand All @@ -18,24 +18,24 @@
},
"dependencies": {
"@sentry/browser": "^4.5.2",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.21.2",
"locuszoom": "git+https://github.com/statgen/locuszoom.git#674d25c",
"bootstrap": "^4.6.1",
"bootstrap-vue": "2.21.2",
"locuszoom": "0.14.0",
"lodash": "^4.17.11",
"tabulator-tables": "^4.9.3",
"vue": "^2.6.14",
"vue-bootstrap-typeahead": "^0.2.6"
},
"devDependencies": {
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.17.12",
"@vue/cli-plugin-babel": "^3.0.0",
"@vue/cli-plugin-eslint": "^3.0.0",
"@vue/cli-plugin-unit-mocha": "^3.0.0",
"@vue/cli-service": "^3.0.0",
"@vue/eslint-config-airbnb": "^4.0.0",
"@vue/test-utils": "^1.2.2",
"@vue/test-utils": "^1.3.0",
"autoprefixer": "^9.8.8",
"chai": "^4.3.4",
"chai": "^4.3.6",
"source-map-loader": "^0.2.4",
"vue-template-compiler": "^2.6.14"
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/GwasToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import RegionPicker from './RegionPicker.vue';
import TabixAdder from './TabixAdder.vue';
import { createStudySources, createStudyLayouts } from '../util/lz-helpers';
import { MAX_REGION_SIZE } from '../util/constants';
const MAX_REGION_SIZE = 1000000;
export default {
name: 'GwasToolbar',
Expand Down
3 changes: 2 additions & 1 deletion src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const REGEX_POSITION = /^(?:chr)?(\w+)\s*:\s*(\d+)$/;
const REGEX_REGION = /^(?:chr)?(\w+)\s*:\s*(\d+)-(\d+)$/;

const DEFAULT_REGION_SIZE = 500000;
const MAX_REGION_SIZE = 2000000;

// Enum that controls recognized data types, so we can rename/ adjust as needed.
const DATA_TYPES = Object.freeze({
Expand All @@ -15,7 +16,7 @@ const DATA_TYPES = Object.freeze({

export {
DATA_TYPES,
DEFAULT_REGION_SIZE,
DEFAULT_REGION_SIZE, MAX_REGION_SIZE,
REGEX_REGION, REGEX_POSITION,
PORTAL_API_BASE_URL, LD_SERVER_BASE_URL,
};
7 changes: 4 additions & 3 deletions src/util/entity-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ function positionToStartRange(position, { region_size = DEFAULT_REGION_SIZE, pad
* @param {number} [region_size=DEFAULT_REGION_SIZE] If specified, enforces a max region size.
* @returns {[string, number, number]} [chr, start, end]
*/
function parseRegion(spec, { region_size = DEFAULT_REGION_SIZE }) {
const range_match = spec.match(REGEX_REGION);
const single_match = spec.match(REGEX_POSITION);
function parseRegion(spec, { region_size = DEFAULT_REGION_SIZE } = {}) {
const region = spec.replace(/,/g, '');
const range_match = region.match(REGEX_REGION);
const single_match = region.match(REGEX_POSITION);
let chr;
let start;
let end;
Expand Down
3 changes: 2 additions & 1 deletion src/util/lz-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import tabixSource from 'locuszoom/esm/ext/lz-tabix-source';
import intervalTracks from 'locuszoom/esm/ext/lz-intervals-track';
import lzParsers from 'locuszoom/esm/ext/lz-parsers';

import { PORTAL_API_BASE_URL, LD_SERVER_BASE_URL, DATA_TYPES } from './constants';
import { PORTAL_API_BASE_URL, LD_SERVER_BASE_URL, DATA_TYPES, MAX_REGION_SIZE } from './constants';

LocusZoom.use(credibleSets);
LocusZoom.use(tabixSource);
Expand Down Expand Up @@ -366,6 +366,7 @@ function getBasicLayout(initial_state = {}, study_panels = [], mods = {}) {
];

const extra = Object.assign({
max_region_scale: MAX_REGION_SIZE,
state: initial_state,
panels,
}, mods);
Expand Down
27 changes: 15 additions & 12 deletions tests/unit/entity_helpers.js → tests/unit/entity_helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,45 @@ import { parseRegion } from '../../src/util/entity-helpers';
describe('parseRegion', function () {
it('parses a single position', function () {
let result = parseRegion('1:1000', {region_size: 100});
assert.deepEqual(result, {chr: '1', start: 900, end: 1100}, 'Single position is center of a defined region size');
assert.deepEqual(result, {chr: '1', start: 950, end: 1050}, 'Single position is center of a defined region size');

result = parseRegion('chr1:1000', {region_size: 100});
assert.deepEqual(result, {chr: '1', start: 900, end: 1100}, 'Allows matching with a leading chr prefix');
assert.deepEqual(result, {chr: '1', start: 950, end: 1050}, 'Allows matching with a leading chr prefix');

result = parseRegion('1:10', {region_size: 100});
assert.deepEqual(result, {chr: '1', start: 1, end: 110}, 'Single position is center of a defined region size, and respects minima');
assert.deepEqual(result, {chr: '1', start: 1, end: 60}, 'Single position is inside a defined region size, and respects minima');
});

it('fails on totally unrecognized formats', function () {
assert.throws(() => parseRegion('TCF7L2'), 'Invalid format because not a region', /Could not parse/);
assert.throws(() => parseRegion('1:23ab'), 'Invalid format because trailing chars', /Could not parse/);
assert.throws(() => parseRegion('TCF7L2'), /Could not parse/);
assert.throws(() => parseRegion('1:23ab'), /Could not parse/);
});

it('handles various region types', function () {
// Note: this region is actually too small for a real LZ plot, but that is not the job of this function to handle.
let result = parseRegion('1:1000-2000', {region_size: 100});
assert.deepEqual(result, {chr: '1', start: 1000, end: 1000}, 'Faithfully parses a region as given');
let result = parseRegion('1:1000-2000', {region_size: 1000});
assert.deepEqual(result, {chr: '1', start: 1000, end: 2000}, 'Faithfully parses a region as given');

result = parseRegion('chr1:1000-2000', {region_size: 100});
assert.deepEqual(result, {chr: '1', start: 1000, end: 1000}, 'Allows matching with a leading chr prefix');
result = parseRegion('chr1:1000-2000', {region_size: 1000});
assert.deepEqual(result, {chr: '1', start: 1000, end: 2000}, 'Allows matching with a leading chr prefix');

result = parseRegion('chr1:1,000-2,000', {region_size: 1000});
assert.deepEqual(result, {chr: '1', start: 1000, end: 2000}, 'Allows matching regions with commas');

assert.throws(
() => parseRegion('2:1-1000', {region_size: 250}),
/Maximum allowable/,
'Warns if the requested region is too wide',
/Maximum allowable/
);
assert.throws(
() => parseRegion('2:1000-1', {region_size: 250}),
/smaller than/,
'Warns if the requested region makes no sense',
/smaller than/
);
assert.throws(
() => parseRegion('chr1:1000-2000ab', {region_size: 250}),
/Could not parse/,
'Fails because trailing characters are present',
/Could not parse/
);
});
});

0 comments on commit 84215bf

Please sign in to comment.