Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 79:14ecbe46ae9f 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 09:36:07 +0000 |
| parents | 7bb6259ea52f |
| children | dff27c9f6d72 |
comparison
equal
deleted
inserted
replaced
| 78:7bb6259ea52f | 79:14ecbe46ae9f |
|---|---|
| 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 = [] # for default session - these are read as first line of the assembly .fai | 406 self.ass_first_contigs = ( |
| 407 [] | |
| 408 ) # for default session - these are read as first line of the assembly .fai | |
| 407 self.giURL = GALAXY_INFRASTRUCTURE_URL | 409 self.giURL = GALAXY_INFRASTRUCTURE_URL |
| 408 self.outdir = outdir | 410 self.outdir = outdir |
| 409 self.jbrowse2path = jbrowse2path | 411 self.jbrowse2path = jbrowse2path |
| 410 os.makedirs(self.outdir, exist_ok=True) | 412 os.makedirs(self.outdir, exist_ok=True) |
| 411 self.genome_names = [] | 413 self.genome_names = [] |
| 1400 "displays": [style_data], | 1402 "displays": [style_data], |
| 1401 } | 1403 } |
| 1402 ) | 1404 ) |
| 1403 # paf genomes have no tracks associated so nothing for the view | 1405 # paf genomes have no tracks associated so nothing for the view |
| 1404 if len(tracks_data) > 0: | 1406 if len(tracks_data) > 0: |
| 1405 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} | 1407 view_json = { |
| 1406 logging.debug("Looking for %s in self.ass_ %s" % (gnome, self.ass_first_contigs)) | 1408 "type": "LinearGenomeView", |
| 1409 "offsetPx": 0, | |
| 1410 "minimized": False, | |
| 1411 "tracks": tracks_data, | |
| 1412 } | |
| 1413 logging.debug( | |
| 1414 "Looking for %s in self.ass_ %s" % (gnome, self.ass_first_contigs) | |
| 1415 ) | |
| 1407 first = [x for x in self.ass_first_contigs if x[0] == gnome] | 1416 first = [x for x in self.ass_first_contigs if x[0] == gnome] |
| 1408 if len(first) > 0: | 1417 if len(first) > 0: |
| 1409 [gnome, refName, end] = first[0] | 1418 [gnome, refName, end] = first[0] |
| 1410 start = 1 | 1419 start = 0 |
| 1411 end = int(end) | 1420 end = int(end) |
| 1412 refName = self.assmeta[gnome][0].get("genome_firstcontig", None) | 1421 refName = self.assmeta[gnome][0].get("genome_firstcontig", None) |
| 1413 drdict = { | 1422 drdict = { |
| 1423 "refName": refName, | |
| 1424 "start": start, | |
| 1425 "end": end, | |
| 1414 "reversed": False, | 1426 "reversed": False, |
| 1415 "assemblyName": gnome, | 1427 "assemblyName": gnome, |
| 1416 "start": start, | |
| 1417 "end": end, | |
| 1418 "refName": refName, | |
| 1419 } | 1428 } |
| 1420 else: | 1429 else: |
| 1421 ddl = default_data.get("defaultLocation", None) | 1430 ddl = default_data.get("defaultLocation", None) |
| 1422 if ddl: | 1431 if ddl: |
| 1423 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) | 1432 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", ddl) |
| 1424 # allow commas like 100,000 but ignore as integer | 1433 # allow commas like 100,000 but ignore as integer |
| 1425 if loc_match: | 1434 if loc_match: |
| 1426 refName = loc_match.group(1) | 1435 refName = loc_match.group(1) |
| 1427 drdict["refName"] = refName | 1436 drdict["refName"] = refName |
| 1428 if loc_match.group(2) > "": | 1437 if loc_match.group(2) > "": |
| 1429 drdict["start"] = int(loc_match.group(2).replace(",", "")) | 1438 drdict["start"] = int( |
| 1439 loc_match.group(2).replace(",", "") | |
| 1440 ) | |
| 1430 if loc_match.group(3) > "": | 1441 if loc_match.group(3) > "": |
| 1431 drdict["end"] = int(loc_match.group(3).replace(",", "")) | 1442 drdict["end"] = int(loc_match.group(3).replace(",", "")) |
| 1432 else: | 1443 else: |
| 1433 logging.info( | 1444 logging.info( |
| 1434 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix" | 1445 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix" |
| 1461 with open(self.config_json_file, "w") as config_file: | 1472 with open(self.config_json_file, "w") as config_file: |
| 1462 json.dump(self.config_json, config_file, indent=2) | 1473 json.dump(self.config_json, config_file, indent=2) |
| 1463 | 1474 |
| 1464 def add_defsess_to_index(self, data): | 1475 def add_defsess_to_index(self, data): |
| 1465 """ | 1476 """ |
| 1466 Broken in Anthony's PR because only ever dealt with the first assembly. | 1477 This was included on request of the new codeowner from Anthony's IUC PR. |
| 1467 | 1478 Now fixed to deal with each assembly and tracks separately. |
| 1479 Originally used only the first assembly, putting all tracks there and | |
| 1480 generally falling apart when tested with 2 or more. Seems ironic that | |
| 1481 this vital feature was never tested given the rejection of my original IUC PR | |
| 1482 because it was not there. And no, reviewer, I do not want this important piece of history | |
| 1483 removed. I prefer that it remain here since it has caused me considerable discomfort. | |
| 1484 | |
| 1485 ---------------------------------------------------------- | |
| 1468 Add some default session settings: set some assemblies/tracks on/off | 1486 Add some default session settings: set some assemblies/tracks on/off |
| 1469 | 1487 |
| 1470 This allows to select a default view: | 1488 This allows to select a default view: |
| 1471 - jb type (Linear, Circular, etc) | 1489 - jb type (Linear, Circular, etc) |
| 1472 - default location on an assembly | 1490 - default location on an assembly |
| 1746 assconf = jc.config_json.get("assemblies", []) | 1764 assconf = jc.config_json.get("assemblies", []) |
| 1747 assconf += jc.assemblies | 1765 assconf += jc.assemblies |
| 1748 jc.config_json["assemblies"] = assconf | 1766 jc.config_json["assemblies"] = assconf |
| 1749 logging.debug("assemblies=%s, gnames=%s" % (assconf, jc.genome_names)) | 1767 logging.debug("assemblies=%s, gnames=%s" % (assconf, jc.genome_names)) |
| 1750 jc.write_config() | 1768 jc.write_config() |
| 1751 jc.add_default_session(default_session_data) | 1769 # jc.add_default_session(default_session_data) |
| 1770 # note that this can be left in the config.json but has NO EFFECT if add_defsess_to_index is called. | |
| 1752 jc.add_defsess_to_index(default_session_data) | 1771 jc.add_defsess_to_index(default_session_data) |
| 1753 # jc.text_index() not sure what broke here. | 1772 # jc.text_index() not sure what broke here. |
