Skip to content

Commit dc0b2d7

Browse files
committed
fix: do not yield molfile that has less than 40 characters long
1 parent 9bdaab3 commit dc0b2d7

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/MolfileStream.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ export class MolfileStream extends TransformStream {
1717
}
1818
const eolLength = this.#buffer[endOfDelimiter - 1] === '\r' ? 2 : 1;
1919
// need to remove the last eol because we will split on eol+'>' in getMolecule
20-
controller.enqueue(this.#buffer.slice(begin, index - eolLength));
20+
if (index - eolLength - begin > 40) {
21+
controller.enqueue(this.#buffer.slice(begin, index - eolLength));
22+
}
2123
index = endOfDelimiter + eolLength;
2224
begin = index;
2325
}
2426
this.#buffer = this.#buffer.slice(begin);
2527
},
2628
flush: (controller) => {
27-
if (this.#buffer) {
29+
if (this.#buffer && this.#buffer.length > 40) {
2830
controller.enqueue(this.#buffer);
2931
}
3032
},

src/__tests__/test2.sdf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,8 @@ M END
496496
0:Chloroform-D1 (CDCl3)
497497

498498
$$$$
499+
500+
asdfasdf
501+
iABAAA
502+
M END
503+
$$$$

src/iterator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export async function* iterator(readStream, options = {}) {
1616

1717
const moleculeStream = readStream.pipeThrough(new MolfileStream({ eol }));
1818
for await (const entry of moleculeStream) {
19-
if (entry.length < 20) continue;
2019
const molecule = getMolecule(entry, {
2120
eol,
2221
dynamicTyping,

src/parse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getMolecule } from './util/getMolecule';
1313
* @param {object} [options.modifiers] - Object containing callbacks to apply on some specific fields
1414
* @param {boolean} [options.mixedEOL=false] - Set to true if you know there is a mixture between \r\n and \n
1515
* @param {string} [options.eol] - Specify the end of line character. Default will be the one found in the file
16+
* @returns {object} - Object containing the molecules, the labels and the statistics
1617
*/
1718
export function parse(sdf, options = {}) {
1819
options = { ...options };
@@ -53,7 +54,7 @@ export function parse(sdf, options = {}) {
5354

5455
for (let i = 0; i < entriesBoundaries.length; i++) {
5556
let sdfPart = sdf.slice(...entriesBoundaries[i]);
56-
57+
if (sdfPart.length < 40) continue;
5758
let currentLabels = [];
5859
const molecule = getMolecule(sdfPart, labels, currentLabels, options);
5960
if (!molecule) continue;

0 commit comments

Comments
 (0)