comparison jbrowse2.py @ 137:e237edee9a53 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/jbrowse2 commit 5482aa86f906615d9bddcc32cfbc2d45b24e6345
author iuc
date Fri, 24 Oct 2025 07:50:40 +0000
parents 93fdd696c281
children
comparison
equal deleted inserted replaced
136:93fdd696c281 137:e237edee9a53
29 "]": "__cb__", 29 "]": "__cb__",
30 "{": "__oc__", 30 "{": "__oc__",
31 "}": "__cc__", 31 "}": "__cc__",
32 "@": "__at__", 32 "@": "__at__",
33 "#": "__pd__", 33 "#": "__pd__",
34 "": "__cn__", 34 "\n": "__cn__",
35 "\r": "__cr__",
36 "\t": "__tc__",
35 } 37 }
36 38
37 39
38 def etree_to_dict(t): 40 def etree_to_dict(t):
39 if t is None: 41 if t is None:
60 62
61 63
62 INSTALLED_TO = os.path.dirname(os.path.realpath(__file__)) 64 INSTALLED_TO = os.path.dirname(os.path.realpath(__file__))
63 65
64 66
67 def unsanitize(input):
68
69 for key, value in mapped_chars.items():
70 input = input.replace(value, key)
71
72 return input
73
74
65 def metadata_from_node(node): 75 def metadata_from_node(node):
66 metadata = {} 76 metadata = {}
67 77
68 if len(node.findall("dataset")) == 1: 78 if len(node.findall("dataset")) == 1:
69 79
72 82
73 for key, value in node.findall("history")[0].attrib.items(): 83 for key, value in node.findall("history")[0].attrib.items():
74 metadata[f"history_{key}"] = value 84 metadata[f"history_{key}"] = value
75 85
76 for key, value in node.findall("metadata")[0].attrib.items(): 86 for key, value in node.findall("metadata")[0].attrib.items():
77 metadata[f"metadata_{key}"] = value 87 metadata[f"metadata_{key}"] = unsanitize(value)
78 88
79 for key, value in node.findall("tool")[0].attrib.items(): 89 for key, value in node.findall("tool")[0].attrib.items():
80 metadata[f"tool_{key}"] = value 90 metadata[f"tool_{key}"] = value
81 91
82 # Additional Mappings applied: 92 # Additional Mappings applied:
263 def _prepare_format_details(self, xml_conf): 273 def _prepare_format_details(self, xml_conf):
264 formatDetails = { 274 formatDetails = {
265 } 275 }
266 276
267 if "feature" in xml_conf["formatdetails"]: 277 if "feature" in xml_conf["formatdetails"]:
268 feat_jexl = xml_conf["formatdetails"]["feature"] 278 feat_jexl = unsanitize(xml_conf["formatdetails"]["feature"])
269 for key, value in mapped_chars.items():
270 feat_jexl = feat_jexl.replace(value, key)
271 formatDetails["feature"] = feat_jexl 279 formatDetails["feature"] = feat_jexl
272 280
273 if "subfeature" in xml_conf["formatdetails"]: 281 if "subfeature" in xml_conf["formatdetails"]:
274 sfeat_jexl = xml_conf["formatdetails"]["subfeature"] 282 sfeat_jexl = unsanitize(xml_conf["formatdetails"]["subfeature"])
275 for key, value in mapped_chars.items():
276 sfeat_jexl = sfeat_jexl.replace(value, key)
277 formatDetails["subfeatures"] = sfeat_jexl 283 formatDetails["subfeatures"] = sfeat_jexl
278 284
279 if "depth" in xml_conf["formatdetails"]: 285 if "depth" in xml_conf["formatdetails"]:
280 formatDetails["depth"] = int(xml_conf["formatdetails"]["depth"]) 286 formatDetails["depth"] = int(xml_conf["formatdetails"]["depth"])
281 287
769 trackData["category"], 775 trackData["category"],
770 rel_dest, 776 rel_dest,
771 parent, 777 parent,
772 config=style_json, 778 config=style_json,
773 remote=trackData['remote'] 779 remote=trackData['remote']
780 )
781
782 def add_gtf(self, parent, data, format, trackData, gffOpts, **kwargs):
783 # Not a super recommended format
784 # https://github.com/GMOD/jbrowse-components/pull/2389
785 # https://github.com/GMOD/jbrowse-components/issues/3876
786 if trackData['remote']:
787 rel_dest = data
788 else:
789 rel_dest = os.path.join("data", trackData["label"] + ".gtf")
790 dest = os.path.join(self.outdir, rel_dest)
791 shutil.copy(os.path.realpath(data), dest)
792
793 json_track_data = {
794 "type": "FeatureTrack",
795 "trackId": trackData["label"],
796 "name": trackData["key"],
797 "adapter": {
798 "type": "GtfAdapter",
799 "gtfLocation": {
800 "uri": rel_dest,
801 "locationType": "UriLocation"
802 },
803 },
804 "category": [trackData["category"]],
805 "assemblyNames": [parent['uniq_id']],
806 }
807
808 style_json = self._prepare_track_style(trackData)
809
810 formatdetails = self._prepare_format_details(trackData)
811
812 style_json.update(formatdetails)
813
814 track_metadata = self._prepare_track_metadata(trackData)
815
816 style_json.update(track_metadata)
817
818 json_track_data.update(style_json)
819
820 self.subprocess_check_call(
821 [
822 "jbrowse",
823 "add-track-json",
824 "--target",
825 self.outdir,
826 json.dumps(json_track_data),
827 ]
774 ) 828 )
775 829
776 def add_bed(self, parent, data, format, trackData, gffOpts, **kwargs): 830 def add_bed(self, parent, data, format, trackData, gffOpts, **kwargs):
777 if trackData['remote']: 831 if trackData['remote']:
778 rel_dest = data 832 rel_dest = data
1113 dataset_ext, 1167 dataset_ext,
1114 track_human_label, 1168 track_human_label,
1115 extra_metadata, 1169 extra_metadata,
1116 ) in enumerate(track["trackfiles"]): 1170 ) in enumerate(track["trackfiles"]):
1117 # Unsanitize labels (element_identifiers are always sanitized by Galaxy) 1171 # Unsanitize labels (element_identifiers are always sanitized by Galaxy)
1118 for key, value in mapped_chars.items(): 1172 track_human_label = unsanitize(track_human_label)
1119 track_human_label = track_human_label.replace(value, key)
1120 1173
1121 is_multi = type(dataset_path) is list 1174 is_multi = type(dataset_path) is list
1122 1175
1123 log.info( 1176 log.info(
1124 f"-----> Processing track {category} / {track_human_label} ({dataset_ext}, {len(dataset_path) if is_multi else 1} files)" 1177 f"-----> Processing track {category} / {track_human_label} ({dataset_ext}, {len(dataset_path) if is_multi else 1} files)"
1172 else: 1225 else:
1173 dataset_ext = "vcf" 1226 dataset_ext = "vcf"
1174 1227
1175 if dataset_ext in ("gff", "gff3"): 1228 if dataset_ext in ("gff", "gff3"):
1176 self.add_gff( 1229 self.add_gff(
1230 parent,
1231 dataset_path,
1232 dataset_ext,
1233 outputTrackConfig,
1234 track["conf"]["options"]["gff"],
1235 )
1236 elif dataset_ext in ("gtf"):
1237 self.add_gtf(
1177 parent, 1238 parent,
1178 dataset_path, 1239 dataset_path,
1179 dataset_ext, 1240 dataset_ext,
1180 outputTrackConfig, 1241 outputTrackConfig,
1181 track["conf"]["options"]["gff"], 1242 track["conf"]["options"]["gff"],
1286 dataset_path, 1347 dataset_path,
1287 outputTrackConfig, 1348 outputTrackConfig,
1288 track["conf"]["options"]["hic"] 1349 track["conf"]["options"]["hic"]
1289 ) 1350 )
1290 elif dataset_ext == "sparql": 1351 elif dataset_ext == "sparql":
1291 sparql_query = track["conf"]["options"]["sparql"]["query"] 1352 sparql_query = unsanitize(track["conf"]["options"]["sparql"]["query"])
1292 for key, value in mapped_chars.items():
1293 sparql_query = sparql_query.replace(value, key)
1294 sparql_query_refnames = track["conf"]["options"]["sparql"].get("query_refnames", "") 1353 sparql_query_refnames = track["conf"]["options"]["sparql"].get("query_refnames", "")
1295 if sparql_query_refnames: 1354 if sparql_query_refnames:
1296 for key, value in mapped_chars.items(): 1355 sparql_query_refnames = unsanitize(sparql_query_refnames)
1297 sparql_query_refnames = sparql_query_refnames.replace(value, key)
1298 self.add_sparql( 1356 self.add_sparql(
1299 parent, 1357 parent,
1300 track["conf"]["options"]["sparql"]["url"], 1358 track["conf"]["options"]["sparql"]["url"],
1301 sparql_query, 1359 sparql_query,
1302 sparql_query_refnames, 1360 sparql_query_refnames,
1306 self.add_gc_content( 1364 self.add_gc_content(
1307 parent, 1365 parent,
1308 outputTrackConfig, 1366 outputTrackConfig,
1309 ) 1367 )
1310 else: 1368 else:
1311 log.error(f"Do not know how to handle {dataset_ext}") 1369 raise RuntimeError(f"Do not know how to handle dataset of type '{dataset_ext}'")
1312 1370
1313 track_labels.append(outputTrackConfig["label"]) 1371 track_labels.append(outputTrackConfig["label"])
1314 1372
1315 # Return non-human label for use in other fields 1373 # Return non-human label for use in other fields
1316 return track_labels 1374 return track_labels
1708 1766
1709 track_conf["remote"] = is_remote 1767 track_conf["remote"] = is_remote
1710 1768
1711 track_labels = jc.process_annotations(track_conf, genome) 1769 track_labels = jc.process_annotations(track_conf, genome)
1712 1770
1713 if track.attrib["visibility"] == "default_on": 1771 if track.attrib["visibility"] == "default_on" and \
1772 (track_conf["format"] != "synteny" or track_conf["style"]["display"] != "LinearSyntenyDisplay"):
1714 for tlabel in track_labels: 1773 for tlabel in track_labels:
1715 default_tracks_on.append(tlabel) 1774 default_tracks_on.append(tlabel)
1716 1775
1717 track_num += 1 1776 track_num += 1
1718 1777