Skip to content

Commit

Permalink
change --template to --prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Jun 24, 2021
1 parent da63a07 commit 9e58b87
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.1.7
======
+ breaking: change `--template` to `--prefix`

v0.1.5
======
+ add `--template` option to allow for each variant or site to be written to a separte js (or base64) file.
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ This can be scripted with your favorite language for a set of regions.
# options

```
Usage:
jigv [options] [xams ...]
Arguments:
Expand All @@ -66,20 +65,19 @@ Options:
--cytoband=CYTOBAND optional path to cytoband/ideogram file
--annotation=ANNOTATION path to additional bed or vcf file to be added as a track; may be specified multiple times
--ped=PED pedigree file used to find relations for --sample
--template=TEMPLATE if specified, encoded data for each region is written to it's own js file and no html is generated. this is a file template like: 'jigv_encoded/HG002/${site}.js' where and `site` must be in the template to be filled by jigv
--template-raw by default if --template is specified, then the data is written to a javascript variable and includes the data: prefix. if this option is specified (along with --template), then the raw base64 encoded data is written to the file.
--prefix=PREFIX if specified, encoded data for each region is written to it's own js file and no html is generated. this is a path prefix like: 'jigv_encoded/HG002/' where where and `$site.js` will be added by jigv
--prefix-raw by default if --prefix is specified, the data is written to a javascript variable and includes the 'data:base64' prefix. if this option is also specified, then the raw base64 encoded data is written to the file.
--fasta=FASTA path to indexed fasta file; required for cram files
--flank=FLANK bases on either side of the variant or region to show (default: 100) (default: 100)
-h, --help Show this help
```
### template
### prefix

By default, jigv will embed all data for all sites into a single html file. This can scale up to about 2000 variants
for a trio at which point the single file becomes quite large (~60MB).
Using `--template`, it's possible to send each encoded site to a separate file. These can be loaded on demand from a
Using `--prefix`, it's possible to send each encoded site to a separate file. These can be loaded on demand from a
server or sent to the user and loaded as a script on demand from the local file system.

Files written with `--template` but without `--template-raw' can be loaded from the local file-sytem of the user (or from a server depending on if they are viewing as `file:///...` on their local system or on a server. The code for that looks like this:
Files written with `--prefix` but without `--prefix-raw' can be loaded from the local file-sytem of the user (or from a server depending on if they are viewing as `file:///...` on their local system or on a server. The code for that looks like this:

```Javascript

Expand Down
34 changes: 17 additions & 17 deletions jigv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -403,23 +403,23 @@ proc first_affected_or_zero*(samples:seq[Sample]): int =
if samples.len == 0: raise newException(IndexError, "[tiwih] no samples given")
return 0
proc write_site(s:string, site:string, tmpl:string, template_raw:bool) =
var path = tmpl % ["site", site]
proc write_site(s:string, site:string, prefix:string, prefix_raw:bool) =
var path = &"{prefix}{site}.js"
createDir(splitFile(path).dir)
var fh:File
if tmpl == "stdout":
if prefix == "stdout":
fh = stdout
else:
doAssert fh.open(path, mode=fmWrite), "[jigv] error opening template file"
if not template_raw:
doAssert fh.open(path, mode=fmWrite), &"[jigv] error opening file: {path}"
if not prefix_raw:
fh.write("jigv_data = \"")
fh.write(s)
fh.write_line("\"")
else:
let prefix = "data:application/gzip;base64,"
doAssert s.startsWith(prefix)
fh.write_line(s[prefix.len .. s.high])
if tmpl != "stdout":
let dprefix = "data:application/gzip;base64,"
doAssert s.startsWith(dprefix)
fh.write_line(s[dprefix.len .. s.high])
if prefix != "stdout":
fh.close()
proc main*(args:seq[string]=commandLineParams()) =
Expand All @@ -432,8 +432,8 @@ proc main*(args:seq[string]=commandLineParams()) =
option("--cytoband", help="optional path to cytoband/ideogram file")
option("--annotation", help="path to additional bed or vcf file to be added as a track; may be specified multiple times", multiple=true)
option("--ped", help="pedigree file used to find relations for --sample")
option("--template", help="if specified, encoded data for each region is written to it's own js file and no html is generated. this is a file template like: 'jigv_encoded/HG002/${site}.js' where and `site` must be in the template to be filled by jigv", default="")
flag("--template-raw", help="by default if --template is specified, then the data is written to a javascript variable and includes the data: prefix. if this option is specified (along with --template), then the raw base64 encoded data is written to the file.")
option("--prefix", help="if specified, encoded data for each region is written to it's own js file and no html is generated. this is a path prefix like: 'jigv_encoded/HG002/' where where and `$site.js` will be added by jigv", default="")
flag("--prefix-raw", help="by default if --prefix is specified, the data is written to a javascript variable and includes the 'data:base64' prefix. if this option is also specified, then the raw base64 encoded data is written to the file.")
option("--fasta", help="path to indexed fasta file; required for cram files")
option("--flank", default="100", help="bases on either side of the variant or region to show (default: 100)")
arg("xams", nargs= -1, help="indexed bam or cram files for relevant samples. read-groups must match samples in vcf.")
Expand Down Expand Up @@ -522,9 +522,9 @@ proc main*(args:seq[string]=commandLineParams()) =
tracks["genome"] = % opts.genome_build
var s = ($tracks).encode
if opts.`template` != "":
if opts.prefix != "":
var site = &"""{v.CHROM}-{v.start+1}-{v.REF}-{join(v.ALT, ",")}"""
write_site(s, site, opts.`template`, opts.template_raw)
write_site(s, site, opts.prefix, opts.prefix_raw)
continue
Expand All @@ -545,16 +545,16 @@ proc main*(args:seq[string]=commandLineParams()) =
tracks["genome"] = % opts.genome_build
var s = ($tracks).encode
if opts.`template` != "":
if opts.prefix != "":
var site = locus.replace(':', '-')
write_site(s, site, opts.`template`, opts.template_raw)
write_site(s, site, opts.prefix, opts.prefix_raw)
continue
loc2idx[($(tracks["locus"].str)).replace(",", "")] = loc2idx.len
sessions.add(s)
if opts.`template` == "":
if opts.prefix == "":
stderr.write_line &"[jigv] writing {sessions.len} regions to html"
if ivcf != nil:
Expand All @@ -570,7 +570,7 @@ proc main*(args:seq[string]=commandLineParams()) =
meta_options["sessions"] = %* sessions
meta_options["loc2idx"] = %* loc2idx
if opts.`template` == "":
if opts.prefix == "":
var index_html = get_html().replace("<OPTIONS>", pretty(meta_options)).replace("<JIGV_CUSTOM_JS>", "")
echo index_html
Expand Down
2 changes: 1 addition & 1 deletion jigv.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.1.5"
version = "0.1.7"
author = "Brent Pedersen"
description = "igv.js static files"
license = "MIT"
Expand Down

0 comments on commit 9e58b87

Please sign in to comment.