comparison jbrowse2.py @ 78:7bb6259ea52f draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit d03454f949af9f3fff638f6a3e52fe42bc96be3b-dirty
author fubar
date Mon, 01 Apr 2024 05:40:29 +0000
parents 9e3eb6b26f85
children 14ecbe46ae9f
comparison
equal deleted inserted replaced
77:3dcda36b97b4 78:7bb6259ea52f
401 401
402 class JbrowseConnector(object): 402 class JbrowseConnector(object):
403 def __init__(self, outdir, jbrowse2path): 403 def __init__(self, outdir, jbrowse2path):
404 self.assemblies = [] # these require more than a few line diff. 404 self.assemblies = [] # these require more than a few line diff.
405 self.assmeta = {} 405 self.assmeta = {}
406 self.ass_first_contigs = ( 406 self.ass_first_contigs = [] # for default session - these are read as first line of the assembly .fai
407 []
408 ) # for default session - these are read as first line of the assembly .fai
409 self.giURL = GALAXY_INFRASTRUCTURE_URL 407 self.giURL = GALAXY_INFRASTRUCTURE_URL
410 self.outdir = outdir 408 self.outdir = outdir
411 self.jbrowse2path = jbrowse2path 409 self.jbrowse2path = jbrowse2path
412 os.makedirs(self.outdir, exist_ok=True) 410 os.makedirs(self.outdir, exist_ok=True)
413 self.genome_names = [] 411 self.genome_names = []
1370 config_json = json.load(config_file) 1368 config_json = json.load(config_file)
1371 if self.config_json: 1369 if self.config_json:
1372 config_json.update(self.config_json) 1370 config_json.update(self.config_json)
1373 if "defaultSession" in config_json: 1371 if "defaultSession" in config_json:
1374 session_json = config_json["defaultSession"] 1372 session_json = config_json["defaultSession"]
1373 session_views = []
1375 else: 1374 else:
1376 session_json = {} 1375 session_json = {}
1377 session_views = [] 1376 session_views = []
1378 for gnome in self.genome_names: 1377 for gnome in self.genome_names:
1379 tracks_data = [] 1378 tracks_data = []
1402 } 1401 }
1403 ) 1402 )
1404 # paf genomes have no tracks associated so nothing for the view 1403 # paf genomes have no tracks associated so nothing for the view
1405 if len(tracks_data) > 0: 1404 if len(tracks_data) > 0:
1406 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} 1405 view_json = {"type": "LinearGenomeView", "tracks": tracks_data}
1407 refName = self.assmeta[gnome][0].get("genome_firstcontig", None) 1406 logging.debug("Looking for %s in self.ass_ %s" % (gnome, self.ass_first_contigs))
1408 drdict = { 1407 first = [x for x in self.ass_first_contigs if x[0] == gnome]
1409 "reversed": False, 1408 if len(first) > 0:
1410 "assemblyName": gnome, 1409 [gnome, refName, end] = first[0]
1411 "start": 0, 1410 start = 1
1412 "end": 100000, 1411 end = int(end)
1413 "refName": refName, 1412 refName = self.assmeta[gnome][0].get("genome_firstcontig", None)
1414 } 1413 drdict = {
1415 ddl = default_data.get("defaultLocation", None) 1414 "reversed": False,
1416 if ddl: 1415 "assemblyName": gnome,
1417 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) 1416 "start": start,
1418 # allow commas like 100,000 but ignore as integer 1417 "end": end,
1419 if loc_match: 1418 "refName": refName,
1420 refName = loc_match.group(1) 1419 }
1421 drdict["refName"] = refName 1420 else:
1422 if loc_match.group(2) > "": 1421 ddl = default_data.get("defaultLocation", None)
1423 drdict["start"] = int(loc_match.group(2).replace(",", "")) 1422 if ddl:
1424 if loc_match.group(3) > "": 1423 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl)
1425 drdict["end"] = int(loc_match.group(3).replace(",", "")) 1424 # allow commas like 100,000 but ignore as integer
1426 else: 1425 if loc_match:
1427 logging.info( 1426 refName = loc_match.group(1)
1428 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix" 1427 drdict["refName"] = refName
1429 % ddl 1428 if loc_match.group(2) > "":
1430 ) 1429 drdict["start"] = int(loc_match.group(2).replace(",", ""))
1430 if loc_match.group(3) > "":
1431 drdict["end"] = int(loc_match.group(3).replace(",", ""))
1432 else:
1433 logging.info(
1434 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix"
1435 % ddl
1436 )
1431 if drdict.get("refName", None): 1437 if drdict.get("refName", None):
1432 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome 1438 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome
1433 view_json["displayedRegions"] = [ 1439 view_json["displayedRegions"] = [
1434 drdict, 1440 drdict,
1435 ] 1441 ]
1436 logging.info("@@@ defaultlocation %s for default session" % drdict) 1442 logging.info("@@@ defaultlocation %s for default session" % drdict)
1437 else: 1443 else:
1438 logging.info( 1444 logging.info(
1439 "@@@ no contig name found for default session - please add one!" 1445 "@@@ no track location for default session - please add one!"
1440 ) 1446 )
1441 session_views.append(view_json) 1447 session_views.append(view_json)
1442 session_name = default_data.get("session_name", "New session") 1448 session_name = default_data.get("session_name", "New session")
1443 for key, value in mapped_chars.items(): 1449 for key, value in mapped_chars.items():
1444 session_name = session_name.replace(value, key) 1450 session_name = session_name.replace(value, key)
1488 logging.debug("def ass_first=%s\ndata=%s" % (self.ass_first_contigs, data)) 1494 logging.debug("def ass_first=%s\ndata=%s" % (self.ass_first_contigs, data))
1489 for first_contig in self.ass_first_contigs: 1495 for first_contig in self.ass_first_contigs:
1490 logging.debug("first contig=%s" % self.ass_first_contigs) 1496 logging.debug("first contig=%s" % self.ass_first_contigs)
1491 [gnome, refName, end] = first_contig 1497 [gnome, refName, end] = first_contig
1492 start = 0 1498 start = 0
1493 # if False or data.get("defaultLocation", ""):
1494 # loc_match = re.search(
1495 # r"^([^:]+):([\d,]*)\.*([\d,]*)$", data["defaultLocation"]
1496 # )
1497 # # loc_match = re.search(r"^(\w+):(\d+)\.+(\d+)$", data["defaultLocation"])
1498 # if loc_match:
1499 # refName = loc_match.group(1)
1500 # start = int(loc_match.group(2))
1501 # end = int(loc_match.group(3))
1502 # else:
1503 aview = { 1499 aview = {
1504 "assembly": gnome, 1500 "assembly": gnome,
1505 "loc": "{}:{}..{}".format(refName, start, end), 1501 "loc": "{}:{}..{}".format(refName, start, end),
1506 "type": "LinearGenomeView", 1502 "type": "LinearGenomeView",
1507 "tracks": data[gnome]["tracks"], 1503 "tracks": data[gnome]["tracks"],
1750 assconf = jc.config_json.get("assemblies", []) 1746 assconf = jc.config_json.get("assemblies", [])
1751 assconf += jc.assemblies 1747 assconf += jc.assemblies
1752 jc.config_json["assemblies"] = assconf 1748 jc.config_json["assemblies"] = assconf
1753 logging.debug("assemblies=%s, gnames=%s" % (assconf, jc.genome_names)) 1749 logging.debug("assemblies=%s, gnames=%s" % (assconf, jc.genome_names))
1754 jc.write_config() 1750 jc.write_config()
1755 # jc.add_default_session(default_session_data) 1751 jc.add_default_session(default_session_data)
1756 jc.add_defsess_to_index(default_session_data) 1752 jc.add_defsess_to_index(default_session_data)
1757 # jc.text_index() not sure what broke here. 1753 # jc.text_index() not sure what broke here.