diff --git a/packages/core/util/io/declare.d.ts b/packages/core/util/io/declare.d.ts deleted file mode 100644 index 9b3708832a..0000000000 --- a/packages/core/util/io/declare.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'detect-node' diff --git a/products/jbrowse-img/src/bin.js b/products/jbrowse-img/src/bin.js index b76eddf8a4..ba359555e4 100644 --- a/products/jbrowse-img/src/bin.js +++ b/products/jbrowse-img/src/bin.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -require("./index.js"); +require('./index.js') diff --git a/products/jbrowse-img/src/index.js b/products/jbrowse-img/src/index.js index 327400f483..61574618e8 100644 --- a/products/jbrowse-img/src/index.js +++ b/products/jbrowse-img/src/index.js @@ -1,185 +1,187 @@ -import "abortcontroller-polyfill/dist/abortcontroller-polyfill-only"; -import fs from "fs"; -import yargs from "yargs"; -import { standardizeArgv, parseArgv } from "./parseArgv"; -import { renderRegion } from "./renderRegion"; -import tmp from "tmp"; +/* eslint-disable no-console */ +import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only' +import fs from 'fs' +import yargs from 'yargs' +import { standardizeArgv, parseArgv } from './parseArgv' +import { renderRegion } from './renderRegion' +import tmp from 'tmp' -import { spawnSync } from "child_process"; +import { spawnSync } from 'child_process' +// eslint-disable-next-line no-unused-expressions yargs - .command("jb2export", "Creates a jbrowse 2 image snapshot") - .option("config", { - description: "Path to config file", - type: "string", + .command('jb2export', 'Creates a jbrowse 2 image snapshot') + .option('config', { + description: 'Path to config file', + type: 'string', }) - .option("session", { - description: "Path to session file", - type: "string", + .option('session', { + description: 'Path to session file', + type: 'string', }) - .option("assembly", { + .option('assembly', { description: - "Path to an assembly configuration, or a name of an assembly in the configFile", - type: "string", + 'Path to an assembly configuration, or a name of an assembly in the configFile', + type: 'string', }) - .option("tracks", { - description: "Path to tracks portion of a session", - type: "string", + .option('tracks', { + description: 'Path to tracks portion of a session', + type: 'string', }) - .option("loc", { + .option('loc', { description: - "A locstring to navigate to, or --loc all to view the whole genome", - type: "string", + 'A locstring to navigate to, or --loc all to view the whole genome', + type: 'string', }) - .option("fasta", { - description: "Supply a fasta for the assembly", - type: "string", + .option('fasta', { + description: 'Supply a fasta for the assembly', + type: 'string', }) - .option("aliases", { + .option('aliases', { description: - "Supply aliases for the assembly, e.g. mapping of 1 to chr1. Tab separated file where column 1 matches the names from the FASTA", - type: "string", + 'Supply aliases for the assembly, e.g. mapping of 1 to chr1. Tab separated file where column 1 matches the names from the FASTA', + type: 'string', }) - .option("width", { + .option('width', { description: - "Set the width of the window that jbrowse renders to, default: 1500px", - type: "number", + 'Set the width of the window that jbrowse renders to, default: 1500px', + type: 'number', }) - .option("pngwidth", { + .option('pngwidth', { description: - "Set the width of the png canvas if using png output, default 2048px", - type: "number", + 'Set the width of the png canvas if using png output, default 2048px', + type: 'number', default: 2048, }) // track types - .option("configtracks", { - description: "A list of track labels from a config file", - type: "array", + .option('configtracks', { + description: 'A list of track labels from a config file', + type: 'array', }) - .option("bam", { + .option('bam', { description: - "A bam file, flag --bam can be used multiple times to specify multiple bam files", - type: "array", + 'A bam file, flag --bam can be used multiple times to specify multiple bam files', + type: 'array', }) - .option("bigwig", { + .option('bigwig', { description: - "A bigwig file, the --bigwig flag can be used multiple times to specify multiple bigwig files", - type: "array", + 'A bigwig file, the --bigwig flag can be used multiple times to specify multiple bigwig files', + type: 'array', }) - .option("cram", { + .option('cram', { description: - "A cram file, the --cram flag can be used multiple times to specify multiple cram files", - type: "array", + 'A cram file, the --cram flag can be used multiple times to specify multiple cram files', + type: 'array', }) - .option("vcfgz", { + .option('vcfgz', { description: - "A tabixed VCF, the --vcfgz flag can be used multiple times to specify multiple vcfgz files", - type: "array", + 'A tabixed VCF, the --vcfgz flag can be used multiple times to specify multiple vcfgz files', + type: 'array', }) - .option("gffgz", { + .option('gffgz', { description: - "A tabixed GFF, the --gffgz can be used multiple times to specify multiple gffgz files", - type: "array", + 'A tabixed GFF, the --gffgz can be used multiple times to specify multiple gffgz files', + type: 'array', }) - .option("hic", { + .option('hic', { description: - "A .hic file, the --hic can be used multiple times to specify multiple hic files", - type: "array", + 'A .hic file, the --hic can be used multiple times to specify multiple hic files', + type: 'array', }) - .option("bigbed", { + .option('bigbed', { description: - "A .bigBed file, the --bigbed can be used multiple times to specify multiple bigbed files", - type: "array", + 'A .bigBed file, the --bigbed can be used multiple times to specify multiple bigbed files', + type: 'array', }) - .option("bedgz", { + .option('bedgz', { description: - "A bed tabix file, the --bedgz can be used multiple times to specify multiple bedtabix files", - type: "array", + 'A bed tabix file, the --bedgz can be used multiple times to specify multiple bedtabix files', + type: 'array', }) // other - .option("out", { + .option('out', { description: - "File to output to. Default: out.svg. If a filename with extension .png is supplied the program will try to automatically execute rsvg-convert to convert it to png", - type: "string", - default: "out.svg", + 'File to output to. Default: out.svg. If a filename with extension .png is supplied the program will try to automatically execute rsvg-convert to convert it to png', + type: 'string', + default: 'out.svg', }) - .option("noRasterize", { + .option('noRasterize', { description: - "Use full SVG rendering with no rasterized layers, this can substantially increase filesize", - type: "boolean", + 'Use full SVG rendering with no rasterized layers, this can substantially increase filesize', + type: 'boolean', }) - .option("defaultSession", { - description: "Use the defaultSession from config.json", - type: "boolean", + .option('defaultSession', { + description: 'Use the defaultSession from config.json', + type: 'boolean', }) .help() - .alias("help", "h") - .alias("width", "w").argv; + .alias('help', 'h') + .alias('width', 'w').argv -//prints to stderr the time it takes to execute cb +// prints to stderr the time it takes to execute cb async function time(cb) { - const start = +Date.now(); - const ret = await cb(); - console.log(`Finished rendering: ${(+Date.now() - start) / 1000}s`); - return ret; + const start = +Date.now() + const ret = await cb() + console.log(`Finished rendering: ${(+Date.now() - start) / 1000}s`) + return ret } const args = standardizeArgv(parseArgv(process.argv.slice(2)), [ - "bam", - "cram", - "vcfgz", - "hic", - "bigwig", - "bigbed", - "bedgz", - "gffgz", - "configtracks", -]); + 'bam', + 'cram', + 'vcfgz', + 'hic', + 'bigwig', + 'bigbed', + 'bedgz', + 'gffgz', + 'configtracks', +]) time(() => - renderRegion(args).then((result) => { - const outfile = args.out || "out.svg"; - if (outfile.endsWith(".png")) { + renderRegion(args).then(result => { + const outfile = args.out || 'out.svg' + if (outfile.endsWith('.png')) { const tmpobj = tmp.fileSync({ mode: 0o644, - prefix: "prefix-", - postfix: ".svg", - }); - fs.writeFileSync(tmpobj.name, result); - const ls = spawnSync("rsvg-convert", [ - "-w", + prefix: 'prefix-', + postfix: '.svg', + }) + fs.writeFileSync(tmpobj.name, result) + const ls = spawnSync('rsvg-convert', [ + '-w', args.pngwidth || 2048, tmpobj.name, - "-o", + '-o', outfile, - ]); + ]) - console.log(`rsvg-convert stderr: ${ls.stderr.toString()}`); - console.log(`rsvg-convert stdout: ${ls.stdout.toString()}`); - fs.unlinkSync(tmpobj.name); - } else if (outfile.endsWith(".pdf")) { + console.log(`rsvg-convert stderr: ${ls.stderr.toString()}`) + console.log(`rsvg-convert stdout: ${ls.stdout.toString()}`) + fs.unlinkSync(tmpobj.name) + } else if (outfile.endsWith('.pdf')) { const tmpobj = tmp.fileSync({ mode: 0o644, - prefix: "prefix-", - postfix: ".svg", - }); - fs.writeFileSync(tmpobj.name, result); - const ls = spawnSync("rsvg-convert", [ - "-w", + prefix: 'prefix-', + postfix: '.svg', + }) + fs.writeFileSync(tmpobj.name, result) + const ls = spawnSync('rsvg-convert', [ + '-w', args.pngwidth || 2048, tmpobj.name, - "-f", - "pdf", - "-o", + '-f', + 'pdf', + '-o', outfile, - ]); + ]) - console.log(`rsvg-convert stderr: ${ls.stderr.toString()}`); - console.log(`rsvg-convert stdout: ${ls.stdout.toString()}`); - fs.unlinkSync(tmpobj.name); + console.log(`rsvg-convert stderr: ${ls.stderr.toString()}`) + console.log(`rsvg-convert stdout: ${ls.stdout.toString()}`) + fs.unlinkSync(tmpobj.name) } else { - fs.writeFileSync(outfile, result); + fs.writeFileSync(outfile, result) } - }, console.error) -); + }, console.error), +) diff --git a/products/jbrowse-img/src/index.test.js b/products/jbrowse-img/src/index.test.js index 2831d6db01..251736a6de 100644 --- a/products/jbrowse-img/src/index.test.js +++ b/products/jbrowse-img/src/index.test.js @@ -2,9 +2,11 @@ import { renderRegion } from './renderRegion' import fs from 'fs' function hashCode(str) { - var hash = 0 + let hash = 0 let chr - if (str.length === 0) return hash + if (str.length === 0) { + return hash + } for (let i = 0; i < str.length; i++) { chr = str.charCodeAt(i) hash = (hash << 5) - hash + chr @@ -15,7 +17,7 @@ function hashCode(str) { const timeout = 20000 -//commented out for using remote files currently +// commented out for using remote files currently xtest( 'renders a region with --session and --config args', async () => { @@ -29,7 +31,7 @@ xtest( timeout, ) -//commented out for using remote files currently +// commented out for using remote files currently xtest( 'renders a region with --session, --tracks, and --assembly args', async () => { @@ -74,7 +76,7 @@ test( timeout, ) -//commented out for using remote files currently +// commented out for using remote files currently xtest( 'configtracks arg with urls', async () => { diff --git a/products/jbrowse-img/src/parseArgv.js b/products/jbrowse-img/src/parseArgv.js index fa487198c6..23bbd25c78 100644 --- a/products/jbrowse-img/src/parseArgv.js +++ b/products/jbrowse-img/src/parseArgv.js @@ -1,29 +1,29 @@ export function parseArgv(argv) { - const map = []; + const map = [] while (argv.length) { - const val = argv[0].slice(2); - argv = argv.slice(1); - const next = argv.findIndex((arg) => arg.startsWith("-")); + const val = argv[0].slice(2) + argv = argv.slice(1) + const next = argv.findIndex(arg => arg.startsWith('-')) if (next !== -1) { - map.push([val, argv.slice(0, next)]); - argv = argv.slice(next); + map.push([val, argv.slice(0, next)]) + argv = argv.slice(next) } else { - map.push([val, argv]); - break; + map.push([val, argv]) + break } } - return map; + return map } export function standardizeArgv(args, trackTypes) { - const result = { trackList: [] }; - args.forEach((arg) => { + const result = { trackList: [] } + args.forEach(arg => { if (trackTypes.includes(arg[0])) { - result.trackList.push(arg); + result.trackList.push(arg) } else { - result[arg[0]] = arg[1][0] || true; + result[arg[0]] = arg[1][0] || true } - }); - return result; + }) + return result } diff --git a/products/jbrowse-img/src/parseArgv.test.js b/products/jbrowse-img/src/parseArgv.test.js index dd272ce070..d1025ede83 100644 --- a/products/jbrowse-img/src/parseArgv.test.js +++ b/products/jbrowse-img/src/parseArgv.test.js @@ -1,15 +1,15 @@ -import { parseArgv } from "./parseArgv"; +import { parseArgv } from './parseArgv' -test("parse", () => { +test('parse', () => { const args = - "--bam dad.bam color:red --vcf variants.vcf --bam mom.bam --defaultSession --out out.svg --noRasterize"; + '--bam dad.bam color:red --vcf variants.vcf --bam mom.bam --defaultSession --out out.svg --noRasterize' - expect(parseArgv(args.split(" "))).toEqual([ - ["bam", ["dad.bam", "color:red"]], - ["vcf", ["variants.vcf"]], - ["bam", ["mom.bam"]], - ["defaultSession", []], - ["out", ["out.svg"]], - ["noRasterize", []], - ]); -}); + expect(parseArgv(args.split(' '))).toEqual([ + ['bam', ['dad.bam', 'color:red']], + ['vcf', ['variants.vcf']], + ['bam', ['mom.bam']], + ['defaultSession', []], + ['out', ['out.svg']], + ['noRasterize', []], + ]) +}) diff --git a/products/jbrowse-img/src/renderRegion.js b/products/jbrowse-img/src/renderRegion.js index 2f1ef598f6..3763e2d835 100644 --- a/products/jbrowse-img/src/renderRegion.js +++ b/products/jbrowse-img/src/renderRegion.js @@ -1,6 +1,5 @@ import 'regenerator-runtime/runtime' import { createViewState } from '@jbrowse/react-linear-genome-view' -import { getSnapshot } from 'mobx-state-tree' import { renderToSvg } from '@jbrowse/plugin-linear-genome-view' import { when } from 'mobx' import path from 'path' @@ -118,7 +117,7 @@ export function readData(opts) { } trackList.forEach(track => { - const [type, [file, opts]] = track + const [type, [file]] = track if (type === 'bam') { configData.tracks = [ diff --git a/products/jbrowse-img/src/util.js b/products/jbrowse-img/src/util.js index a8e7b96d34..0dd5509734 100644 --- a/products/jbrowse-img/src/util.js +++ b/products/jbrowse-img/src/util.js @@ -1,2 +1,2 @@ // nice helper function from https://stackoverflow.com/questions/263965/ -export const booleanize = (string) => (string === "false" ? false : !!string); +export const booleanize = string => (string === 'false' ? false : !!string)