Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 112:56f9a6e0fe80 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 566509061b742b73c8dd1a1db6813fbf6a7a3792
| author | bgruening |
|---|---|
| date | Thu, 04 Jul 2024 08:40:21 +0000 |
| parents | c017111e976a |
| children | 794aecef8327 |
comparison
equal
deleted
inserted
replaced
| 111:0a532764dcfa | 112:56f9a6e0fe80 |
|---|---|
| 705 } | 705 } |
| 706 ] | 706 ] |
| 707 } | 707 } |
| 708 categ = trackData["category"] | 708 categ = trackData["category"] |
| 709 fname = tId | 709 fname = tId |
| 710 dest = "%s/%s" % (self.outdir, fname) | 710 dest = os.path.join(self.outdir, fname) |
| 711 gname = trackData["assemblyNames"] | 711 gname = trackData["assemblyNames"] |
| 712 | 712 |
| 713 cmd = [ | 713 cmd = [ |
| 714 "bash", | 714 "bash", |
| 715 os.path.join(INSTALLED_TO, "convertMAF.sh"), | 715 os.path.join(INSTALLED_TO, "convertMAF.sh"), |
| 1072 trackDict["style"] = style_json | 1072 trackDict["style"] = style_json |
| 1073 self.tracksToAdd[trackData["assemblyNames"]].append(copy.copy(trackDict)) | 1073 self.tracksToAdd[trackData["assemblyNames"]].append(copy.copy(trackDict)) |
| 1074 self.trackIdlist.append(tId) | 1074 self.trackIdlist.append(tId) |
| 1075 | 1075 |
| 1076 def add_bed(self, data, ext, trackData): | 1076 def add_bed(self, data, ext, trackData): |
| 1077 bedPlugin = {"name": "BedScorePlugin", "umdLoc": { "uri": "bedscoreplugin.js" } } | 1077 bedPlugin = {"name": "BedScorePlugin", "umdLoc": {"uri": "bedscoreplugin.js"}} |
| 1078 tId = trackData["label"] | 1078 tId = trackData["label"] |
| 1079 categ = trackData["category"] | 1079 categ = trackData["category"] |
| 1080 useuri = trackData["useuri"].lower() == "yes" | 1080 useuri = trackData["useuri"].lower() == "yes" |
| 1081 if useuri: | 1081 if useuri: |
| 1082 url = data | 1082 url = data |
| 1083 else: | 1083 else: |
| 1084 url = tId + ".gz" | 1084 url = tId + ".gz" |
| 1085 dest = os.path.join(self.outdir, url) | 1085 dest = os.path.join(self.outdir, url) |
| 1086 self._sort_bed(data, dest) | 1086 self._sort_bed(data, dest) |
| 1087 if True or trackData.get("usebedscore",None): | 1087 if True or trackData.get("usebedscore", None): |
| 1088 bedgzlocation = { | 1088 bedgzlocation = { |
| 1089 "uri": url, | 1089 "uri": url, |
| 1090 "columnNames": ["chr","start","end","name","score"], | 1090 "columnNames": ["chr", "start", "end", "name", "score"], |
| 1091 "scoreColumn": "score", | 1091 "scoreColumn": "score", |
| 1092 } | 1092 } |
| 1093 else: | 1093 else: |
| 1094 bedgzlocation = { | 1094 bedgzlocation = { |
| 1095 "uri": url, | 1095 "uri": url, |
| 1096 } | 1096 } |
| 1097 trackDict = { | 1097 trackDict = { |
| 1098 "type": "FeatureTrack", | 1098 "type": "FeatureTrack", |
| 1099 "trackId": tId, | 1099 "trackId": tId, |
| 1100 "name": trackData["name"], | 1100 "name": trackData["name"], |
| 1101 "assemblyNames": [trackData["assemblyNames"]], | 1101 "assemblyNames": [trackData["assemblyNames"]], |
| 1116 "type": "LinearBasicDisplay", | 1116 "type": "LinearBasicDisplay", |
| 1117 "displayId": "%s-LinearBasicDisplay" % tId, | 1117 "displayId": "%s-LinearBasicDisplay" % tId, |
| 1118 "renderer": { | 1118 "renderer": { |
| 1119 "type": "SvgFeatureRenderer", | 1119 "type": "SvgFeatureRenderer", |
| 1120 "color1": "jexl:customColor(feature)", | 1120 "color1": "jexl:customColor(feature)", |
| 1121 }, | 1121 }, |
| 1122 }, | 1122 }, |
| 1123 { | 1123 { |
| 1124 "type": "LinearPileupDisplay", | 1124 "type": "LinearPileupDisplay", |
| 1125 "displayId": "%s-LinearPileupDisplay" % tId, | 1125 "displayId": "%s-LinearPileupDisplay" % tId, |
| 1126 }, | 1126 }, |
| 1169 passnames.append(gname) | 1169 passnames.append(gname) |
| 1170 useuri = pafOpts["useuri"] == "true" | 1170 useuri = pafOpts["useuri"] == "true" |
| 1171 if gname not in self.genome_names: | 1171 if gname not in self.genome_names: |
| 1172 # ignore if already there - eg for duplicates among pafs. | 1172 # ignore if already there - eg for duplicates among pafs. |
| 1173 asstrack, first_contig = self.make_assembly(gpath, gname, useuri) | 1173 asstrack, first_contig = self.make_assembly(gpath, gname, useuri) |
| 1174 self.genome_names.append(copy.copy(gname)) | 1174 self.genome_names.append(gname) |
| 1175 self.tracksToAdd[gname] = [] | 1175 self.tracksToAdd[gname] = [] |
| 1176 self.assemblies.append(copy.copy(asstrack)) | 1176 self.assemblies.append(copy.copy(asstrack)) |
| 1177 self.ass_first_contigs.append(copy.copy(first_contig)) | 1177 self.ass_first_contigs.append(copy.copy(first_contig)) |
| 1178 trackDict = { | 1178 trackDict = { |
| 1179 "type": "SyntenyTrack", | 1179 "type": "SyntenyTrack", |
| 1223 | 1223 |
| 1224 def process_annotations(self, track): | 1224 def process_annotations(self, track): |
| 1225 category = track["category"].replace("__pd__date__pd__", TODAY) | 1225 category = track["category"].replace("__pd__date__pd__", TODAY) |
| 1226 tt1 = ",/ :;\\" | 1226 tt1 = ",/ :;\\" |
| 1227 tt2 = "______" | 1227 tt2 = "______" |
| 1228 labttab = str.maketrans(tt1,tt2) | 1228 labttab = str.maketrans(tt1, tt2) |
| 1229 for trackIndex, ( | 1229 for trackIndex, ( |
| 1230 dataset_path, | 1230 dataset_path, |
| 1231 dataset_ext, | 1231 dataset_ext, |
| 1232 useuri, | 1232 useuri, |
| 1233 track_human_label, | 1233 track_human_label, |
| 1333 track["conf"]["options"]["paf"], | 1333 track["conf"]["options"]["paf"], |
| 1334 ) | 1334 ) |
| 1335 else: | 1335 else: |
| 1336 logging.warning("Do not know how to handle %s", dataset_ext) | 1336 logging.warning("Do not know how to handle %s", dataset_ext) |
| 1337 # Return non-human label for use in other fields | 1337 # Return non-human label for use in other fields |
| 1338 logging.debug("### processanno ext=%s trackstoadd = %s" % (dataset_ext, self.tracksToAdd)) | |
| 1339 yield outputTrackConfig["label"] | 1338 yield outputTrackConfig["label"] |
| 1340 | 1339 |
| 1341 def add_default_session(self, default_data): | 1340 def add_default_session(self, default_data): |
| 1342 """ | 1341 """ |
| 1343 default session settings are hard and fragile. | 1342 default session settings are hard and fragile. |
| 1344 .add_default_view() and other configuration code adapted from | 1343 .add_default_view() and other configuration code adapted from |
| 1345 https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py | 1344 https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py |
| 1346 """ | 1345 """ |
| 1347 # TODO using the default session for now, but check out session specs in the future https://github.com/GMOD/jbrowse-components/issues/2708 | 1346 # TODO using the default session for now, but check out session specs in the future https://github.com/GMOD/jbrowse-components/issues/2708 |
| 1348 bpPerPx = self.bpPerPx # Browser window width is unknown and default session cannot be used to figure it out in JB2 code so could be 200-2000+ pixels. | 1347 bpPerPx = self.bpPerPx # Browser window width is unknown and default session cannot be used to figure it out in JB2 code so could be 200-2000+ pixels. |
| 1349 track_types = {} | 1348 track_types = {} |
| 1350 with open(self.config_json_file, "r") as config_file: | 1349 with open(self.config_json_file, "r") as config_file: |
| 1351 config_json = json.load(config_file) | 1350 config_json = json.load(config_file) |
| 1352 if self.config_json: | 1351 if self.config_json: |
| 1353 config_json.update(self.config_json) | 1352 config_json.update(self.config_json) |
| 1372 else: | 1371 else: |
| 1373 logging.debug( | 1372 logging.debug( |
| 1374 "style data for %s = %s" | 1373 "style data for %s = %s" |
| 1375 % (tId, style_data) | 1374 % (tId, style_data) |
| 1376 ) | 1375 ) |
| 1377 if style_data.get('type',None) == None: | 1376 if style_data.get('type', None) is None: |
| 1378 style_data["type"] = "LinearBasicDisplay" | 1377 style_data["type"] = "LinearBasicDisplay" |
| 1379 if "displays" in track_conf: | 1378 if "displays" in track_conf: |
| 1380 disp = track_conf["displays"][0]["type"] | 1379 disp = track_conf["displays"][0]["type"] |
| 1381 style_data["type"] = disp | 1380 style_data["type"] = disp |
| 1382 if track_conf.get("displays", None): | 1381 if track_conf.get("displays", None): |
| 1394 "displays": [style_data], | 1393 "displays": [style_data], |
| 1395 } | 1394 } |
| 1396 ) | 1395 ) |
| 1397 first = [x for x in self.ass_first_contigs if x[0] == gnome] | 1396 first = [x for x in self.ass_first_contigs if x[0] == gnome] |
| 1398 drdict = { | 1397 drdict = { |
| 1399 "reversed": False, | 1398 "reversed": False, |
| 1400 "assemblyName": gnome, | 1399 "assemblyName": gnome, |
| 1401 } | 1400 } |
| 1402 if len(first) > 0: | 1401 if len(first) > 0: |
| 1403 [gnome, refName, end] = first[0] | 1402 [gnome, refName, end] = first[0] |
| 1404 drdict["refName"] = refName | 1403 drdict["refName"] = refName |
| 1405 drdict["start"] = 0 | 1404 drdict["start"] = 0 |
| 1406 end = int(end) | 1405 end = int(end) |
| 1407 drdict["end"] = end | 1406 drdict["end"] = end |
| 1408 else: | 1407 else: |
| 1409 ddl = default_data.get("defaultLocation", None) | 1408 ddl = default_data.get("defaultLocation", None) |
| 1410 if ddl: | 1409 if ddl: |
| 1411 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) | 1410 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) |
| 1412 # allow commas like 100,000 but ignore as integer | 1411 # allow commas like 100,000 but ignore as integer |
| 1413 if loc_match: | 1412 if loc_match: |
| 1414 refName = loc_match.group(1) | 1413 refName = loc_match.group(1) |
| 1415 drdict["refName"] = refName | 1414 drdict["refName"] = refName |
| 1416 if loc_match.group(2) > "": | 1415 if loc_match.group(2) > "": |
| 1417 drdict["start"] = int(loc_match.group(2).replace(",", "")) | 1416 drdict["start"] = int(loc_match.group(2).replace(",", "")) |
| 1423 % ddl | 1422 % ddl |
| 1424 ) | 1423 ) |
| 1425 view_json = { | 1424 view_json = { |
| 1426 "type": "LinearGenomeView", | 1425 "type": "LinearGenomeView", |
| 1427 "offsetPx": 0, | 1426 "offsetPx": 0, |
| 1428 "bpPerPx" : bpPerPx, | 1427 "bpPerPx": bpPerPx, |
| 1429 "minimized": False, | 1428 "minimized": False, |
| 1430 "tracks": tracks_data | 1429 "tracks": tracks_data |
| 1431 } | 1430 } |
| 1432 if drdict.get("refName", None): | 1431 if drdict.get("refName", None): |
| 1433 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome | 1432 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome |
| 1654 trackfiles = track.findall("files/trackFile") | 1653 trackfiles = track.findall("files/trackFile") |
| 1655 if trackfiles: | 1654 if trackfiles: |
| 1656 for x in trackfiles: | 1655 for x in trackfiles: |
| 1657 isBed = False | 1656 isBed = False |
| 1658 if x.attrib['ext'] == "bed": | 1657 if x.attrib['ext'] == "bed": |
| 1659 isBed = True | 1658 isBed = True |
| 1660 track_conf["label"] = "%s_%d" % ( | 1659 track_conf["label"] = "%s_%d" % ( |
| 1661 x.attrib["label"].replace(" ", "_").replace(",", "_").replace("/","_"), | 1660 x.attrib["label"].replace(" ", "_").replace(",", "_").replace("/", "_"), |
| 1662 trackI, | 1661 trackI, |
| 1663 ) | 1662 ) |
| 1664 trackI += 1 | 1663 trackI += 1 |
| 1665 track_conf["useuri"] = x.attrib["useuri"] | 1664 track_conf["useuri"] = x.attrib["useuri"] |
| 1666 if is_multi_bigwig: | 1665 if is_multi_bigwig: |
