diff --git a/CHANGES.md b/CHANGES.md index 7c226ea..ef32300 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/README.md b/README.md index a390ff6..d01cfaf 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ This can be scripted with your favorite language for a set of regions. # options ``` -Usage: jigv [options] [xams ...] Arguments: @@ -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 diff --git a/jigv.nim b/jigv.nim index a9bd10f..192c649 100644 --- a/jigv.nim +++ b/jigv.nim @@ -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()) = @@ -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.") @@ -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 @@ -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: @@ -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("", pretty(meta_options)).replace("", "") echo index_html diff --git a/jigv.nimble b/jigv.nimble index 8e4b0df..e6a0bd1 100644 --- a/jigv.nimble +++ b/jigv.nimble @@ -1,4 +1,4 @@ -version = "0.1.5" +version = "0.1.7" author = "Brent Pedersen" description = "igv.js static files" license = "MIT"