comparison jbrowse2.py @ 17:4c201a3d4755 draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit a37bfdfc108501b11c7b2aa15efb1bd16f0c4b66
author fubar
date Sun, 28 Jan 2024 06:48:52 +0000
parents cce8dacb240f
children bde6b1d09f7d
comparison
equal deleted inserted replaced
16:1fe91657bfd6 17:4c201a3d4755
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 self.genome_firstcontig = None
462 fl = open(fapath, "r").readline().strip().split(">", 1)
463 if len(fl) > 1:
464 self.genome_firstcontig = fl[1].strip()
461 if self.config_json.get("assemblies", None): 465 if self.config_json.get("assemblies", None):
462 self.config_json["assemblies"] += assemblies 466 self.config_json["assemblies"] += assemblies
463 else: 467 else:
464 self.config_json["assemblies"] = assemblies 468 self.config_json["assemblies"] = assemblies
465 469
558 """ 562 """
559 tId = trackData["label"] 563 tId = trackData["label"]
560 # can be served - if public. 564 # can be served - if public.
561 # dsId = trackData["metadata"]["dataset_id"] 565 # dsId = trackData["metadata"]["dataset_id"]
562 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId) 566 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId)
563 hname = trackData["label"] 567 hname = trackData["name"]
564 dest = os.path.join(self.outdir, hname) 568 dest = os.path.join(self.outdir, hname)
565 cmd = ["cp", data, dest] 569 cmd = ["cp", data, dest]
566 # these can be very big. 570 # these can be very big.
567 self.subprocess_check_call(cmd) 571 self.subprocess_check_call(cmd)
568 floc = { 572 floc = {
646 "displays": [ 650 "displays": [
647 { 651 {
648 "type": "LinearBasicDisplay", 652 "type": "LinearBasicDisplay",
649 "displayId": "%s-LinearBasicDisplay" % tId, 653 "displayId": "%s-LinearBasicDisplay" % tId,
650 }, 654 },
651 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, 655 {
656 "type": "LinearArcDisplay",
657 "displayId": "%s-LinearArcDisplay" % tId,
658 },
652 ], 659 ],
653 } 660 }
654 style_json = self._prepare_track_style(trackDict) 661 style_json = self._prepare_track_style(trackDict)
655 trackDict["style"] = style_json 662 trackDict["style"] = style_json
656 self.tracksToAdd.append(trackDict) 663 self.tracksToAdd.append(trackDict)
715 "displays": [ 722 "displays": [
716 { 723 {
717 "type": "LinearBasicDisplay", 724 "type": "LinearBasicDisplay",
718 "displayId": "%s-LinearBasicDisplay" % tId, 725 "displayId": "%s-LinearBasicDisplay" % tId,
719 }, 726 },
720 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, 727 {
728 "type": "LinearArcDisplay",
729 "displayId": "%s-LinearArcDisplay" % tId,
730 },
721 ], 731 ],
722 } 732 }
723 style_json = self._prepare_track_style(trackDict) 733 style_json = self._prepare_track_style(trackDict)
724 trackDict["style"] = style_json 734 trackDict["style"] = style_json
725 self.tracksToAdd.append(trackDict) 735 self.tracksToAdd.append(trackDict)
904 "displays": [ 914 "displays": [
905 { 915 {
906 "type": "LinearBasicDisplay", 916 "type": "LinearBasicDisplay",
907 "displayId": "%s-LinearBasicDisplay" % tId, 917 "displayId": "%s-LinearBasicDisplay" % tId,
908 }, 918 },
909 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, 919 {
920 "type": "LinearArcDisplay",
921 "displayId": "%s-LinearArcDisplay" % tId,
922 },
910 ], 923 ],
911 } 924 }
912 style_json = self._prepare_track_style(trackDict) 925 style_json = self._prepare_track_style(trackDict)
913 trackDict["style"] = style_json 926 trackDict["style"] = style_json
914 self.tracksToAdd.append(trackDict) 927 self.tracksToAdd.append(trackDict)
943 }, 956 },
944 { 957 {
945 "type": "LinearPileupDisplay", 958 "type": "LinearPileupDisplay",
946 "displayId": "%s-LinearPileupDisplay" % tId, 959 "displayId": "%s-LinearPileupDisplay" % tId,
947 }, 960 },
948 {"type": "LinearArcDisplay", "displayId": "%s-LinearArcDisplay" % tId}, 961 {
962 "type": "LinearArcDisplay",
963 "displayId": "%s-LinearArcDisplay" % tId,
964 },
949 ], 965 ],
950 } 966 }
951 style_json = self._prepare_track_style(trackDict) 967 style_json = self._prepare_track_style(trackDict)
952 trackDict["style"] = style_json 968 trackDict["style"] = style_json
953 self.tracksToAdd.append(trackDict) 969 self.tracksToAdd.append(trackDict)
981 "type": "PAFAdapter", 997 "type": "PAFAdapter",
982 "pafLocation": {"uri": url}, 998 "pafLocation": {"uri": url},
983 "assemblyNames": [self.genome_name, pgname], 999 "assemblyNames": [self.genome_name, pgname],
984 }, 1000 },
985 # "displays": [ 1001 # "displays": [
986 # { 1002 # {
987 # "type": "LinearSyntenyDisplay", 1003 # "type": "LinearSyntenyDisplay",
988 # "displayId": "%s-LinearSyntenyDisplay" % tId, 1004 # "displayId": "%s-LinearSyntenyDisplay" % tId,
989 # }, 1005 # },
990 # { 1006 # {
991 # "type": "DotPlotDisplay", 1007 # "type": "DotPlotDisplay",
992 # "displayId": "%s-DotPlotDisplay" % tId, 1008 # "displayId": "%s-DotPlotDisplay" % tId,
993 # }, 1009 # },
994 # ], 1010 # ],
995 } 1011 }
996 style_json = self._prepare_track_style(trackDict) 1012 style_json = self._prepare_track_style(trackDict)
997 trackDict["style"] = style_json 1013 trackDict["style"] = style_json
998 self.tracksToAdd.append(trackDict) 1014 self.tracksToAdd.append(trackDict)
1141 track["conf"]["options"]["pileup"], 1157 track["conf"]["options"]["pileup"],
1142 bam_index=real_indexes[i], 1158 bam_index=real_indexes[i],
1143 ) 1159 )
1144 elif dataset_ext == "blastxml": 1160 elif dataset_ext == "blastxml":
1145 self.add_blastxml( 1161 self.add_blastxml(
1146 dataset_path, outputTrackConfig, track["conf"]["options"]["blast"] 1162 dataset_path,
1163 outputTrackConfig,
1164 track["conf"]["options"]["blast"],
1147 ) 1165 )
1148 elif dataset_ext == "vcf": 1166 elif dataset_ext == "vcf":
1149 self.add_vcf(dataset_path, outputTrackConfig) 1167 self.add_vcf(dataset_path, outputTrackConfig)
1150 elif dataset_ext == "paf": 1168 elif dataset_ext == "paf":
1151 self.add_paf( 1169 self.add_paf(
1152 dataset_path, outputTrackConfig, track["conf"]["options"]["synteny"] 1170 dataset_path,
1171 outputTrackConfig,
1172 track["conf"]["options"]["synteny"],
1153 ) 1173 )
1154 else: 1174 else:
1155 log.warn("Do not know how to handle %s", dataset_ext) 1175 log.warn("Do not know how to handle %s", dataset_ext)
1156 # Return non-human label for use in other fields 1176 # Return non-human label for use in other fields
1157 yield outputTrackConfig["label"] 1177 yield outputTrackConfig["label"]
1192 1212
1193 # The view for the assembly we're adding 1213 # The view for the assembly we're adding
1194 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} 1214 view_json = {"type": "LinearGenomeView", "tracks": tracks_data}
1195 1215
1196 refName = None 1216 refName = None
1217 drdict = {
1218 "reversed": False,
1219 "assemblyName": self.genome_name,
1220 "start": 0,
1221 "end": 100000,
1222 }
1223
1197 if data.get("defaultLocation", ""): 1224 if data.get("defaultLocation", ""):
1198 ddl = data["defaultLocation"] 1225 ddl = data["defaultLocation"]
1199 loc_match = re.search( 1226 loc_match = re.search(r"^([^:]+):(\d*)\.*(\d*)$", ddl)
1200 r"^([^:]+):(\d+)\.+(\d+)$", ddl
1201 )
1202 if loc_match: 1227 if loc_match:
1203 refName = loc_match.group(1) 1228 refName = loc_match.group(1)
1204 start = int(loc_match.group(2)) 1229 drdict["refName"] = refName
1205 end = int(loc_match.group(3)) 1230 if loc_match.group(2) > "":
1231 drdict["start"] = int(loc_match.group(2))
1232 if loc_match.group(3) > "":
1233 drdict["end"] = int(loc_match.group(3))
1206 else: 1234 else:
1207 logging.info( 1235 logging.info(
1208 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix" 1236 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix"
1209 % ddl 1237 % ddl
1210 ) 1238 )
1211 elif self.genome_name is not None: 1239 elif self.genome_firstcontig is not None:
1212 start = 0 1240 drdict["refName"] = self.genome_firstcontig
1213 end = 10000 # Booh, hard coded! waiting for https://github.com/GMOD/jbrowse-components/issues/2708
1214 logging.info( 1241 logging.info(
1215 "@@@ no defaultlocation found for default session - please add one" 1242 "@@@ no defaultlocation found for default session - using %s as first contig found"
1243 % self.genome_firstcontig
1216 ) 1244 )
1217 1245
1218 if refName is not None: 1246 if drdict.get("refName", None):
1219 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome 1247 # TODO displayedRegions is not just zooming to the region, it hides the rest of the chromosome
1220 view_json["displayedRegions"] = [ 1248 view_json["displayedRegions"] = [
1221 { 1249 drdict,
1222 "refName": refName,
1223 "start": start,
1224 "end": end,
1225 "reversed": False,
1226 "assemblyName": self.genome_name,
1227 }
1228 ] 1250 ]
1229 1251
1230 logging.info( 1252 logging.info("@@@ defaultlocation %s for default session" % drdict)
1231 "@@@ defaultlocation %s for default session"
1232 % view_json["displayedRegions"]
1233 )
1234 else: 1253 else:
1235 logging.info( 1254 logging.info(
1236 "@@@ no contig name found for default session - please add one!" 1255 "@@@ no contig name found for default session - please add one!"
1237 ) 1256 )
1238 session_name = data.get("session_name", "New session") 1257 session_name = data.get("session_name", "New session")
1305 "version.txt", 1324 "version.txt",
1306 "test_data", 1325 "test_data",
1307 ]: 1326 ]:
1308 cmd = ["rm", "-rf", os.path.join(self.outdir, fn)] 1327 cmd = ["rm", "-rf", os.path.join(self.outdir, fn)]
1309 self.subprocess_check_call(cmd) 1328 self.subprocess_check_call(cmd)
1310 cmd = ["cp", os.path.join(INSTALLED_TO, "jb2_webserver.py"), self.outdir] 1329 cmd = [
1330 "cp",
1331 os.path.join(INSTALLED_TO, "jb2_webserver.py"),
1332 self.outdir,
1333 ]
1311 self.subprocess_check_call(cmd) 1334 self.subprocess_check_call(cmd)
1312 1335
1313 1336
1314 def parse_style_conf(item): 1337 def parse_style_conf(item):
1315 if "type" in item.attrib and item.attrib["type"] in ["boolean", "integer"]: 1338 if "type" in item.attrib and item.attrib["type"] in [
1339 "boolean",
1340 "integer",
1341 ]:
1316 if item.attrib["type"] == "boolean": 1342 if item.attrib["type"] == "boolean":
1317 return item.text in ("yes", "true", "True") 1343 return item.text in ("yes", "true", "True")
1318 elif item.attrib["type"] == "integer": 1344 elif item.attrib["type"] == "integer":
1319 return int(item.text) 1345 return int(item.text)
1320 else: 1346 else:
1377 trackfiles = track.findall("files/trackFile") 1403 trackfiles = track.findall("files/trackFile")
1378 if trackfiles: 1404 if trackfiles:
1379 for x in track.findall("files/trackFile"): 1405 for x in track.findall("files/trackFile"):
1380 if is_multi_bigwig: 1406 if is_multi_bigwig:
1381 multi_bigwig_paths.append( 1407 multi_bigwig_paths.append(
1382 (x.attrib["label"], os.path.realpath(x.attrib["path"])) 1408 (
1409 x.attrib["label"],
1410 os.path.realpath(x.attrib["path"]),
1411 )
1383 ) 1412 )
1384 else: 1413 else:
1385 if trackfiles: 1414 if trackfiles:
1386 metadata = metadata_from_node(x.find("metadata")) 1415 metadata = metadata_from_node(x.find("metadata"))
1387 track_conf["dataset_id"] = metadata["dataset_id"] 1416 track_conf["dataset_id"] = metadata["dataset_id"]