Skip to content

Commit

Permalink
Merge pull request #15 from bcgsc/master
Browse files Browse the repository at this point in the history
Master back to dev
  • Loading branch information
creisle authored Feb 24, 2022
2 parents 74f1ede + ae37388 commit 139af0d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 20 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@
"unix"
],
"max-classes-per-file": "off",
"max-len": "warn",
"max-len": [
"warn",
{
"code": 100,
"ignoreComments": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreTrailingComments": true
}
],
"multiline-ternary": [
"error",
"always"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
node-version: ${{ matrix.node }}
- run: npm ci
- run: npm audit --production
- run: npm run lint
- name: test build
run: npm run build
- run: npm test
- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bcgsc-pori/graphkb-parser",
"version": "1.1.3",
"version": "2.0.0",
"description": "A package for parsing and recreating HGVS-like variant notation used in GraphKB",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,6 +11,7 @@
"test": "NODE_ENV=test jest --config config/jest.config.js --detectOpenHandles --forceExit",
"build": "tsc",
"clean": "rm -rf dist",
"prepublishOnly": "npm ci && npm run build",
"lint": "eslint src test -c .eslintrc.json"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ const TYPES_TO_NOTATION: Readonly<{ [key: string]: string }> = addTypeMappings()

type Prefix = 'g' | 'y' | 'i' | 'c' | 'r' | 'e' | 'n' | 'p';
/**
* the mapping of positional variant notation prefixes to their corresponging position classes
* the mapping of positional variant notation prefixes to their corresponding position classes
* @namespace
*
* @property {string} g genomic postions
* @property {string} g genomic positions
* @property {string} i intronic positions
* @property {string} e exonic positions
* @property {string} p protein positions (amino acid coordinates)
Expand Down
24 changes: 18 additions & 6 deletions src/continuous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ const convert3to1 = (notation: string): string => {
* Extract and return the position range
* @param {string} string
*/
const extractPositions = (prefix: Prefix, string: string): { input: string; start?: AnyPosition; end?: AnyPosition } => {
const extractPositions = (
prefix: Prefix,
string: string,
): { input: string; start?: AnyPosition; end?: AnyPosition } => {
let input: string;

if (string.startsWith('(')) {
// expect the first breakpoint to be a range of two positions
if (string.indexOf(')') < 0) {
throw new ParsingError('Expected a range of positions. Missing the closing parenthesis');
throw new ParsingError(
'Expected a range of positions. Missing the closing parenthesis',
);
}
if (string.indexOf('_') < 0) {
throw new ParsingError('Positions within a range must be separated by an underscore. Missing underscore');
throw new ParsingError(
'Positions within a range must be separated by an underscore. Missing underscore',
);
}
input = string.slice(0, string.indexOf(')') + 1);
return {
Expand Down Expand Up @@ -242,7 +249,7 @@ const parseContinuous = (inputString) => {

if (alt === '*' && truncation !== 1) {
throw new ParsingError({
message: 'invalid framshift specifies a non-immeadiate truncation which conflicts with the terminating alt seqeuence',
message: 'invalid frameshift specifies a non-immediate truncation which conflicts with the terminating alt sequence',
violatedAttr: 'truncation',
});
}
Expand Down Expand Up @@ -279,7 +286,7 @@ const parseContinuous = (inputString) => {
});
}
}
// check for innapropriate types
// check for inappropriate types
if (prefix === 'y') {
if (refSeq) {
throw new ParsingError({
Expand Down Expand Up @@ -323,7 +330,12 @@ const parseContinuous = (inputString) => {
refSeq = break1Start.longRefAA || break1Start.refAA;
}
// covert to 1AA code? check if any of the positions were converted
const convert = [break1Start, break1End, break2Start, break2End].some((x) => x && x.longRefAA);
const convert = [
break1Start,
break1End,
break2Start,
break2End,
].some((x) => x && x.longRefAA);

if (convert) {
if (untemplatedSeq) {
Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jc from 'json-cycle';
* @property {string} message the error message
* @property {string} name the error name (generally the same as the error class)
* @property {string} stack the stack trace associated with this error
* @property {Object} content additional properties assigined to the error to aid in debugging
* @property {Object} content additional properties assigned to the error to aid in debugging
*/
class ErrorMixin extends Error {
message: string;
Expand Down Expand Up @@ -40,7 +40,7 @@ class ErrorMixin extends Error {
}

/**
* @return {Object} the JSON respresenation of this error
* @return {Object} the JSON representation of this error
*/
toJSON() {
return jc.decycle(Object.assign(this.content, {
Expand Down
28 changes: 21 additions & 7 deletions src/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const createCytoBandPosition = ({ arm, majorBand, minorBand }): CytobandPosition
return result;
};

const checkBasicPosition = (pos: any, allowNegative = false): number | null => {
const checkBasicPosition = (pos: unknown, allowNegative = false): number | null => {
if (pos === '?' || pos === null) {
return null;
}
Expand All @@ -110,7 +110,11 @@ const checkBasicPosition = (pos: any, allowNegative = false): number | null => {
return Number(pos);
};

const createBasicPosition = (pos: any, prefix: Prefix, allowNegative = false): BasicPosition => {
const createBasicPosition = (
pos: unknown,
prefix: Prefix,
allowNegative = false,
): BasicPosition => {
const result = {
[CLASS_FIELD]: PREFIX_CLASS[prefix],
pos: checkBasicPosition(pos, allowNegative),
Expand All @@ -120,7 +124,9 @@ const createBasicPosition = (pos: any, prefix: Prefix, allowNegative = false): B
};

const createCdsLikePosition = ({ offset, pos }, prefix: 'c' | 'n' | 'r'): CdsLikePosition => {
const result: any = { ...createBasicPosition(pos, prefix, true) };
const result: CdsLikePosition = {
...createBasicPosition(pos, prefix, true) as CdsLikePosition,
};

if (offset !== undefined) {
result.offset = Number(offset);
Expand All @@ -135,9 +141,13 @@ const createCdsLikePosition = ({ offset, pos }, prefix: 'c' | 'n' | 'r'): CdsLik
return result;
};

const createProteinPosition = ({ refAA, pos }: { refAA: string; pos: string | number | null }): ProteinPosition => {
const prefix = 'p';
const result: any = { ...createBasicPosition(pos, prefix), longRefAA: null, refAA };
const createProteinPosition = ({
refAA,
pos,
}: { refAA: string; pos: string | number | null }): ProteinPosition => {
const result: ProteinPosition = {
...createBasicPosition(pos, 'p') as ProteinPosition, longRefAA: null, refAA,
};

if (result.refAA) {
if (result.refAA === '?') {
Expand Down Expand Up @@ -214,7 +224,11 @@ const convertPositionToString = (position) => {
*
* @returns the string representation of a breakpoint or breakpoint range including the prefix
*/
const createBreakRepr = (start: AnyPosition, end: AnyPosition | null = null, multiFeature = false): string => {
const createBreakRepr = (
start: AnyPosition,
end: AnyPosition | null = null,
multiFeature = false,
): string => {
if (end) {
if (start.prefix !== end.prefix) {
throw new ParsingError('Mismatch prefix in range');
Expand Down

0 comments on commit 139af0d

Please sign in to comment.