comparison jbrowse2.py @ 61:e7a6f7a7148d draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 6dde5ad41d63730085116ab2c9a9d3e500a760e4-dirty
author fubar
date Tue, 26 Mar 2024 00:52:34 +0000
parents 81d535970196
children ab0d6782a95f
comparison
equal deleted inserted replaced
60:81d535970196 61:e7a6f7a7148d
440 wstyle = { 440 wstyle = {
441 "displays": [ 441 "displays": [
442 style_data, 442 style_data,
443 ] 443 ]
444 } 444 }
445 logging.warn("style=%s" % (wstyle))
446 return wstyle 445 return wstyle
447 446
448 def process_genomes(self): 447 def process_genomes(self):
449 assemblies = [] 448 assemblies = []
450 useuri = False 449 useuri = False
608 uri: 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.fai', 607 uri: 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.fai',
609 gziLocation: 608 gziLocation:
610 uri: 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.gzi', 609 uri: 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.gzi',
611 Cool will not be likely to be a good fit - see discussion at https://github.com/GMOD/jbrowse-components/issues/2438 610 Cool will not be likely to be a good fit - see discussion at https://github.com/GMOD/jbrowse-components/issues/2438
612 611
613
614 """ 612 """
615 tId = trackData["label"] 613 tId = trackData["label"]
616 # can be served - if public. 614 # can be served - if public.
617 # dsId = trackData["metadata"]["dataset_id"] 615 # dsId = trackData["metadata"]["dataset_id"]
618 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId) 616 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId)
617 hic_path = trackData.get("hic_path", None)
619 useuri = trackData["useuri"].lower() == "yes" 618 useuri = trackData["useuri"].lower() == "yes"
620 if useuri: 619 if useuri:
621 uri = data 620 uri = data
622 else: 621 else:
623 uri = "%s.hic" % trackData["label"] 622 uri = "%s.hic" % trackData["label"]
657 "url": "https://unpkg.com/jbrowse-plugin-mafviewer/dist/jbrowse-plugin-mafviewer.umd.production.min.js", 656 "url": "https://unpkg.com/jbrowse-plugin-mafviewer/dist/jbrowse-plugin-mafviewer.umd.production.min.js",
658 } 657 }
659 ] 658 ]
660 } 659 }
661 categ = trackData["category"] 660 categ = trackData["category"]
662 fname = "%s.bed" % tId 661 fname = "%s" % tId
663 dest = "%s/%s" % (self.outdir, fname) 662 dest = "%s/%s" % (self.outdir, fname)
664 gname = self.genome_name 663 gname = self.genome_name
664
665 cmd = [ 665 cmd = [
666 "bash", 666 "bash",
667 os.path.join(INSTALLED_TO, "convertMAF.sh"), 667 os.path.join(INSTALLED_TO, "convertMAF.sh"),
668 data, 668 data,
669 gname, 669 gname,
670 INSTALLED_TO, 670 INSTALLED_TO,
671 dest, 671 dest,
672 ] 672 ]
673 self.subprocess_check_call(cmd) 673 self.subprocess_check_call(cmd)
674 # Construct samples list 674 mafs = open(data,'r').readlines()
675 # We could get this from galaxy metadata, not sure how easily. 675 mafss = [x for x in mafs if (x.startswith('s\t') or x.startswith('s '))]
676 ps = subprocess.Popen(["grep", "^s [^ ]*", "-o", data], stdout=subprocess.PIPE) 676 samp = [x.split()[1] for x in mafss if len(x.split()) > 0]
677 output = subprocess.check_output(("sort", "-u"), stdin=ps.stdout) 677 sampu = list(dict.fromkeys(samp))
678 ps.wait() 678 samples = [x.split('.')[0] for x in sampu]
679 outp = output.decode("ascii") 679 samples.sort()
680 soutp = outp.split("\n") 680 logging.warn("$$$$ cmd=%s, mafss=%s samp=%s samples=%s" % (' '.join(cmd), mafss, samp, samples))
681 samp = [x.split("s ")[1] for x in soutp if x.startswith("s ")]
682 samples = [x.split(".")[0] for x in samp]
683 logging.warn("### maf convert cmd = %s,\nsamples=%s" % (' '.join(cmd), samples))
684 trackDict = { 681 trackDict = {
685 "type": "MafTrack", 682 "type": "MafTrack",
686 "trackId": tId, 683 "trackId": tId,
687 "name": trackData["name"], 684 "name": trackData["name"],
688 "category": [ 685 "category": [
702 }, 699 },
703 "assemblyNames": [self.genome_name], 700 "assemblyNames": [self.genome_name],
704 "displays": [ 701 "displays": [
705 { 702 {
706 "type": "LinearBasicDisplay", 703 "type": "LinearBasicDisplay",
707 "displayId": "%s-LinearBasicDisplay" % tId, 704 "displayId": "%s-LinearBasicDisplay" % tId
708 }, 705 },
709 { 706 {
710 "type": "LinearArcDisplay", 707 "type": "LinearArcDisplay",
711 "displayId": "%s-LinearArcDisplay" % tId, 708 "displayId": "%s-LinearArcDisplay" % tId
712 }, 709 },
713 ], 710 ]
714 } 711 }
715 style_json = self._prepare_track_style(trackDict) 712 style_json = self._prepare_track_style(trackDict)
716 trackDict["style"] = style_json 713 trackDict["style"] = style_json
717 self.tracksToAdd.append(trackDict) 714 self.tracksToAdd.append(trackDict)
718 self.trackIdlist.append(tId) 715 self.trackIdlist.append(tId)
1108 tId = trackData["label"] 1105 tId = trackData["label"]
1109 categ = trackData["category"] 1106 categ = trackData["category"]
1110 pgnames = [x.strip() for x in pafOpts["genome_label"].split(",") if len(x.strip()) > 0] 1107 pgnames = [x.strip() for x in pafOpts["genome_label"].split(",") if len(x.strip()) > 0]
1111 pgpaths = [x.strip() for x in pafOpts["genome"].split(",") if len(x.strip()) > 0] 1108 pgpaths = [x.strip() for x in pafOpts["genome"].split(",") if len(x.strip()) > 0]
1112 passnames = [self.genome_name] # always first 1109 passnames = [self.genome_name] # always first
1113 logging.warn("### add_paf got pafOpts=%s, pgnames=%s, pgpaths=%s for %s" % (pafOpts, pgnames, pgpaths, tId)) 1110 logging.debug("### add_paf got pafOpts=%s, pgnames=%s, pgpaths=%s for %s" % (pafOpts, pgnames, pgpaths, tId))
1114 for i, gname in enumerate(pgnames): 1111 for i, gname in enumerate(pgnames):
1115 if len(gname.split()) > 1: 1112 if len(gname.split()) > 1:
1116 gname = gname.split()[0] 1113 gname = gname.split()[0]
1117 passnames.append(gname) 1114 passnames.append(gname)
1118 # trouble from spacey names in command lines avoidance 1115 # trouble from spacey names in command lines avoidance
1200 self.add_hic( 1197 self.add_hic(
1201 dataset_path, 1198 dataset_path,
1202 outputTrackConfig, 1199 outputTrackConfig,
1203 ) 1200 )
1204 elif dataset_ext in ("cool", "mcool", "scool"): 1201 elif dataset_ext in ("cool", "mcool", "scool"):
1205 hic_url = "%s_%d.juicebox_hic" % (track_human_label, i) 1202 hic_url = "%s_%d.hic" % (track_human_label, i)
1206 hic_path = os.path.join(self.outdir, hic_url) 1203 hic_path = os.path.join(self.outdir, hic_url)
1207 self.subprocess_check_call( 1204 self.subprocess_check_call(
1208 [ 1205 [
1209 "hictk", 1206 "hictk",
1210 "convert", 1207 "convert",
1213 "hic", 1210 "hic",
1214 dataset_path, 1211 dataset_path,
1215 hic_path, 1212 hic_path,
1216 ] 1213 ]
1217 ) 1214 )
1218 outputTrackConfig["hic_url"] = hic_url
1219 self.add_hic( 1215 self.add_hic(
1220 hic_path, 1216 hic_url,
1221 outputTrackConfig, 1217 outputTrackConfig,
1222 ) 1218 )
1223 elif dataset_ext in ("bed",): 1219 elif dataset_ext in ("bed",):
1224 self.add_bed( 1220 self.add_bed(
1225 dataset_path, 1221 dataset_path,
1303 "displays": [style_data], 1299 "displays": [style_data],
1304 } 1300 }
1305 ) 1301 )
1306 # The view for the assembly we're adding 1302 # The view for the assembly we're adding
1307 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} 1303 view_json = {"type": "LinearGenomeView", "tracks": tracks_data}
1308 logging.warn("### view_json=%s" % view_json)
1309 refName = None 1304 refName = None
1310 drdict = { 1305 drdict = {
1311 "reversed": False, 1306 "reversed": False,
1312 "assemblyName": self.genome_name, 1307 "assemblyName": self.genome_name,
1313 "start": 1, 1308 "start": 1,
1396 config_json["configuration"].update(config_data) 1391 config_json["configuration"].update(config_data)
1397 self.config_json.update(config_json) 1392 self.config_json.update(config_json)
1398 with open(config_path, "w") as config_file: 1393 with open(config_path, "w") as config_file:
1399 json.dump(self.config_json, config_file, indent=2) 1394 json.dump(self.config_json, config_file, indent=2)
1400 1395
1401 def clone_jbrowse(self, realclone=False): 1396 def clone_jbrowse(self, realclone=True):
1402 """Clone a JBrowse directory into a destination directory. This also works in Biocontainer testing now 1397 """Clone a JBrowse directory into a destination directory. This also works in Biocontainer testing now
1403 Leave as True between version updates on temporary tools - requires manual conda trigger :( 1398 Leave as True between version updates on temporary tools - requires manual conda trigger :(
1404 """ 1399 """
1405 dest = self.outdir 1400 dest = self.outdir
1406 if realclone: 1401 if realclone:
1548 ].append(key) 1543 ].append(key)
1549 if track.find("options/style"): 1544 if track.find("options/style"):
1550 default_session_data["style"][key] = { 1545 default_session_data["style"][key] = {
1551 item.tag: parse_style_conf(item) for item in track.find("options/style") 1546 item.tag: parse_style_conf(item) for item in track.find("options/style")
1552 } 1547 }
1553 logging.warn("### added %s to defsess %s for %s" % (trackkey, default_session_data, key ))
1554 else: 1548 else:
1555 default_session_data["style"][key] = {} 1549 default_session_data["style"][key] = {}
1556 logging.warn("@@@@ no options/style found for %s" % (key)) 1550 logging.warn("@@@@ no options/style found for %s" % (key))
1557 1551
1558 if track.find("options/style_labels"): 1552 if track.find("options/style_labels"):
1564 "metadata/general/defaultLocation" 1558 "metadata/general/defaultLocation"
1565 ).text 1559 ).text
1566 default_session_data["session_name"] = root.find( 1560 default_session_data["session_name"] = root.find(
1567 "metadata/general/session_name" 1561 "metadata/general/session_name"
1568 ).text 1562 ).text
1569 logging.warn("default_session=%s" % (default_session_data)) 1563 logging.debug("default_session=%s" % (default_session_data))
1570 jc.zipOut = root.find("metadata/general/zipOut").text == "true" 1564 jc.zipOut = root.find("metadata/general/zipOut").text == "true"
1571 general_data = { 1565 general_data = {
1572 "analytics": root.find("metadata/general/analytics").text, 1566 "analytics": root.find("metadata/general/analytics").text,
1573 "primary_color": root.find("metadata/general/primary_color").text, 1567 "primary_color": root.find("metadata/general/primary_color").text,
1574 "secondary_color": root.find("metadata/general/secondary_color").text, 1568 "secondary_color": root.find("metadata/general/secondary_color").text,