Mercurial > repos > fubar > jbrowse2dev
comparison jbrowse2/jbrowse2.py @ 6:88b9b105c09b draft
Uploaded
author | fubar |
---|---|
date | Fri, 05 Jan 2024 01:58:02 +0000 |
parents | 42ca8804cd93 |
children | 234cf4490901 |
comparison
equal
deleted
inserted
replaced
5:42ca8804cd93 | 6:88b9b105c09b |
---|---|
108 | 108 |
109 | 109 |
110 class JbrowseConnector(object): | 110 class JbrowseConnector(object): |
111 def __init__(self, jbrowse, outdir, genomes, standalone=None): | 111 def __init__(self, jbrowse, outdir, genomes, standalone=None): |
112 self.debug = False | 112 self.debug = False |
113 self.usejson = True | |
113 self.giURL = GALAXY_INFRASTRUCTURE_URL | 114 self.giURL = GALAXY_INFRASTRUCTURE_URL |
114 self.jbrowse = jbrowse | 115 self.jbrowse = jbrowse |
115 self.outdir = outdir | 116 self.outdir = outdir |
116 os.makedirs(self.outdir, exist_ok=True) | 117 os.makedirs(self.outdir, exist_ok=True) |
117 self.genome_paths = genomes | 118 self.genome_paths = genomes |
118 self.standalone = standalone | 119 self.standalone = standalone |
119 self.trackIdlist = [] | 120 self.trackIdlist = [] |
120 self.tracksToAdd = [] | 121 self.tracksToAdd = [] |
121 self.config_json = { | 122 self.config_json = {} |
122 "configuration": { | 123 self.config_json_file = os.path.realpath(os.path.join(outdir, "config.json")) |
123 "rpc": { | 124 self.clone_jbrowse(self.jbrowse, self.outdir) |
124 "defaultDriver": "WebWorkerRpcDriver", | |
125 "drivers": {"MainThreadRpcDriver": {}, "WebWorkerRpcDriver": {}}, | |
126 }, | |
127 "logoPath": {"locationType": "UriLocation", "uri": ""}, | |
128 } | |
129 } | |
130 self.config_json_file = os.path.join(outdir, "config.json") | |
131 if standalone == "complete": | |
132 self.clone_jbrowse(self.jbrowse, self.outdir) | |
133 elif standalone == "minimal": | |
134 self.clone_jbrowse(self.jbrowse, self.outdir, minimal=True) | |
135 | 125 |
136 def subprocess_check_call(self, command, output=None): | 126 def subprocess_check_call(self, command, output=None): |
137 if output: | 127 if output: |
138 if self.debug: | 128 if self.debug: |
139 log.debug("cd %s && %s > %s", self.outdir, " ".join(command), output) | 129 log.debug("cd %s && %s > %s", self.outdir, " ".join(command), output) |
179 return self.subprocess_check_call(cmd) | 169 return self.subprocess_check_call(cmd) |
180 | 170 |
181 def process_genomes(self): | 171 def process_genomes(self): |
182 assemblies = [] | 172 assemblies = [] |
183 for i, genome_node in enumerate(self.genome_paths): | 173 for i, genome_node in enumerate(self.genome_paths): |
184 log.info("genome_node=%s" % str(genome_node)) | 174 if self.debug: |
185 # We only expect one input genome per run. This for loop is just | 175 log.info("genome_node=%s" % str(genome_node)) |
186 # easier to write than the alternative / catches any possible | |
187 # issues. | |
188 genome_name = genome_node["meta"]["dataset_dname"] | 176 genome_name = genome_node["meta"]["dataset_dname"] |
189 dsId = genome_node["meta"]["dataset_id"] | 177 dsId = genome_node["meta"]["dataset_id"] |
190 fapath = genome_node["path"] | 178 fapath = genome_node["path"] |
191 faname = genome_name + ".fasta" | |
192 faind = os.path.realpath(os.path.join(self.outdir, faname + ".fai")) | |
193 if self.standalone == "complete": | 179 if self.standalone == "complete": |
194 faurl = faname | 180 faname = genome_name + ".fa.gz" |
195 fadest = os.path.realpath(os.path.join(self.outdir, faname)) | 181 fadest = os.path.realpath(os.path.join(self.outdir, faname)) |
196 cmd = ["cp", fapath, fadest] | 182 cmd = "bgzip -i -c %s > %s && samtools faidx %s" % ( |
183 fapath, | |
184 fadest, | |
185 fadest, | |
186 ) | |
187 self.subprocess_popen(cmd) | |
188 adapter = { | |
189 "type": "BgzipFastaAdapter", | |
190 "fastaLocation": { | |
191 "uri": faname, | |
192 }, | |
193 "faiLocation": { | |
194 "uri": faname + ".fai", | |
195 }, | |
196 "gziLocation": { | |
197 "uri": faname + ".gzi", | |
198 }, | |
199 } | |
200 else: | |
201 faurl = "%s/api/datasets/%s/display" % (self.giURL, dsId) | |
202 faname = genome_name + ".fa.fai" | |
203 fastalocation = { | |
204 "uri": faurl, | |
205 } | |
206 failocation = { | |
207 "uri": faname, | |
208 } | |
209 adapter = { | |
210 "type": "IndexedFastaAdapter", | |
211 "fastaLocation": fastalocation, | |
212 "faiLocation": failocation, | |
213 } | |
214 | |
215 cmd = ["samtools", "faidx", fapath, "--fai-idx", faname] | |
197 self.subprocess_check_call(cmd) | 216 self.subprocess_check_call(cmd) |
198 else: | |
199 faurl = "%s/api/datasets/%s/display?to_ext=fasta" % (self.giURL, dsId) | |
200 cmd = ["samtools", "faidx", fapath, "--fai-idx", faind] | |
201 self.subprocess_check_call(cmd) | |
202 trackDict = { | 217 trackDict = { |
203 "name": genome_name, | 218 "name": genome_name, |
204 "sequence": { | 219 "sequence": { |
205 "type": "ReferenceSequenceTrack", | 220 "type": "ReferenceSequenceTrack", |
206 "trackId": genome_name, | 221 "trackId": genome_name, |
207 "adapter": { | 222 "adapter": adapter, |
208 "type": "IndexedFastaAdapter", | 223 }, |
209 "fastaLocation": {"uri": faurl, "locationType": "UriLocation"}, | 224 "rendering": {"type": "DivSequenceRenderer"}, |
210 "faiLocation": { | |
211 "uri": faname + ".fai", | |
212 "locationType": "UriLocation", | |
213 }, | |
214 }, | |
215 }, | |
216 } | 225 } |
217 assemblies.append(trackDict) | 226 assemblies.append(trackDict) |
218 self.config_json["assemblies"] = assemblies | |
219 self.genome_name = genome_name | 227 self.genome_name = genome_name |
220 self.genome_path = faurl | 228 if self.usejson: |
221 self.genome_fai_path = faname + ".fai" | 229 self.config_json["assemblies"] = assemblies |
230 else: | |
231 if self.standalone == "complete": | |
232 cmd = [ | |
233 "jbrowse", | |
234 "add-assembly", | |
235 faname, | |
236 "-t", | |
237 "bgzipFasta", | |
238 "-n", | |
239 genome_name, | |
240 "--load", | |
241 "inPlace", | |
242 "--faiLocation", | |
243 faname + ".fai", | |
244 "--gziLocation", | |
245 faname + ".gzi", | |
246 "--target", | |
247 self.outdir, | |
248 ] | |
249 else: | |
250 cmd = [ | |
251 "jbrowse", | |
252 "add-assembly", | |
253 faname, | |
254 "-t", | |
255 "indexedFasta", | |
256 "-n", | |
257 genome_name, | |
258 "--load", | |
259 "inPlace", | |
260 "--faiLocation", | |
261 faname + ".fai", | |
262 "--target", | |
263 self.outdir, | |
264 ] | |
265 self.subprocess_check_call(cmd) | |
222 | 266 |
223 def add_default_view(self): | 267 def add_default_view(self): |
224 cmd = [ | 268 cmd = [ |
225 "jbrowse", | 269 "jbrowse", |
226 "set-default-session", | 270 "set-default-session", |
227 "-s", | 271 "-s", |
228 self.config_json_file, | 272 self.config_json_file, |
229 "-t", | 273 "-t", |
230 ",".join(self.trackIdlist), | 274 ",".join(self.trackIdlist), |
231 "-n", | 275 "-n", |
232 "Default", | 276 "JBrowse2 in Galaxy", |
233 "--target", | 277 "--target", |
234 self.outdir, | 278 self.config_json_file, |
235 ] # | 279 "-v", |
280 " LinearGenomeView", | |
281 ] | |
282 if True or self.debug: | |
283 log.info("### calling set-default-session with cmd=%s" % " ".join(cmd)) | |
236 self.subprocess_check_call(cmd) | 284 self.subprocess_check_call(cmd) |
237 | 285 |
238 def write_config(self): | 286 def write_config(self): |
239 with open(self.config_json_file, "w") as fp: | 287 with open(self.config_json_file, "w") as fp: |
240 json.dump(self.config_json, fp) | 288 json.dump(self.config_json, fp) |
266 if self.standalone == "complete": | 314 if self.standalone == "complete": |
267 dest = os.path.realpath(os.path.join(self.outdir, hname)) | 315 dest = os.path.realpath(os.path.join(self.outdir, hname)) |
268 url = hname | 316 url = hname |
269 cmd = ["cp", data, dest] | 317 cmd = ["cp", data, dest] |
270 self.subprocess_check_call(cmd) | 318 self.subprocess_check_call(cmd) |
319 floc = { | |
320 "uri": hname, | |
321 } | |
271 else: | 322 else: |
272 url = "%s/api/datasets/%s/display?to_ext=hic" % (self.giURL, dsId) | 323 url = "%s/api/datasets/%s/display?to_ext=hic" % (self.giURL, dsId) |
324 floc = { | |
325 "uri": url, | |
326 } | |
273 trackDict = { | 327 trackDict = { |
274 "type": "HicTrack", | 328 "type": "HicTrack", |
275 "trackId": tId, | 329 "trackId": tId, |
276 "name": hname, | 330 "name": hname, |
277 "assemblyNames": [self.genome_name], | 331 "assemblyNames": [self.genome_name], |
278 "adapter": { | 332 "adapter": { |
279 "type": "HicAdapter", | 333 "type": "HicAdapter", |
280 "hicLocation": {"uri": url, "locationType": "UriLocation"}, | 334 "hicLocation": floc, |
281 }, | 335 }, |
282 } | 336 } |
283 self.tracksToAdd.append(trackDict) | 337 if self.usejson: |
284 self.trackIdlist.append(tId) | 338 self.tracksToAdd.append(trackDict) |
339 self.trackIdlist.append(tId) | |
340 else: | |
341 cmd = [ | |
342 "jbrowse", | |
343 "add-track", | |
344 url, | |
345 "-t", | |
346 "HicTrack", | |
347 "-a", | |
348 self.genome_name, | |
349 "-n", | |
350 hname, | |
351 "--load", | |
352 "inPlace", | |
353 "--target", | |
354 self.outdir, | |
355 ] | |
356 self.subprocess_check_call(cmd) | |
285 | 357 |
286 def add_maf(self, data, trackData): | 358 def add_maf(self, data, trackData): |
287 """ | 359 """ |
288 from https://github.com/cmdcolin/maf2bed | 360 from https://github.com/cmdcolin/maf2bed |
289 Note: Both formats start with a MAF as input, and note that your MAF file should contain the species name and chromosome name | 361 Note: Both formats start with a MAF as input, and note that your MAF file should contain the species name and chromosome name |
331 "trackId": tId, | 403 "trackId": tId, |
332 "name": trackData["name"], | 404 "name": trackData["name"], |
333 "adapter": { | 405 "adapter": { |
334 "type": "MafTabixAdapter", | 406 "type": "MafTabixAdapter", |
335 "samples": samples, | 407 "samples": samples, |
336 "bedGzLocation": {"uri": fname + ".sorted.bed.gz"}, | 408 "bedGzLocation": { |
409 "uri": fname + ".sorted.bed.gz", | |
410 }, | |
337 "index": { | 411 "index": { |
338 "location": {"uri": fname + ".sorted.bed.gz.tbi"}, | 412 "location": { |
413 "uri": fname + ".sorted.bed.gz.tbi", | |
414 }, | |
339 }, | 415 }, |
340 }, | 416 }, |
341 "assemblyNames": [self.genome_name], | 417 "assemblyNames": [self.genome_name], |
342 } | 418 } |
343 self.tracksToAdd.append(trackDict) | 419 self.tracksToAdd.append(trackDict) |
388 "trackId": tId, | 464 "trackId": tId, |
389 "name": trackData["name"], | 465 "name": trackData["name"], |
390 "assemblyNames": [self.genome_name], | 466 "assemblyNames": [self.genome_name], |
391 "adapter": { | 467 "adapter": { |
392 "type": "Gff3TabixAdapter", | 468 "type": "Gff3TabixAdapter", |
393 "gffGzLocation": {"locationType": "UriLocation", "uri": url}, | 469 "gffGzLocation": { |
470 "uri": url, | |
471 }, | |
394 "index": { | 472 "index": { |
395 "location": {"locationType": "UriLocation", "uri": url + ".tbi"} | 473 "location": { |
474 "uri": url + ".tbi", | |
475 } | |
396 }, | 476 }, |
397 }, | 477 }, |
398 "displays": [ | 478 "displays": [ |
399 { | 479 { |
400 "type": "LinearBasicDisplay", | 480 "type": "LinearBasicDisplay", |
401 "displayId": "%s-LinearBasicDisplay" % tId, | 481 "displayId": "%s-LinearBasicDisplay" % tId, |
402 }, | 482 }, |
403 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, | 483 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, |
404 ], | 484 ], |
405 } | 485 } |
406 self.tracksToAdd.append(trackDict) | 486 if self.usejson: |
407 self.trackIdlist.append(tId) | 487 self.tracksToAdd.append(trackDict) |
488 self.trackIdlist.append(tId) | |
489 else: | |
490 cmd = [ | |
491 "jbrowse", | |
492 "add-track", | |
493 url, | |
494 "-t", | |
495 "FeatureTrack", | |
496 "-a", | |
497 self.genome_name, | |
498 "--indexFile", | |
499 url + ".tbi", | |
500 "-n", | |
501 trackData["name"], | |
502 "--load", | |
503 "inPlace", | |
504 "--target", | |
505 self.outdir, | |
506 ] | |
507 self.subprocess_check_call(cmd) | |
408 os.unlink(gff3) | 508 os.unlink(gff3) |
409 | 509 |
410 def add_bigwig(self, data, trackData): | 510 def add_bigwig(self, data, trackData): |
411 fname = trackData["name"] | 511 url = "%s.bw" % trackData["name"] |
412 if self.standalone == "complete": | 512 if self.standalone == "complete": |
413 dest = os.path.realpath(os.path.join(self.outdir, fname)) | 513 dest = os.path.realpath(os.path.join(self.outdir, url)) |
414 url = fname | |
415 cmd = ["cp", data, dest] | 514 cmd = ["cp", data, dest] |
416 self.subprocess_check_call(cmd) | 515 self.subprocess_check_call(cmd) |
516 bwloc = {"uri": url} | |
417 else: | 517 else: |
418 dsId = trackData["metadata"]["dataset_id"] | 518 dsId = trackData["metadata"]["dataset_id"] |
419 url = "%s/api/datasets/%s/display?to_ext=fasta" % (self.giURL, dsId) | 519 url = "%s/api/datasets/%s/display?to_ext=fasta" % (self.giURL, dsId) |
520 bwloc = {"uri": url} | |
420 tId = trackData["label"] | 521 tId = trackData["label"] |
421 trackDict = { | 522 trackDict = { |
422 "type": "QuantitativeTrack", | 523 "type": "QuantitativeTrack", |
423 "trackId": tId, | 524 "trackId": tId, |
424 "name": fname, | 525 "name": url, |
425 "assemblyNames": [ | 526 "assemblyNames": [ |
426 self.genome_name, | 527 self.genome_name, |
427 ], | 528 ], |
428 "adapter": { | 529 "adapter": { |
429 "type": "BigWigAdapter", | 530 "type": "BigWigAdapter", |
430 "bigWigLocation": {"locationType": "UriLocation", "uri": url}, | 531 "bigWigLocation": bwloc, |
431 }, | 532 }, |
432 "displays": [ | 533 "displays": [ |
433 { | 534 { |
434 "type": "LinearWiggleDisplay", | 535 "type": "LinearWiggleDisplay", |
435 "displayId": "%s-LinearWiggleDisplay" % tId, | 536 "displayId": "%s-LinearWiggleDisplay" % tId, |
436 } | 537 } |
437 ], | 538 ], |
438 } | 539 } |
439 self.tracksToAdd.append(trackDict) | 540 if self.usejson: |
440 self.trackIdlist.append(tId) | 541 self.tracksToAdd.append(trackDict) |
542 self.trackIdlist.append(tId) | |
543 else: | |
544 cmd = [ | |
545 "jbrowse", | |
546 "add-track", | |
547 url, | |
548 "-t", | |
549 "QuantitativeTrack", | |
550 "-a", | |
551 self.genome_name, | |
552 "-n", | |
553 trackData["name"], | |
554 "--load", | |
555 "inPlace", | |
556 "--target", | |
557 self.outdir, | |
558 ] | |
559 self.subprocess_check_call(cmd) | |
441 | 560 |
442 def add_bam(self, data, trackData, bamOpts, bam_index=None, **kwargs): | 561 def add_bam(self, data, trackData, bamOpts, bam_index=None, **kwargs): |
443 tId = trackData["label"] | 562 tId = trackData["label"] |
444 fname = "%s.bam" % trackData["label"] | 563 fname = "%s.bam" % trackData["label"] |
445 dest = os.path.realpath("%s/%s" % (self.outdir, fname)) | 564 dest = os.path.realpath("%s/%s" % (self.outdir, fname)) |
446 if self.standalone == "minimal": | 565 if self.standalone == "complete": |
566 url = fname | |
567 self.subprocess_check_call(["cp", data, dest]) | |
568 log.info("### copied %s to %s" % (data, dest)) | |
569 bloc = {"uri": url} | |
570 else: | |
447 dsId = trackData["metadata"]["dataset_id"] | 571 dsId = trackData["metadata"]["dataset_id"] |
448 url = "%s/api/datasets/%s/display?to_ext=bam" % (self.giURL, dsId) | 572 url = "%s/api/datasets/%s/display?to_ext=bam" % (self.giURL, dsId) |
449 else: | 573 bloc = {"uri": url} |
450 url = fname | |
451 self.symlink_or_copy(data, dest) | |
452 if bam_index is not None and os.path.exists(os.path.realpath(bam_index)): | 574 if bam_index is not None and os.path.exists(os.path.realpath(bam_index)): |
453 # bai most probably made by galaxy and stored in galaxy dirs, need to copy it to dest | 575 # bai most probably made by galaxy and stored in galaxy dirs, need to copy it to dest |
454 self.subprocess_check_call( | 576 self.subprocess_check_call( |
455 ["cp", os.path.realpath(bam_index), dest + ".bai"] | 577 ["cp", os.path.realpath(bam_index), dest + ".bai"] |
456 ) | 578 ) |
468 "trackId": tId, | 590 "trackId": tId, |
469 "name": trackData["name"], | 591 "name": trackData["name"], |
470 "assemblyNames": [self.genome_name], | 592 "assemblyNames": [self.genome_name], |
471 "adapter": { | 593 "adapter": { |
472 "type": "BamAdapter", | 594 "type": "BamAdapter", |
473 "bamLocation": {"locationType": "UriLocation", "uri": url}, | 595 "bamLocation": bloc, |
474 "index": { | 596 "index": { |
475 "location": {"locationType": "UriLocation", "uri": fname + ".bai"} | 597 "location": { |
476 }, | 598 "uri": fname + ".bai", |
477 "sequenceAdapter": { | 599 } |
478 "type": "IndexedFastaAdapter", | |
479 "fastaLocation": { | |
480 "locationType": "UriLocation", | |
481 "uri": self.genome_path, | |
482 }, | |
483 "faiLocation": { | |
484 "locationType": "UriLocation", | |
485 "uri": self.genome_fai_path, | |
486 }, | |
487 "metadataLocation": { | |
488 "locationType": "UriLocation", | |
489 "uri": "/path/to/fa.metadata.yaml", | |
490 }, | |
491 }, | 600 }, |
492 }, | 601 }, |
493 } | 602 } |
494 self.tracksToAdd.append(trackDict) | 603 if self.usejson: |
495 self.trackIdlist.append(tId) | 604 self.tracksToAdd.append(trackDict) |
605 self.trackIdlist.append(tId) | |
606 else: | |
607 cmd = [ | |
608 "jbrowse", | |
609 "add-track", | |
610 fname, | |
611 "-t", | |
612 "AlignmentsTrack", | |
613 "-l", | |
614 "inPlace", | |
615 "-a", | |
616 self.genome_name, | |
617 "--indexFile", | |
618 fname + ".bai", | |
619 "-n", | |
620 trackData["name"], | |
621 "--target", | |
622 self.outdir, | |
623 ] | |
624 self.subprocess_check_call(cmd) | |
496 | 625 |
497 def add_vcf(self, data, trackData): | 626 def add_vcf(self, data, trackData): |
498 tId = trackData["label"] | 627 tId = trackData["label"] |
499 url = "%s/api/datasets/%s/display" % ( | 628 url = "%s/api/datasets/%s/display" % ( |
500 self.giURL, | 629 self.giURL, |
511 "trackId": tId, | 640 "trackId": tId, |
512 "name": trackData["name"], | 641 "name": trackData["name"], |
513 "assemblyNames": [self.genome_name], | 642 "assemblyNames": [self.genome_name], |
514 "adapter": { | 643 "adapter": { |
515 "type": "VcfTabixAdapter", | 644 "type": "VcfTabixAdapter", |
516 "vcfGzLocation": {"uri": url, "locationType": "UriLocation"}, | 645 "vcfGzLocation": { |
646 "uri": url, | |
647 }, | |
517 "index": { | 648 "index": { |
518 "location": {"uri": url + ".tbi", "locationType": "UriLocation"} | 649 "location": { |
650 "uri": url + ".tbi", | |
651 } | |
519 }, | 652 }, |
520 }, | 653 }, |
521 "displays": [ | 654 "displays": [ |
522 { | 655 { |
523 "type": "LinearVariantDisplay", | 656 "type": "LinearVariantDisplay", |
531 "type": "LinearPairedArcDisplay", | 664 "type": "LinearPairedArcDisplay", |
532 "displayId": "%s-LinearPairedArcDisplay" % tId, | 665 "displayId": "%s-LinearPairedArcDisplay" % tId, |
533 }, | 666 }, |
534 ], | 667 ], |
535 } | 668 } |
536 self.tracksToAdd.append(trackDict) | 669 if self.usejson: |
537 self.trackIdlist.append(tId) | 670 self.tracksToAdd.append(trackDict) |
671 self.trackIdlist.append(tId) | |
672 else: | |
673 cmd = [ | |
674 "jbrowse", | |
675 "add-track", | |
676 url, | |
677 "-t", | |
678 "VariantTrack", | |
679 "-a", | |
680 self.genome_name, | |
681 "--indexFile", | |
682 url + ".tbi", | |
683 "-n", | |
684 trackData["name"], | |
685 "--load", | |
686 "inPlace", | |
687 "--target", | |
688 self.outdir, | |
689 ] | |
690 self.subprocess_check_call(cmd) | |
538 | 691 |
539 def _sort_gff(self, data, dest): | 692 def _sort_gff(self, data, dest): |
540 # Only index if not already done | 693 # Only index if not already done |
541 if not os.path.exists(dest + ".gz"): | 694 if not os.path.exists(dest + ".gz"): |
542 cmd = "jbrowse sort-gff %s | bgzip -c > %s.gz" % ( | 695 cmd = "jbrowse sort-gff %s | bgzip -c > %s.gz" % ( |
565 "trackId": tId, | 718 "trackId": tId, |
566 "name": trackData["name"], | 719 "name": trackData["name"], |
567 "assemblyNames": [self.genome_name], | 720 "assemblyNames": [self.genome_name], |
568 "adapter": { | 721 "adapter": { |
569 "type": "Gff3TabixAdapter", | 722 "type": "Gff3TabixAdapter", |
570 "gffGzLocation": {"locationType": "UriLocation", "uri": url}, | 723 "gffGzLocation": { |
724 "uri": url, | |
725 }, | |
571 "index": { | 726 "index": { |
572 "location": {"uri": url + ".tbi", "locationType": "UriLocation"} | 727 "location": { |
728 "uri": url + ".tbi", | |
729 } | |
573 }, | 730 }, |
574 }, | 731 }, |
575 "displays": [ | 732 "displays": [ |
576 { | 733 { |
577 "type": "LinearBasicDisplay", | 734 "type": "LinearBasicDisplay", |
578 "displayId": "%s-LinearBasicDisplay" % tId, | 735 "displayId": "%s-LinearBasicDisplay" % tId, |
579 }, | 736 }, |
580 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, | 737 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, |
581 ], | 738 ], |
582 } | 739 } |
583 self.tracksToAdd.append(trackDict) | 740 if self.usejson: |
584 self.trackIdlist.append(tId) | 741 self.tracksToAdd.append(trackDict) |
742 self.trackIdlist.append(tId) | |
743 else: | |
744 cmd = [ | |
745 "jbrowse", | |
746 "add-track", | |
747 url, | |
748 "-t", | |
749 "FeatureTrack", | |
750 "-a", | |
751 self.genome_name, | |
752 "-n", | |
753 trackData["name"], | |
754 "--load", | |
755 "inPlace", | |
756 "--target", | |
757 self.outdir, | |
758 ] | |
759 self.subprocess_check_call(cmd) | |
585 | 760 |
586 def add_bed(self, data, ext, trackData): | 761 def add_bed(self, data, ext, trackData): |
587 url = "%s.%s" % (trackData["label"], ext) | 762 url = "%s.%s" % (trackData["label"], ext) |
588 dest = os.path.realpath("%s/%s.gz" % (self.outdir, url)) | 763 dest = os.path.realpath("%s/%s.gz" % (self.outdir, url)) |
589 self._sort_bed(data, dest) | 764 self._sort_bed(data, dest) |
594 "trackId": tId, | 769 "trackId": tId, |
595 "name": trackData["name"], | 770 "name": trackData["name"], |
596 "assemblyNames": [self.genome_name], | 771 "assemblyNames": [self.genome_name], |
597 "adapter": { | 772 "adapter": { |
598 "type": "BedTabixAdapter", | 773 "type": "BedTabixAdapter", |
599 "bedGzLocation": {"locationType": "UriLocation", "uri": url}, | 774 "bedGzLocation": { |
775 "uri": url, | |
776 }, | |
600 "index": { | 777 "index": { |
601 "location": {"uri": url + ".tbi", "locationType": "UriLocation"} | 778 "location": { |
779 "uri": url + ".tbi", | |
780 } | |
602 }, | 781 }, |
603 }, | 782 }, |
604 "displays": [ | 783 "displays": [ |
605 { | 784 { |
606 "type": "LinearBasicDisplay", | 785 "type": "LinearBasicDisplay", |
607 "displayId": "%s-LinearBasicDisplay" % tId, | 786 "displayId": "%s-LinearBasicDisplay" % tId, |
608 }, | 787 }, |
609 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, | 788 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, |
610 ], | 789 ], |
611 } | 790 } |
612 self.tracksToAdd.append(trackDict) | 791 if self.usejson: |
613 self.trackIdlist.append(tId) | 792 self.tracksToAdd.append(trackDict) |
793 self.trackIdlist.append(tId) | |
794 else: | |
795 cmd = [ | |
796 "jbrowse", | |
797 "add-track", | |
798 url, | |
799 "-t", | |
800 "FeatureTrack", | |
801 "-a", | |
802 self.genome_name, | |
803 "--indexFile", | |
804 url + ".tbi", | |
805 "-n", | |
806 trackData["name"], | |
807 "--load", | |
808 "inPlace", | |
809 "--target", | |
810 self.outdir, | |
811 ] | |
812 self.subprocess_check_call(cmd) | |
614 | 813 |
615 def process_annotations(self, track): | 814 def process_annotations(self, track): |
616 category = track["category"].replace("__pd__date__pd__", TODAY) | 815 category = track["category"].replace("__pd__date__pd__", TODAY) |
617 for i, ( | 816 for i, ( |
618 dataset_path, | 817 dataset_path, |
711 elif dataset_ext == "vcf": | 910 elif dataset_ext == "vcf": |
712 self.add_vcf(dataset_path, outputTrackConfig) | 911 self.add_vcf(dataset_path, outputTrackConfig) |
713 else: | 912 else: |
714 log.warn("Do not know how to handle %s", dataset_ext) | 913 log.warn("Do not know how to handle %s", dataset_ext) |
715 | 914 |
716 def clone_jbrowse(self, jbrowse_dir, destination, minimal=False): | 915 def clone_jbrowse(self, jbrowse_dir, destination): |
717 """Clone a JBrowse directory into a destination directory.""" | 916 """Clone a JBrowse directory into a destination directory.""" |
718 cmd = ["jbrowse", "create", "-f", self.outdir] | 917 cmd = ["jbrowse", "create", "-f", self.outdir] |
719 self.subprocess_check_call(cmd) | 918 self.subprocess_check_call(cmd) |
720 for fn in [ | 919 for fn in [ |
721 "asset-manifest.json", | 920 "asset-manifest.json", |
840 jc.trackIdlist, | 1039 jc.trackIdlist, |
841 "config=", | 1040 "config=", |
842 str(jc.config_json), | 1041 str(jc.config_json), |
843 ) | 1042 ) |
844 jc.config_json["tracks"] = jc.tracksToAdd | 1043 jc.config_json["tracks"] = jc.tracksToAdd |
845 jc.write_config() | 1044 if jc.usejson: |
1045 jc.write_config() | |
846 jc.add_default_view() | 1046 jc.add_default_view() |