Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 15:cce8dacb240f draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 1a20cf06627d429a211427753f223467188dbe7f-dirty
author | fubar |
---|---|
date | Thu, 25 Jan 2024 07:39:41 +0000 |
parents | 7c2e28e144f3 |
children | 4c201a3d4755 |
comparison
equal
deleted
inserted
replaced
14:7c2e28e144f3 | 15:cce8dacb240f |
---|---|
16 from collections import defaultdict | 16 from collections import defaultdict |
17 | 17 |
18 logging.basicConfig(level=logging.INFO) | 18 logging.basicConfig(level=logging.INFO) |
19 log = logging.getLogger("jbrowse") | 19 log = logging.getLogger("jbrowse") |
20 | 20 |
21 JB2VER = "v2.10.0" | 21 JB2VER = "v2.10.1" |
22 # version pinned for cloning | 22 # version pinned for cloning |
23 | 23 |
24 TODAY = datetime.datetime.now().strftime("%Y-%m-%d") | 24 TODAY = datetime.datetime.now().strftime("%Y-%m-%d") |
25 GALAXY_INFRASTRUCTURE_URL = None | 25 GALAXY_INFRASTRUCTURE_URL = None |
26 JB2REL = "v2.10.0" | 26 JB2REL = "v2.10.0" |
456 self.genome_names.append(genome_name) | 456 self.genome_names.append(genome_name) |
457 if self.genome_name is None: | 457 if self.genome_name is None: |
458 self.genome_name = ( | 458 self.genome_name = ( |
459 genome_name # first one for all tracks - other than paf | 459 genome_name # first one for all tracks - other than paf |
460 ) | 460 ) |
461 if self.config_json.get("assemblies", None): | 461 if self.config_json.get("assemblies", None): |
462 self.config_json["assemblies"] += assemblies | 462 self.config_json["assemblies"] += assemblies |
463 else: | 463 else: |
464 self.config_json["assemblies"] = assemblies | 464 self.config_json["assemblies"] = assemblies |
465 | 465 |
466 def make_assembly(self, fapath, gname): | 466 def make_assembly(self, fapath, gname): |
467 hashData = [ | 467 hashData = [ |
468 fapath, | 468 fapath, |
469 gname, | 469 gname, |
725 self.tracksToAdd.append(trackDict) | 725 self.tracksToAdd.append(trackDict) |
726 self.trackIdlist.append(tId) | 726 self.trackIdlist.append(tId) |
727 os.unlink(gff3) | 727 os.unlink(gff3) |
728 | 728 |
729 def add_bigwig(self, data, trackData): | 729 def add_bigwig(self, data, trackData): |
730 """ "type": "LinearWiggleDisplay", | |
731 "configuration": {}, | |
732 "selectedRendering": "", | |
733 "resolution": 1, | |
734 "posColor": "rgb(228, 26, 28)", | |
735 "negColor": "rgb(255, 255, 51)", | |
736 "constraints": {} | |
737 """ | |
730 url = "%s.bigwig" % trackData["label"] | 738 url = "%s.bigwig" % trackData["label"] |
731 # slashes in names cause path trouble | 739 # slashes in names cause path trouble |
732 dest = os.path.join(self.outdir, url) | 740 dest = os.path.join(self.outdir, url) |
733 cmd = ["cp", data, dest] | 741 cmd = ["cp", data, dest] |
734 self.subprocess_check_call(cmd) | 742 self.subprocess_check_call(cmd) |
754 } | 762 } |
755 style_json = self._prepare_track_style(trackDict) | 763 style_json = self._prepare_track_style(trackDict) |
756 trackDict["style"] = style_json | 764 trackDict["style"] = style_json |
757 self.tracksToAdd.append(trackDict) | 765 self.tracksToAdd.append(trackDict) |
758 self.trackIdlist.append(tId) | 766 self.trackIdlist.append(tId) |
759 logging.debug("#### wig trackData=%s" % str(trackData)) | 767 logging.info("#### wig trackData=%s" % str(trackData)) |
760 | 768 |
761 def add_bam(self, data, trackData, bamOpts, bam_index=None, **kwargs): | 769 def add_bam(self, data, trackData, bamOpts, bam_index=None, **kwargs): |
762 tId = trackData["label"] | 770 tId = trackData["label"] |
763 fname = "%s.bam" % trackData["label"] | 771 fname = "%s.bam" % trackData["label"] |
764 dest = "%s/%s" % (self.outdir, fname) | 772 dest = "%s/%s" % (self.outdir, fname) |
947 | 955 |
948 def add_paf(self, data, trackData, pafOpts, **kwargs): | 956 def add_paf(self, data, trackData, pafOpts, **kwargs): |
949 tname = trackData["name"] | 957 tname = trackData["name"] |
950 tId = trackData["label"] | 958 tId = trackData["label"] |
951 pgname = pafOpts["genome_label"] | 959 pgname = pafOpts["genome_label"] |
952 if len(pgname.split() > 1): | 960 if len(pgname.split()) > 1: |
953 pgname = pgname.split()[ | 961 pgname = pgname.split()[ |
954 0 | 962 0 |
955 ] # trouble from spacey names in command lines avoidance | 963 ] # trouble from spacey names in command lines avoidance |
956 asstrack, gname = self.make_assembly(pafOpts["genome"], pgname) | 964 asstrack = self.make_assembly(pafOpts["genome"], pgname) |
957 self.genome_names.append(pgname) | 965 self.genome_names.append(pgname) |
958 if self.config_json.get("assemblies", None): | 966 if self.config_json.get("assemblies", None): |
959 self.config_json["assemblies"].append(asstrack) | 967 self.config_json["assemblies"].append(asstrack) |
960 else: | 968 else: |
961 self.config_json["assemblies"] = [ | 969 self.config_json["assemblies"] = [ |
962 asstrack, | 970 asstrack, |
963 ] | 971 ] |
964 | |
965 url = "%s.paf" % (trackData["label"]) | 972 url = "%s.paf" % (trackData["label"]) |
966 dest = "%s/%s" % (self.outdir, url) | 973 dest = "%s/%s" % (self.outdir, url) |
967 self.symlink_or_copy(os.path.realpath(data), dest) | 974 self.symlink_or_copy(os.path.realpath(data), dest) |
968 trackDict = { | 975 trackDict = { |
969 "type": "SyntenyTrack", | 976 "type": "SyntenyTrack", |
973 "adapter": { | 980 "adapter": { |
974 "type": "PAFAdapter", | 981 "type": "PAFAdapter", |
975 "pafLocation": {"uri": url}, | 982 "pafLocation": {"uri": url}, |
976 "assemblyNames": [self.genome_name, pgname], | 983 "assemblyNames": [self.genome_name, pgname], |
977 }, | 984 }, |
985 # "displays": [ | |
986 # { | |
987 # "type": "LinearSyntenyDisplay", | |
988 # "displayId": "%s-LinearSyntenyDisplay" % tId, | |
989 # }, | |
990 # { | |
991 # "type": "DotPlotDisplay", | |
992 # "displayId": "%s-DotPlotDisplay" % tId, | |
993 # }, | |
994 # ], | |
978 } | 995 } |
979 style_json = self._prepare_track_style(trackDict) | 996 style_json = self._prepare_track_style(trackDict) |
980 trackDict["style"] = style_json | 997 trackDict["style"] = style_json |
981 self.tracksToAdd.append(trackDict) | 998 self.tracksToAdd.append(trackDict) |
982 self.trackIdlist.append(tId) | 999 self.trackIdlist.append(tId) |
1128 self.add_blastxml( | 1145 self.add_blastxml( |
1129 dataset_path, outputTrackConfig, track["conf"]["options"]["blast"] | 1146 dataset_path, outputTrackConfig, track["conf"]["options"]["blast"] |
1130 ) | 1147 ) |
1131 elif dataset_ext == "vcf": | 1148 elif dataset_ext == "vcf": |
1132 self.add_vcf(dataset_path, outputTrackConfig) | 1149 self.add_vcf(dataset_path, outputTrackConfig) |
1150 elif dataset_ext == "paf": | |
1151 self.add_paf( | |
1152 dataset_path, outputTrackConfig, track["conf"]["options"]["synteny"] | |
1153 ) | |
1133 else: | 1154 else: |
1134 log.warn("Do not know how to handle %s", dataset_ext) | 1155 log.warn("Do not know how to handle %s", dataset_ext) |
1135 # Return non-human label for use in other fields | 1156 # Return non-human label for use in other fields |
1136 yield outputTrackConfig["label"] | 1157 yield outputTrackConfig["label"] |
1137 | 1158 |
1175 refName = None | 1196 refName = None |
1176 if data.get("defaultLocation", ""): | 1197 if data.get("defaultLocation", ""): |
1177 ddl = data["defaultLocation"] | 1198 ddl = data["defaultLocation"] |
1178 loc_match = re.search( | 1199 loc_match = re.search( |
1179 r"^([^:]+):(\d+)\.+(\d+)$", ddl | 1200 r"^([^:]+):(\d+)\.+(\d+)$", ddl |
1180 ) # was re.search(r"^(\w.+):(\d+)\.+(\d+)$" | 1201 ) |
1181 if loc_match: | 1202 if loc_match: |
1182 refName = loc_match.group(1) | 1203 refName = loc_match.group(1) |
1183 start = int(loc_match.group(2)) | 1204 start = int(loc_match.group(2)) |
1184 end = int(loc_match.group(3)) | 1205 end = int(loc_match.group(3)) |
1185 else: | 1206 else: |
1405 item.tag: parse_style_conf(item) | 1426 item.tag: parse_style_conf(item) |
1406 for item in track.find("options/style_labels") | 1427 for item in track.find("options/style_labels") |
1407 } | 1428 } |
1408 | 1429 |
1409 track_conf["conf"] = etree_to_dict(track.find("options")) | 1430 track_conf["conf"] = etree_to_dict(track.find("options")) |
1431 track_conf["category"] = track.attrib["cat"] | |
1432 track_conf["format"] = track.attrib["format"] | |
1433 try: | |
1434 # Only pertains to gff3 + blastxml. TODO? | |
1435 track_conf["style"] = {t.tag: t.text for t in track.find("options/style")} | |
1436 except TypeError: | |
1437 track_conf["style"] = {} | |
1438 pass | |
1439 track_conf["conf"] = etree_to_dict(track.find("options")) | |
1410 keys = jc.process_annotations(track_conf) | 1440 keys = jc.process_annotations(track_conf) |
1411 | 1441 |
1412 if keys: | 1442 if keys: |
1413 for key in keys: | 1443 for key in keys: |
1414 default_session_data["visibility"][ | 1444 default_session_data["visibility"][ |
1420 ] # TODO do we need this anymore? | 1450 ] # TODO do we need this anymore? |
1421 if track_conf.get("style_lables", None): | 1451 if track_conf.get("style_lables", None): |
1422 default_session_data["style_labels"][key] = track_conf.get( | 1452 default_session_data["style_labels"][key] = track_conf.get( |
1423 "style_labels", None | 1453 "style_labels", None |
1424 ) | 1454 ) |
1425 | 1455 default_session_data["defaultLocation"] = root.find( |
1426 default_session_data["defaultLocation"] = root.find( | 1456 "metadata/general/defaultLocation" |
1427 "metadata/general/defaultLocation" | 1457 ).text |
1428 ).text | 1458 default_session_data["session_name"] = root.find( |
1429 default_session_data["session_name"] = root.find( | 1459 "metadata/general/session_name" |
1430 "metadata/general/session_name" | 1460 ).text |
1431 ).text | 1461 general_data = { |
1432 | 1462 "analytics": root.find("metadata/general/analytics").text, |
1433 general_data = { | 1463 "primary_color": root.find("metadata/general/primary_color").text, |
1434 "analytics": root.find("metadata/general/analytics").text, | 1464 "secondary_color": root.find("metadata/general/secondary_color").text, |
1435 "primary_color": root.find("metadata/general/primary_color").text, | 1465 "tertiary_color": root.find("metadata/general/tertiary_color").text, |
1436 "secondary_color": root.find("metadata/general/secondary_color").text, | 1466 "quaternary_color": root.find("metadata/general/quaternary_color").text, |
1437 "tertiary_color": root.find("metadata/general/tertiary_color").text, | 1467 "font_size": root.find("metadata/general/font_size").text, |
1438 "quaternary_color": root.find("metadata/general/quaternary_color").text, | 1468 } |
1439 "font_size": root.find("metadata/general/font_size").text, | 1469 jc.add_general_configuration(general_data) |
1440 } | 1470 trackconf = jc.config_json.get("tracks", None) |
1441 track_conf["category"] = track.attrib["cat"] | 1471 if trackconf: |
1442 track_conf["format"] = track.attrib["format"] | 1472 jc.config_json["tracks"].update(jc.tracksToAdd) |
1443 try: | 1473 else: |
1444 # Only pertains to gff3 + blastxml. TODO? | 1474 jc.config_json["tracks"] = jc.tracksToAdd |
1445 track_conf["style"] = {t.tag: t.text for t in track.find("options/style")} | |
1446 except TypeError: | |
1447 track_conf["style"] = {} | |
1448 pass | |
1449 track_conf["conf"] = etree_to_dict(track.find("options")) | |
1450 jc.add_general_configuration(general_data) | |
1451 jc.config_json["tracks"] = jc.tracksToAdd | |
1452 jc.write_config() | 1475 jc.write_config() |
1453 jc.add_default_session(default_session_data) | 1476 jc.add_default_session(default_session_data) |
1454 | |
1455 # jc.text_index() not sure what broke here. | 1477 # jc.text_index() not sure what broke here. |