| import { runWorker } from "@/Core/WebWorkers/RunWorker"; |
| import { FileInfo } from "@/FileSystem/FileInfo"; |
| |
| |
| |
| |
| |
| |
| |
| |
| export async function alignFileInfos( |
| referenceFileInfo: FileInfo, |
| mobileFileInfos: FileInfo[] |
| ): Promise<FileInfo[]> { |
| const referencePdb = referenceFileInfo.contents; |
| const mobilePdbs = mobileFileInfos.map((fi) => fi.contents); |
| const worker = new Worker( |
| new URL("./AlignProteins.worker.ts", import.meta.url) |
| ); |
| const path = window.location.pathname; |
| const basePath = |
| window.location.origin + path.substring(0, path.lastIndexOf("/") + 1); |
| const result = await runWorker(worker, { |
| referencePdb, |
| mobilePdbs, |
| basePath: basePath, |
| }); |
| if (result.error) { |
| throw new Error(result.error); |
| } |
| const { alignedPdbs } = result; |
| const alignedFileInfos: FileInfo[] = []; |
| for (let i = 0; i < alignedPdbs.length; i++) { |
| const alignedContent = alignedPdbs[i]; |
| if (alignedContent.startsWith("ERROR:")) { |
| console.error( |
| `Alignment error for ${mobileFileInfos[i].name}: ${alignedContent}` |
| ); |
| |
| continue; |
| } |
| const originalFileInfo = mobileFileInfos[i]; |
| const newName = `aligned.pdb`; |
| const newFileInfo = new FileInfo({ |
| name: newName, |
| contents: alignedContent, |
| |
| treeNode: originalFileInfo.treeNode, |
| }); |
| alignedFileInfos.push(newFileInfo); |
| } |
| return alignedFileInfos; |
| } |
|
|