@datagrok-libraries/bio 0.0.2
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.
- package/.eslintrc.json +29 -0
- package/README.md +3 -0
- package/detectors.js +9 -0
- package/package.json +42 -0
- package/package.png +0 -0
- package/src/sequence-encoder.ts +177 -0
- package/tsconfig.json +71 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"google"
|
|
8
|
+
],
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 12,
|
|
11
|
+
"sourceType": "module"
|
|
12
|
+
},
|
|
13
|
+
"rules": {
|
|
14
|
+
"indent": [
|
|
15
|
+
"error",
|
|
16
|
+
2
|
|
17
|
+
],
|
|
18
|
+
"max-len": [
|
|
19
|
+
"error",
|
|
20
|
+
120
|
|
21
|
+
],
|
|
22
|
+
"require-jsdoc": "off",
|
|
23
|
+
"spaced-comment": "off"
|
|
24
|
+
},
|
|
25
|
+
"parser": "@typescript-eslint/parser",
|
|
26
|
+
"plugins": [
|
|
27
|
+
"@typescript-eslint"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/README.md
ADDED
package/detectors.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class contains semantic type detectors.
|
|
3
|
+
* Detectors are functions tagged with `DG.FUNC_TYPES.SEM_TYPE_DETECTOR`.
|
|
4
|
+
* See also: https://datagrok.ai/help/develop/how-to/define-semantic-type-detectors
|
|
5
|
+
* The class name is comprised of <PackageName> and the `PackageDetectors` suffix.
|
|
6
|
+
* Follow this naming convention to ensure that your detectors are properly loaded.
|
|
7
|
+
*/
|
|
8
|
+
class BioPackageDetectors extends DG.Package {
|
|
9
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@datagrok-libraries/bio",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"beta": true,
|
|
7
|
+
"friendlyName": "Datagrok bio library",
|
|
8
|
+
"version": "0.0.2",
|
|
9
|
+
"description": "",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"datagrok-api": ">=0.95.8",
|
|
12
|
+
"@datagrok-libraries/utils": ">=0.0.13",
|
|
13
|
+
"cash-dom": "latest",
|
|
14
|
+
"dayjs": "latest"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^4.2.3",
|
|
18
|
+
"ts-loader": "^9.2.6",
|
|
19
|
+
"webpack": "latest",
|
|
20
|
+
"webpack-cli": "latest",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^4.29.1",
|
|
22
|
+
"@typescript-eslint/parser": "^4.29.1",
|
|
23
|
+
"eslint": "^7.32.0",
|
|
24
|
+
"eslint-config-google": "^0.14.0"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"link": "npm link",
|
|
28
|
+
"link-api": "npm link datagrok-api",
|
|
29
|
+
"link-utils": "npm link @datagrok-libraries/utils",
|
|
30
|
+
"link-all": "npm link datagrok-api @datagrok-libraries/utils",
|
|
31
|
+
"debug-bio": "grok publish --rebuild",
|
|
32
|
+
"release-bio": "grok publish --rebuild --release",
|
|
33
|
+
"build-bio": "webpack",
|
|
34
|
+
"build": "webpack",
|
|
35
|
+
"debug-bio-public": "grok publish public --rebuild",
|
|
36
|
+
"release-bio-public": "grok publish public --rebuild --release",
|
|
37
|
+
"debug-bio-local": "grok publish local --rebuild",
|
|
38
|
+
"release-bio-local": "grok publish local --rebuild --release",
|
|
39
|
+
"lint": "eslint src --ext .ts",
|
|
40
|
+
"lint-fix": "eslint src --ext .ts --fix"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {assert} from '@datagrok-libraries/utils/src/operations';
|
|
2
|
+
|
|
3
|
+
type SideChainScale = {[name: string]: number};
|
|
4
|
+
type SideChainScaleCollection = {[name: string]: SideChainScale};
|
|
5
|
+
|
|
6
|
+
class SideChainScales {
|
|
7
|
+
static scales: SideChainScaleCollection = {
|
|
8
|
+
// Wimley-White interfacial hydrophobicity scale
|
|
9
|
+
'WimleyWhite': {
|
|
10
|
+
'-': 0,
|
|
11
|
+
'A': 0.17,
|
|
12
|
+
'C': -0.24,
|
|
13
|
+
'D': -0.07, // Asp-: 1.23
|
|
14
|
+
'E': -0.01, // Glu-: 2.02
|
|
15
|
+
'F': -1.13, //
|
|
16
|
+
'G': 0.01,
|
|
17
|
+
'H': 0.17, // His+: 0.96
|
|
18
|
+
'I': -0.31,
|
|
19
|
+
'K': 0.99, // Lys+
|
|
20
|
+
'L': -0.56,
|
|
21
|
+
'M': -0.23,
|
|
22
|
+
'N': 0.42,
|
|
23
|
+
'P': 0.45,
|
|
24
|
+
'Q': 0.58,
|
|
25
|
+
'R': 0.81, // Arg+
|
|
26
|
+
'S': 0.13,
|
|
27
|
+
'T': 0.14,
|
|
28
|
+
'V': 0.07,
|
|
29
|
+
'W': -1.85,
|
|
30
|
+
'Y': -0.94,
|
|
31
|
+
},
|
|
32
|
+
'categorial': {
|
|
33
|
+
'-': 0,
|
|
34
|
+
'A': 1,
|
|
35
|
+
'C': 2,
|
|
36
|
+
'D': 3,
|
|
37
|
+
'E': 4,
|
|
38
|
+
'F': 5,
|
|
39
|
+
'G': 6,
|
|
40
|
+
'H': 7,
|
|
41
|
+
'I': 8,
|
|
42
|
+
'K': 9,
|
|
43
|
+
'L': 10,
|
|
44
|
+
'M': 11,
|
|
45
|
+
'N': 12,
|
|
46
|
+
'P': 13,
|
|
47
|
+
'Q': 14,
|
|
48
|
+
'R': 15,
|
|
49
|
+
'S': 16,
|
|
50
|
+
'T': 17,
|
|
51
|
+
'V': 18,
|
|
52
|
+
'W': 19,
|
|
53
|
+
'Y': 20,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
static getAvailableScales(): string[] {
|
|
58
|
+
return Object.entries(this.scales).map(([k, _]) => k);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static getScale(name: string): SideChainScale {
|
|
62
|
+
assert(!(this.scales[name] === undefined), `Scale '${name}' was not found.`);
|
|
63
|
+
return this.scales[name];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Class to categorial encode/decode aligned amino acid residues sequence.
|
|
69
|
+
*
|
|
70
|
+
* @export
|
|
71
|
+
* @class AlignedSequenceEncoder
|
|
72
|
+
*/
|
|
73
|
+
export class AlignedSequenceEncoder {
|
|
74
|
+
protected aa2num: SideChainScale;
|
|
75
|
+
protected num2aa: {[code: number]: string};
|
|
76
|
+
|
|
77
|
+
constructor(scale: string = 'categorial') {
|
|
78
|
+
this.aa2num = SideChainScales.getScale(scale);
|
|
79
|
+
this.num2aa = {};
|
|
80
|
+
Object.entries(this.aa2num).forEach(([k, v]) => (this.num2aa[v] = k));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Truncate NH2 and -COOH terminals of the given sequence.
|
|
85
|
+
*
|
|
86
|
+
* @static
|
|
87
|
+
* @param {string} seq The sequence provided.
|
|
88
|
+
* @return {string} Truncated sequence.
|
|
89
|
+
* @memberof AlignedSequenceEncoder
|
|
90
|
+
*/
|
|
91
|
+
static _truncateSequence(seq: string): string {
|
|
92
|
+
let start = 0;
|
|
93
|
+
let end = seq.length;
|
|
94
|
+
const termina = ['NH2', 'COOH'];
|
|
95
|
+
|
|
96
|
+
if (seq.startsWith(termina[0])) {
|
|
97
|
+
const l = termina[0].length; // Cut only 'NH2' without following '-'.
|
|
98
|
+
assert(seq[l] == '-', `Wrong sequence format: ${termina[0]} without following '-' in '${seq}'.`);
|
|
99
|
+
start = l;
|
|
100
|
+
}
|
|
101
|
+
if (seq.endsWith(termina[1])) {
|
|
102
|
+
const l = termina[1].length+1; // Cut both 'COOH' and precending '-'.
|
|
103
|
+
assert(seq[end-l] == '-', `Wrong sequence format: ${termina[1]} without '-' precending in '${seq}'.`);
|
|
104
|
+
end -= l;
|
|
105
|
+
}
|
|
106
|
+
return seq.substring(start, end);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Cuts auxiliary defises before a residue.
|
|
111
|
+
*
|
|
112
|
+
* @static
|
|
113
|
+
* @param {string} seq The sequence to process.
|
|
114
|
+
* @return {string} Processed sequence.
|
|
115
|
+
* @memberof AlignedSequenceEncoder
|
|
116
|
+
*/
|
|
117
|
+
static _dropDefises(seq: string): string {
|
|
118
|
+
return seq.replace(/(-)([^-]+)/g, '$2');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Performs truncation and cutting auxiliary defises.
|
|
123
|
+
*
|
|
124
|
+
* @static
|
|
125
|
+
* @param {string} sequence The sequence work under process.
|
|
126
|
+
* @return {string} Result of cleaning.
|
|
127
|
+
* @memberof AlignedSequenceEncoder
|
|
128
|
+
*/
|
|
129
|
+
static clean(sequence: string): string {
|
|
130
|
+
return AlignedSequenceEncoder._dropDefises(AlignedSequenceEncoder._truncateSequence(sequence));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Categorial encode of the sequence provided.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} sequence The sequence.
|
|
137
|
+
* @return {number[]} Encoded vector.
|
|
138
|
+
* @memberof AlignedSequenceEncoder
|
|
139
|
+
*/
|
|
140
|
+
public encode(sequence: string): number[] {
|
|
141
|
+
const nItems = sequence.length;
|
|
142
|
+
const values = new Array(nItems).fill(0);
|
|
143
|
+
|
|
144
|
+
for (let i = 0; i < nItems; ++i) {
|
|
145
|
+
const char = sequence[i];
|
|
146
|
+
|
|
147
|
+
assert(char in this.aa2num, `Unknown char '${char}' found in sequence '${sequence}'`);
|
|
148
|
+
|
|
149
|
+
values[i] = this.encodeLettter(char);
|
|
150
|
+
}
|
|
151
|
+
return values;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public encodeLettter(letter: string): number {
|
|
155
|
+
return this.aa2num[letter];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Decode the encoded vector into the sequence back.
|
|
160
|
+
*
|
|
161
|
+
* @param {number[]} value The vector encoded.
|
|
162
|
+
* @return {string} Decoded sequence.
|
|
163
|
+
* @memberof AlignedSequenceEncoder
|
|
164
|
+
*/
|
|
165
|
+
public decode(value: number[]): string {
|
|
166
|
+
let s: string = '';
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < value.length; ++i) {
|
|
169
|
+
const code = value[i];
|
|
170
|
+
|
|
171
|
+
assert(code in this.num2aa, `Unknown code '${code}' found in vector '${value}'`);
|
|
172
|
+
|
|
173
|
+
s += this.num2aa[code];
|
|
174
|
+
}
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
"module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
+
"lib": ["es2020", "dom"], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
|
|
13
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
43
|
+
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
|
|
44
|
+
|
|
45
|
+
/* Module Resolution Options */
|
|
46
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
47
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
51
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
54
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
55
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
56
|
+
|
|
57
|
+
/* Source Map Options */
|
|
58
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
59
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
61
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
62
|
+
|
|
63
|
+
/* Experimental Options */
|
|
64
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
+
|
|
67
|
+
/* Advanced Options */
|
|
68
|
+
"skipLibCheck": false, /* Skip type checking of declaration files. */
|
|
69
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
70
|
+
}
|
|
71
|
+
}
|