@datagrok/bio 1.3.1 → 1.4.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/detectors.js +38 -15
- package/dist/package-test.js +3811 -590
- package/dist/package.js +2172 -54
- package/dist/vendors-node_modules_datagrok-libraries_ml_src_workers_dimensionality-reducer_js.js +8975 -0
- package/files/sample_FASTA.csv +66 -0
- package/files/sample_FASTA_with_activities.csv +66 -0
- package/files/samples/HELMCoreLibrary.json +18218 -0
- package/files/samples/peptides_complex_msa.csv +10275 -0
- package/files/samples/peptides_simple_msa.csv +648 -0
- package/files/samples/sample_FASTA.csv +66 -0
- package/files/samples/sample_FASTA.fasta +196 -0
- package/files/samples/sample_HELM.csv +541 -0
- package/files/samples/sample_MSA.csv +541 -0
- package/package.json +9 -5
- package/setup.cmd +10 -0
- package/src/const.ts +5 -0
- package/src/package-test.ts +3 -1
- package/src/package.ts +116 -0
- package/src/tests/WebLogo-test.ts +6 -3
- package/src/tests/detectors-test.ts +93 -46
- package/src/tests/msa-tests.ts +34 -0
- package/src/tests/sequence-space-test.ts +24 -0
- package/src/tests/utils.ts +39 -0
- package/src/utils/constants.ts +62 -0
- package/src/utils/convert.ts +24 -0
- package/src/utils/multiple-sequence-alignment.ts +76 -0
- package/src/utils/sequence-space.ts +43 -0
- package/test-Bio-69a4761f6044-51a4ab35.html +0 -245
package/detectors.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
class BioPackageDetectors extends DG.Package {
|
|
13
13
|
|
|
14
|
-
static
|
|
14
|
+
static mmSemType = 'Macromolecule';
|
|
15
15
|
|
|
16
16
|
static Units = {
|
|
17
17
|
FastaSeqPt: 'fasta:SEQ:PT', FastaSeqNt: 'fasta:SEQ:NT', FastaMsaPt: 'fasta:MSA:PT', FastaMsaNt: 'fasta:MSA:NT',
|
|
@@ -40,25 +40,33 @@ class BioPackageDetectors extends DG.Package {
|
|
|
40
40
|
// TODO: Lazy calculations could be helpful for performance and convenient for expressing classification logic.
|
|
41
41
|
const statsAsChars = BioPackageDetectors.getStats(col, 5, BioPackageDetectors.splitterAsChars);
|
|
42
42
|
if (statsAsChars.sameLength) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (Object.keys(statsAsChars.freq).length > 0) { // require non empty alphabet
|
|
44
|
+
const alphabet = BioPackageDetectors.detectAlphabet(statsAsChars.freq, alphabetCandidates, '-');
|
|
45
|
+
const units = `fasta:SEQ.MSA:${alphabet}`;
|
|
46
|
+
col.setTag(DG.TAGS.UNITS, units);
|
|
47
|
+
return BioPackageDetectors.mmSemType;
|
|
48
|
+
}
|
|
47
49
|
} else {
|
|
48
|
-
const
|
|
49
|
-
const gapSymbol =
|
|
50
|
-
const splitter =
|
|
50
|
+
const separator = BioPackageDetectors.detectSeparator(statsAsChars.freq);
|
|
51
|
+
const gapSymbol = separator ? '' : '-';
|
|
52
|
+
const splitter = separator ? BioPackageDetectors.getSplitterWithSeparator(separator) : BioPackageDetectors.splitterAsFasta;
|
|
53
|
+
|
|
51
54
|
const stats = BioPackageDetectors.getStats(col, 5, splitter);
|
|
55
|
+
if (Object.keys(stats.freq).length === 0) return null;
|
|
52
56
|
|
|
53
|
-
const format =
|
|
57
|
+
const format = separator ? 'separator' : 'fasta';
|
|
54
58
|
const seqType = stats.sameLength ? 'SEQ.MSA' : 'SEQ';
|
|
55
59
|
|
|
56
60
|
// TODO: If separator detected, then extra efforts to detect alphabet are allowed.
|
|
57
61
|
const alphabet = BioPackageDetectors.detectAlphabet(stats.freq, alphabetCandidates, gapSymbol);
|
|
58
62
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const forbidden = BioPackageDetectors.checkForbiddenWoSeparator(stats.freq);
|
|
64
|
+
if (separator || !forbidden) {
|
|
65
|
+
const units = `${format}:${seqType}:${alphabet}`;
|
|
66
|
+
col.setTag(DG.TAGS.UNITS, units);
|
|
67
|
+
if (separator) col.setTag('separator', separator);
|
|
68
|
+
return BioPackageDetectors.mmSemType;
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
@@ -73,9 +81,18 @@ class BioPackageDetectors extends DG.Package {
|
|
|
73
81
|
|
|
74
82
|
// !!! But there is a caveat because exceptionally frequent char can be a gap symbol in MSA.
|
|
75
83
|
// !!! What is the difference between the gap symbol and separator symbol in stats terms?
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
84
|
+
// const noSeparatorRe = /[a-z\d]+$/i;
|
|
85
|
+
const noSeparatorRe = /[HBCNOFPSKVYI]/i; // Mendeleev's periodic table single char elements
|
|
86
|
+
const cleanFreq = Object.assign({}, ...Object.entries(freq)
|
|
87
|
+
.filter(([m, f]) => !noSeparatorRe.test(m) &&
|
|
88
|
+
!BioPackageDetectors.AminoacidsFastaAlphabet.has(m) &&
|
|
89
|
+
!BioPackageDetectors.NucleotidesFastaAlphabet.has(m))
|
|
90
|
+
.map(([m, f]) => ({[m]: f})));
|
|
91
|
+
if (Object.keys(cleanFreq).length == 0) return null;
|
|
92
|
+
|
|
93
|
+
const maxFreq = Math.max(...Object.values(cleanFreq));
|
|
94
|
+
|
|
95
|
+
const sep = Object.entries(freq).find(([k, v]) => v === maxFreq)[0];
|
|
79
96
|
const sepFreq = freq[sep];
|
|
80
97
|
const otherSumFreq = Object.entries(freq).filter((kv) => kv[0] !== sep)
|
|
81
98
|
.map((kv) => kv[1]).reduce((pSum, a) => pSum + a, 0);
|
|
@@ -83,6 +100,12 @@ class BioPackageDetectors extends DG.Package {
|
|
|
83
100
|
return sepFreq / otherSumFreq > freqThreshold ? sep : null;
|
|
84
101
|
}
|
|
85
102
|
|
|
103
|
+
/** Without a separator, special symbols or digits are not allowed as monomers. */
|
|
104
|
+
static checkForbiddenWoSeparator(freq) {
|
|
105
|
+
const forbiddenRe = /[\d!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/i;
|
|
106
|
+
return Object.keys(freq).filter((m) => forbiddenRe.test(m)).length > 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
86
109
|
/** Stats of sequences with specified splitter func, returns { freq, sameLength } */
|
|
87
110
|
static getStats(seqCol, minLength, splitter) {
|
|
88
111
|
const freq = {};
|