Skip to content

Commit

Permalink
Format with lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 22, 2021
1 parent 10be2fc commit ab26a56
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 157 deletions.
1 change: 0 additions & 1 deletion packages/core/util/io/declare.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion products/jbrowse-img/src/bin.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("./index.js");
require('./index.js')
242 changes: 122 additions & 120 deletions products/jbrowse-img/src/index.js
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),
)
12 changes: 7 additions & 5 deletions products/jbrowse-img/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
30 changes: 15 additions & 15 deletions products/jbrowse-img/src/parseArgv.js
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
}
Loading

0 comments on commit ab26a56

Please sign in to comment.