Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
],
"license": "MIT",
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@types/command-exists": "^1.2.1",
"@types/node": "^20.5.9",
"@types/split2": "^4.2.0",
Expand Down Expand Up @@ -43,7 +41,9 @@
},
"dependencies": {
"command-exists": "^1.2.9",
"execa": "^9.5.2",
"external-sorting": "^1.3.1",
"nano-spawn": "^2.0.0",
"split2": "^4.1.0",
"tmp": "^0.2.1"
}
Expand Down
80 changes: 48 additions & 32 deletions src/makeIx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import split2 from 'split2'
import fs from 'fs'
import { spawn } from 'child_process'
import { TrixInputTransform } from './TrixInputTransform'
import { TrixOutputTransform } from './TrixOutputTransform'
import { execa } from 'execa'

// Characters that may be part of a word
const wordMiddleChars = [] as boolean[]
Expand Down Expand Up @@ -40,43 +40,59 @@
const isWin =
typeof process !== 'undefined' ? process.platform === 'win32' : false

function elt(buff: string[], current: string) {
return `${current} ${buff.map((elt, idx) => `${elt},${idx + 1}`).join(' ')}\n`
}

export async function makeIxStream(
fileStream: Readable,
outIxFilename: string,
) {
return new Promise((resolve, reject) => {
initCharTables()
initCharTables()

const out = fs.createWriteStream(outIxFilename)
// see https://stackoverflow.com/questions/68835344/ for explainer of
// writer

// see https://stackoverflow.com/questions/68835344/ for explainer of
// writer

// override locale to C, but keep other env vars
if (commandExistsSync('sort') && !isWin) {
const sort = spawn('sort', ['-k1,1'], {
env: { ...process.env, LC_ALL: 'C' },
})
pipeline(
// override locale to C, but keep other env vars
if (commandExistsSync('sort') && !isWin) {
let buff = [] as string[]
let current = ''
await execa('sort', ['-k1,1'], {

Check failure on line 60 in src/makeIx.ts

View workflow job for this annotation

GitHub Actions / Test and typecheck on node 20.x and ubuntu-latest

No overload matches this call.
env: { ...process.env, LC_ALL: 'C' },
stdin: [
fileStream,
split2(),
new TrixInputTransform(),
sort.stdin,
err => {
if (err) {
reject(err)
}
function* (line: string) {
const [id, ...words] = line.toString().split(/\s+/)
yield words.map(word => `${word.toLowerCase()} ${id}\n`).join('')
},
)

pipeline(sort.stdout, split2(), new TrixOutputTransform(), out, err => {
if (err) {
reject(err)
} else {
resolve(true)
}
})
} else {
],
stdout: [
{
transform: function* (line: string) {
// weird: need to strip nulls from string, xref
// https://github.com/GMOD/jbrowse-components/pull/2451
const [id, data] = line.replace(/\0/g, '').split(' ')
if (current !== id) {
if (buff.length) {
yield elt(buff, current)
buff = []
}
current = id
}
buff.push(data)
},
final: function* () {
if (buff.length) {
yield elt(buff, current)
}
},
},
{ file: outIxFilename },
],
})
} else {
return new Promise((resolve, reject) => {
const out = fs.createWriteStream(outIxFilename)
const dir = tmp.dirSync({
prefix: 'jbrowse-trix-sort',
})
Expand All @@ -99,8 +115,8 @@
})
.asc()
.then(resolve, reject)
}
})
})
}
}

export async function makeIx(inFile: string, outIndex: string) {
Expand Down
Loading
Loading