-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
157 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
require("./index.js"); | ||
require('./index.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.