Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 8, 2024
1 parent fb08638 commit 4f808b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
9 changes: 5 additions & 4 deletions taxonium_component/src/webworkers/localBackendWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
import { processNewickAndMetadata } from "../utils/processNewick.js";
import { processNextstrain } from "../utils/processNextstrain.js";
import { ReadableWebToNodeStream } from "readable-web-to-node-stream";
import {parser } from "stream-json";
import {streamValues } from "stream-json/streamers/StreamValues";
import { parser } from "stream-json";
import { streamValues } from "stream-json/streamers/StreamValues";

console.log("worker starting");
postMessage({ data: "Worker starting" });
Expand Down Expand Up @@ -214,9 +214,10 @@ onmessage = async (event) => {
data.data,
sendStatusMessage,
ReadableWebToNodeStream,
parser,streamValues
parser,
streamValues
);

console.log("processedUploadedData created");
} else if (
data.type === "upload" &&
Expand Down
19 changes: 10 additions & 9 deletions taxonium_data_handling/importing.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class StreamSplitter extends stream.Transform {
const headerData = data.slice(0, newlineIndex);
const restData = data.slice(newlineIndex + 1);


// Write header data to headerParser
this.headerParser.write(headerData);
this.headerParser.end();
Expand All @@ -34,7 +33,7 @@ class StreamSplitter extends stream.Transform {
this.firstPart = false;
} else {
// No newline found, store data in buffer
this.headerParser.write(data);
this.headerParser.write(data);
}
} else {
// After header is processed, pass data to dataParser
Expand All @@ -56,7 +55,6 @@ class StreamSplitter extends stream.Transform {
}
}


const roundToDp = (number, dp) => {
return Math.round(number * Math.pow(10, dp)) / Math.pow(10, dp);
};
Expand Down Expand Up @@ -93,12 +91,12 @@ export const setUpStream = (
// Header parser
const headerParser = parser({ jsonStreaming: true });
const headerPipeline = headerParser.pipe(streamValues());
headerPipeline.on('data', (chunk) => {
headerPipeline.on("data", (chunk) => {
data.header = chunk.value;
data.nodes = [];
data.node_to_mut = {};
});
headerPipeline.on('error', (err) => {
headerPipeline.on("error", (err) => {
console.error("Header parser error:", err);
});

Expand Down Expand Up @@ -158,19 +156,22 @@ export const setUpStream = (
const splitter = new StreamSplitter(headerParser, dataParser);

// Pipe the input stream through the splitter
the_stream.pipe(splitter).on("error", (err) => console.error("Splitter error:", err));
the_stream
.pipe(splitter)
.on("error", (err) => console.error("Splitter error:", err));

// Handle the completion of the dataParser
dataParser.on("finish", () => {
console.log("Finished processing the stream");
});
};


export const processJsonl = async (
jsonl,
sendStatusMessage,
ReadableWebToNodeStream, parser, streamValues
ReadableWebToNodeStream,
parser,
streamValues
) => {
console.log(
"Worker processJsonl" //, jsonl
Expand All @@ -186,7 +187,7 @@ export const processJsonl = async (
the_stream = new stream.PassThrough();
}
let new_data = {};
setUpStream(the_stream, new_data, sendStatusMessage,parser, streamValues);
setUpStream(the_stream, new_data, sendStatusMessage, parser, streamValues);

if (status === "loaded") {
const dataAsArrayBuffer = data;
Expand Down

0 comments on commit 4f808b3

Please sign in to comment.