comparison jbrowse2.py @ 99:990291e918c7 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit a1537aea75fc902d0e38c0b7c698830a939648b1-dirty
author fubar
date Fri, 21 Jun 2024 23:34:31 +0000
parents b1260bca5fdc
children e4ba5f1da6ef
comparison
equal deleted inserted replaced
98:b1260bca5fdc 99:990291e918c7
18 from collections import defaultdict 18 from collections import defaultdict
19 19
20 logging.basicConfig(level=logging.DEBUG) 20 logging.basicConfig(level=logging.DEBUG)
21 log = logging.getLogger("jbrowse") 21 log = logging.getLogger("jbrowse")
22 22
23 JB2VER = "v2.11.0" 23 JB2VER = "v2.11.1"
24 # version pinned if cloning - but not used until now 24 # version pinned if cloning - but not cloning now
25 logCommands = True 25 logCommands = True
26 # useful for seeing what's being written but not for production setups 26 # useful for seeing what's being written but not for production setups
27 TODAY = datetime.datetime.now().strftime("%Y-%m-%d") 27 TODAY = datetime.datetime.now().strftime("%Y-%m-%d")
28 SELF_LOCATION = os.path.dirname(os.path.realpath(__file__)) 28 SELF_LOCATION = os.path.dirname(os.path.realpath(__file__))
29 GALAXY_INFRASTRUCTURE_URL = None 29 GALAXY_INFRASTRUCTURE_URL = None
453 retcode = p.returncode 453 retcode = p.returncode
454 if retcode != 0: 454 if retcode != 0:
455 log.error(command) 455 log.error(command)
456 log.error(output) 456 log.error(output)
457 log.error(err) 457 log.error(err)
458 raise RuntimeError(f"Command ( {command} ) failed with exit code {retcode}") 458 raise RuntimeError("Command failed with exit code %s" % (retcode))
459 459
460 def subprocess_check_output(self, command): 460 def subprocess_check_output(self, command):
461 if logCommands: 461 if logCommands:
462 log.debug(" ".join(command)) 462 log.debug(" ".join(command))
463 return subprocess.check_output(command, cwd=self.outdir) 463 return subprocess.check_output(command, cwd=self.outdir)
696 "url": "https://unpkg.com/jbrowse-plugin-mafviewer/dist/jbrowse-plugin-mafviewer.umd.production.min.js", 696 "url": "https://unpkg.com/jbrowse-plugin-mafviewer/dist/jbrowse-plugin-mafviewer.umd.production.min.js",
697 } 697 }
698 ] 698 ]
699 } 699 }
700 categ = trackData["category"] 700 categ = trackData["category"]
701 fname = f"{tId}" 701 fname = tId
702 dest = os.path.join(self.outdir, fname) 702 dest = "%s/%s" % (self.outdir, fname)
703 gname = trackData["assemblyNames"] 703 gname = trackData["assemblyNames"]
704 704
705 cmd = [ 705 cmd = [
706 "bash", 706 "bash",
707 os.path.join(INSTALLED_TO, "convertMAF.sh"), 707 os.path.join(INSTALLED_TO, "convertMAF.sh"),
1196 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict) 1196 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict)
1197 self.trackIdlist.append(tId) 1197 self.trackIdlist.append(tId)
1198 1198
1199 def process_annotations(self, track): 1199 def process_annotations(self, track):
1200 category = track["category"].replace("__pd__date__pd__", TODAY) 1200 category = track["category"].replace("__pd__date__pd__", TODAY)
1201 tt1 = ",/ :;\\"
1202 tt2 = "______"
1203 labttab = str.maketrans(tt1,tt2)
1201 for trackIndex, ( 1204 for trackIndex, (
1202 dataset_path, 1205 dataset_path,
1203 dataset_ext, 1206 dataset_ext,
1204 useuri, 1207 useuri,
1205 track_human_label, 1208 track_human_label,
1207 ) in enumerate(track["trackfiles"]): 1210 ) in enumerate(track["trackfiles"]):
1208 if not dataset_path.strip().startswith("http"): 1211 if not dataset_path.strip().startswith("http"):
1209 # Unsanitize labels (element_identifiers are always sanitized by Galaxy) 1212 # Unsanitize labels (element_identifiers are always sanitized by Galaxy)
1210 for key, value in mapped_chars.items(): 1213 for key, value in mapped_chars.items():
1211 track_human_label = track_human_label.replace(value, key) 1214 track_human_label = track_human_label.replace(value, key)
1212 track_human_label = track_human_label.replace(" ", "_") 1215 track_human_label = track_human_label.translate(labttab)
1213 outputTrackConfig = { 1216 outputTrackConfig = {
1214 "category": category, 1217 "category": category,
1215 "style": {}, 1218 "style": {},
1216 } 1219 }
1217
1218 # hashData = [
1219 # str(dataset_path),
1220 # track_human_label,
1221 # track["category"],
1222 # ]
1223 # hashData = "|".join(hashData).encode("utf-8")
1224 # hash_string = hashlib.md5(hashData).hexdigest()
1225 1220
1226 outputTrackConfig["assemblyNames"] = track["assemblyNames"] 1221 outputTrackConfig["assemblyNames"] = track["assemblyNames"]
1227 outputTrackConfig["key"] = track_human_label 1222 outputTrackConfig["key"] = track_human_label
1228 outputTrackConfig["useuri"] = useuri 1223 outputTrackConfig["useuri"] = useuri
1229 outputTrackConfig["path"] = dataset_path 1224 outputTrackConfig["path"] = dataset_path
1230 outputTrackConfig["ext"] = dataset_ext 1225 outputTrackConfig["ext"] = dataset_ext
1231 outputTrackConfig["trackset"] = track.get("trackset", {}) 1226 outputTrackConfig["trackset"] = track.get("trackset", {})
1232 outputTrackConfig["label"] = track["label"] 1227 outputTrackConfig["label"] = track["label"]
1233 # outputTrackConfig["label"] = "%s_%i_%s_%s" % (
1234 # dataset_ext,
1235 # trackIndex,
1236 # track_human_label,
1237 # hash_string,
1238 # )
1239
1240 outputTrackConfig["metadata"] = extra_metadata 1228 outputTrackConfig["metadata"] = extra_metadata
1241 outputTrackConfig["name"] = track_human_label 1229 outputTrackConfig["name"] = track_human_label
1242 if track["label"] in self.trackIdlist: 1230 if track["label"] in self.trackIdlist:
1243 logging.error( 1231 logging.error(
1244 "### not adding %s already in %s" 1232 "### not adding %s already in %s"
1329 default session settings are hard and fragile. 1317 default session settings are hard and fragile.
1330 .add_default_view() and other configuration code adapted from 1318 .add_default_view() and other configuration code adapted from
1331 https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py 1319 https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py
1332 """ 1320 """
1333 # TODO using the default session for now, but check out session specs in the future https://github.com/GMOD/jbrowse-components/issues/2708 1321 # TODO using the default session for now, but check out session specs in the future https://github.com/GMOD/jbrowse-components/issues/2708
1322 bpPerPx = 50 # this is tricky since browser window width is unknown - this seems a compromise that sort of works....
1334 track_types = {} 1323 track_types = {}
1335 with open(self.config_json_file, "r") as config_file: 1324 with open(self.config_json_file, "r") as config_file:
1336 config_json = json.load(config_file) 1325 config_json = json.load(config_file)
1337 if self.config_json: 1326 if self.config_json:
1338 config_json.update(self.config_json) 1327 config_json.update(self.config_json)
1367 "type": track_types[tId], 1356 "type": track_types[tId],
1368 "configuration": tId, 1357 "configuration": tId,
1369 "displays": [style_data], 1358 "displays": [style_data],
1370 } 1359 }
1371 ) 1360 )
1372 view_json = {
1373 "type": "LinearGenomeView",
1374 "offsetPx": 0,
1375 "minimized": False,
1376 "tracks": tracks_data,
1377 }
1378 first = [x for x in self.ass_first_contigs if x[0] == gnome] 1361 first = [x for x in self.ass_first_contigs if x[0] == gnome]
1379 if len(first) > 0: 1362 drdict = {
1380 [gnome, refName, end] = first[0]
1381 start = 0
1382 end = int(end)
1383 drdict = {
1384 "refName": refName,
1385 "start": start,
1386 "end": end,
1387 "reversed": False, 1363 "reversed": False,
1388 "assemblyName": gnome, 1364 "assemblyName": gnome,
1389 } 1365 }
1366 if len(first) > 0:
1367 [gnome, refName, end] = first[0]
1368 drdict["refName"] = refName
1369 drdict["start"] = 0
1370 end = int(end)
1371 drdict["end"] = end
1390 else: 1372 else:
1391 ddl = default_data.get("defaultLocation", None) 1373 ddl = default_data.get("defaultLocation", None)
1392 if ddl: 1374 if ddl:
1393 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) 1375 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl)
1394 # allow commas like 100,000 but ignore as integer 1376 # allow commas like 100,000 but ignore as integer
1402 else: 1384 else:
1403 logging.info( 1385 logging.info(
1404 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix" 1386 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix"
1405 % ddl 1387 % ddl
1406 ) 1388 )
1389 view_json = {
1390 "type": "LinearGenomeView",
1391 "offsetPx": 0,
1392 "bpPerPx" : bpPerPx,
1393 "minimized": False,
1394 "tracks": tracks_data
1395 }
1407 if drdict.get("refName", None): 1396 if drdict.get("refName", None):
1408 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome 1397 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome
1409 view_json["displayedRegions"] = [ 1398 view_json["displayedRegions"] = [
1410 drdict, 1399 drdict,
1411 ] 1400 ]
1626 1615
1627 trackfiles = track.findall("files/trackFile") 1616 trackfiles = track.findall("files/trackFile")
1628 if trackfiles: 1617 if trackfiles:
1629 for x in trackfiles: 1618 for x in trackfiles:
1630 track_conf["label"] = "%s_%d" % ( 1619 track_conf["label"] = "%s_%d" % (
1631 x.attrib["label"].replace(" ", "_").replace(",", ""), 1620 x.attrib["label"].replace(" ", "_").replace(",", "_").replace("/","_"),
1632 trackI, 1621 trackI,
1633 ) 1622 )
1634 trackI += 1 1623 trackI += 1
1635 track_conf["useuri"] = x.attrib["useuri"] 1624 track_conf["useuri"] = x.attrib["useuri"]
1636 if is_multi_bigwig: 1625 if is_multi_bigwig: