Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 59:f807e219cec3 draft
planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit faada92caf5aaabe58e52b161687a30d542a07b9
author | fubar |
---|---|
date | Fri, 22 Mar 2024 22:04:08 +0000 |
parents | 94264fe60478 |
children | 81d535970196 |
comparison
equal
deleted
inserted
replaced
58:0e592dcaeb7f | 59:f807e219cec3 |
---|---|
437 } | 437 } |
438 | 438 |
439 if trackDict.get("displays", None): # use first if multiple like bed | 439 if trackDict.get("displays", None): # use first if multiple like bed |
440 style_data["type"] = trackDict["displays"][0]["type"] | 440 style_data["type"] = trackDict["displays"][0]["type"] |
441 style_data["displayId"] = trackDict["displays"][0]["displayId"] | 441 style_data["displayId"] = trackDict["displays"][0]["displayId"] |
442 return { | 442 wstyle = { |
443 "displays": [ | 443 "displays": [ |
444 style_data, | 444 style_data, |
445 ] | 445 ] |
446 } | 446 } |
447 logging.warn("style=%s" % (wstyle)) | |
448 return wstyle | |
447 | 449 |
448 def process_genomes(self): | 450 def process_genomes(self): |
449 assemblies = [] | 451 assemblies = [] |
450 useuri = False | 452 useuri = False |
451 for i, genome_node in enumerate(self.genome_paths): | 453 for i, genome_node in enumerate(self.genome_paths): |
494 faname = fapath | 496 faname = fapath |
495 adapter = { | 497 adapter = { |
496 "type": "BgzipFastaAdapter", | 498 "type": "BgzipFastaAdapter", |
497 "fastaLocation": { | 499 "fastaLocation": { |
498 "uri": faname, | 500 "uri": faname, |
499 "locationType": "UriLocation", | 501 "locationType": "UriLocation" |
500 }, | 502 }, |
501 "faiLocation": { | 503 "faiLocation": { |
502 "uri": faname + ".fai", | 504 "uri": faname + ".fai", |
503 "locationType": "UriLocation", | 505 "locationType": "UriLocation" |
504 }, | 506 }, |
505 "gziLocation": { | 507 "gziLocation": { |
506 "uri": faname + ".gzi", | 508 "uri": faname + ".gzi", |
507 "locationType": "UriLocation", | 509 "locationType": "UriLocation" |
508 }, | 510 } |
509 } | 511 } |
510 else: | 512 else: |
511 faname = gname + ".fa.gz" | 513 faname = gname + ".fa.gz" |
512 fadest = os.path.realpath(os.path.join(self.outdir, faname)) | 514 fadest = os.path.realpath(os.path.join(self.outdir, faname)) |
513 cmd = "bgzip -i -c %s -I %s.gzi > %s && samtools faidx %s" % ( | 515 cmd = "bgzip -i -c %s -I %s.gzi > %s && samtools faidx %s" % ( |
526 "faiLocation": { | 528 "faiLocation": { |
527 "uri": faname + ".fai", | 529 "uri": faname + ".fai", |
528 }, | 530 }, |
529 "gziLocation": { | 531 "gziLocation": { |
530 "uri": faname + ".gzi", | 532 "uri": faname + ".gzi", |
531 }, | 533 } |
532 } | 534 } |
533 | 535 |
534 trackDict = { | 536 trackDict = { |
535 "name": gname, | 537 "name": gname, |
536 "sequence": { | 538 "sequence": { |
537 "type": "ReferenceSequenceTrack", | 539 "type": "ReferenceSequenceTrack", |
538 "trackId": gname, | 540 "trackId": gname, |
539 "adapter": adapter, | 541 "adapter": adapter, |
540 }, | 542 }, |
541 "rendering": {"type": "DivSequenceRenderer"}, | |
542 "displays": [ | 543 "displays": [ |
543 { | 544 { |
544 "type": "LinearReferenceSequenceDisplay", | 545 "type": "LinearReferenceSequenceDisplay", |
545 "displayId": "%s-LinearReferenceSequenceDisplay" % gname, | 546 "displayId": "%s-LinearReferenceSequenceDisplay" % gname, |
546 }, | 547 }, |
547 { | 548 { |
548 "type": "LinearGCContentDisplay", | 549 "type": "LinearGCContentDisplay", |
549 "displayId": "%s-LinearGCContentDisplay" % gname, | 550 "displayId": "%s-LinearGCContentDisplay" % gname, |
550 }, | 551 }, |
551 ], | 552 ] |
552 } | 553 } |
553 return trackDict | 554 return trackDict |
554 | 555 |
555 def add_default_view(self): | 556 def add_default_view(self): |
556 cmd = [ | 557 cmd = [ |
633 "type": "LinearHicDisplay", | 634 "type": "LinearHicDisplay", |
634 "displayId": "%s-LinearHicDisplay" % tId, | 635 "displayId": "%s-LinearHicDisplay" % tId, |
635 }, | 636 }, |
636 ], | 637 ], |
637 } | 638 } |
639 style_json = self._prepare_track_style(trackDict) | |
640 trackDict["style"] = style_json | |
638 self.tracksToAdd.append(trackDict) | 641 self.tracksToAdd.append(trackDict) |
639 self.trackIdlist.append(tId) | 642 self.trackIdlist.append(tId) |
640 | 643 |
641 def add_maf(self, data, trackData): | 644 def add_maf(self, data, trackData): |
642 """ | 645 """ |
706 "type": "LinearArcDisplay", | 709 "type": "LinearArcDisplay", |
707 "displayId": "%s-LinearArcDisplay" % tId, | 710 "displayId": "%s-LinearArcDisplay" % tId, |
708 }, | 711 }, |
709 ], | 712 ], |
710 } | 713 } |
714 style_json = self._prepare_track_style(trackDict) | |
715 trackDict["style"] = style_json | |
711 self.tracksToAdd.append(trackDict) | 716 self.tracksToAdd.append(trackDict) |
712 self.trackIdlist.append(tId) | 717 self.trackIdlist.append(tId) |
713 if self.config_json.get("plugins", None): | 718 if self.config_json.get("plugins", None): |
714 self.config_json["plugins"].append(mafPlugin[0]) | 719 self.config_json["plugins"].append(mafPlugin[0]) |
715 else: | 720 else: |
779 "type": "LinearArcDisplay", | 784 "type": "LinearArcDisplay", |
780 "displayId": "%s-LinearArcDisplay" % tId, | 785 "displayId": "%s-LinearArcDisplay" % tId, |
781 }, | 786 }, |
782 ], | 787 ], |
783 } | 788 } |
789 style_json = self._prepare_track_style(trackDict) | |
790 trackDict["style"] = style_json | |
784 self.tracksToAdd.append(trackDict) | 791 self.tracksToAdd.append(trackDict) |
785 self.trackIdlist.append(tId) | 792 self.trackIdlist.append(tId) |
786 os.unlink(gff3) | 793 os.unlink(gff3) |
787 | 794 |
788 def add_bigwig(self, data, trackData): | 795 def add_bigwig(self, data, trackData): |
825 "type": "LinearWiggleDisplay", | 832 "type": "LinearWiggleDisplay", |
826 "displayId": "%s-LinearWiggleDisplay" % tId, | 833 "displayId": "%s-LinearWiggleDisplay" % tId, |
827 } | 834 } |
828 ], | 835 ], |
829 } | 836 } |
837 style_json = self._prepare_track_style(trackDict) | |
838 trackDict["style"] = style_json | |
830 self.tracksToAdd.append(trackDict) | 839 self.tracksToAdd.append(trackDict) |
831 self.trackIdlist.append(tId) | 840 self.trackIdlist.append(tId) |
832 | 841 |
833 def add_bam(self, data, trackData, bam_index=None, **kwargs): | 842 def add_bam(self, data, trackData, bam_index=None, **kwargs): |
834 tId = trackData["label"] | 843 tId = trackData["label"] |
878 "type": "LinearAlignmentsDisplay", | 887 "type": "LinearAlignmentsDisplay", |
879 "displayId": "%s-LinearAlignmentsDisplay" % tId, | 888 "displayId": "%s-LinearAlignmentsDisplay" % tId, |
880 }, | 889 }, |
881 ], | 890 ], |
882 } | 891 } |
892 style_json = self._prepare_track_style(trackDict) | |
893 trackDict["style"] = style_json | |
883 self.tracksToAdd.append(trackDict) | 894 self.tracksToAdd.append(trackDict) |
884 self.trackIdlist.append(tId) | 895 self.trackIdlist.append(tId) |
885 | 896 |
886 def add_cram(self, data, trackData, cram_index=None, **kwargs): | 897 def add_cram(self, data, trackData, cram_index=None, **kwargs): |
887 tId = trackData["label"] | 898 tId = trackData["label"] |
926 "type": "LinearAlignmentsDisplay", | 937 "type": "LinearAlignmentsDisplay", |
927 "displayId": "%s-LinearAlignmentsDisplay" % tId, | 938 "displayId": "%s-LinearAlignmentsDisplay" % tId, |
928 }, | 939 }, |
929 ], | 940 ], |
930 } | 941 } |
942 style_json = self._prepare_track_style(trackDict) | |
943 trackDict["style"] = style_json | |
931 self.tracksToAdd.append(trackDict) | 944 self.tracksToAdd.append(trackDict) |
932 self.trackIdlist.append(tId) | 945 self.trackIdlist.append(tId) |
933 | 946 |
934 def add_vcf(self, data, trackData): | 947 def add_vcf(self, data, trackData): |
935 tId = trackData["label"] | 948 tId = trackData["label"] |
978 "type": "LinearPairedArcDisplay", | 991 "type": "LinearPairedArcDisplay", |
979 "displayId": "%s-LinearPairedArcDisplay" % tId, | 992 "displayId": "%s-LinearPairedArcDisplay" % tId, |
980 }, | 993 }, |
981 ], | 994 ], |
982 } | 995 } |
996 style_json = self._prepare_track_style(trackDict) | |
997 trackDict["style"] = style_json | |
983 self.tracksToAdd.append(trackDict) | 998 self.tracksToAdd.append(trackDict) |
984 self.trackIdlist.append(tId) | 999 self.trackIdlist.append(tId) |
985 | 1000 |
986 def _sort_gff(self, data, dest): | 1001 def _sort_gff(self, data, dest): |
987 # Only index if not already done | 1002 # Only index if not already done |
1039 "type": "LinearArcDisplay", | 1054 "type": "LinearArcDisplay", |
1040 "displayId": "%s-LinearArcDisplay" % tId, | 1055 "displayId": "%s-LinearArcDisplay" % tId, |
1041 }, | 1056 }, |
1042 ], | 1057 ], |
1043 } | 1058 } |
1059 style_json = self._prepare_track_style(trackDict) | |
1060 trackDict["style"] = style_json | |
1044 self.tracksToAdd.append(trackDict) | 1061 self.tracksToAdd.append(trackDict) |
1045 self.trackIdlist.append(tId) | 1062 self.trackIdlist.append(tId) |
1046 | 1063 |
1047 def add_bed(self, data, ext, trackData): | 1064 def add_bed(self, data, ext, trackData): |
1048 tId = trackData["label"] | 1065 tId = trackData["label"] |
1086 "type": "LinearArcDisplay", | 1103 "type": "LinearArcDisplay", |
1087 "displayId": "%s-LinearArcDisplay" % tId, | 1104 "displayId": "%s-LinearArcDisplay" % tId, |
1088 }, | 1105 }, |
1089 ], | 1106 ], |
1090 } | 1107 } |
1108 style_json = self._prepare_track_style(trackDict) | |
1109 trackDict["style"] = style_json | |
1091 self.tracksToAdd.append(trackDict) | 1110 self.tracksToAdd.append(trackDict) |
1092 self.trackIdlist.append(tId) | 1111 self.trackIdlist.append(tId) |
1093 | 1112 |
1094 def add_paf(self, data, trackData, pafOpts, **kwargs): | 1113 def add_paf(self, data, trackData, pafOpts, **kwargs): |
1095 tname = trackData["name"] | 1114 tname = trackData["name"] |
1096 tId = trackData["label"] | 1115 tId = trackData["label"] |
1097 categ = trackData["category"] | 1116 categ = trackData["category"] |
1098 pgnames = [x.strip() for x in pafOpts["genome_label"].split(",")] | 1117 pgnames = [x.strip() for x in pafOpts["genome_label"].split(",") if len(x.strip()) > 0] |
1099 pgpaths = [x.strip() for x in pafOpts["genome"].split(",")] | 1118 pgpaths = [x.strip() for x in pafOpts["genome"].split(",") if len(x.strip()) > 0] |
1100 passnames = [self.genome_name] # always first | 1119 passnames = [self.genome_name] # always first |
1120 logging.warn("### add_paf got pafOpts=%s, pgnames=%s, pgpaths=%s for %s" % (pafOpts, pgnames, pgpaths, tId)) | |
1101 for i, gname in enumerate(pgnames): | 1121 for i, gname in enumerate(pgnames): |
1102 if len(gname.split()) > 1: | 1122 if len(gname.split()) > 1: |
1103 gname = gname.split()[0] | 1123 gname = gname.split()[0] |
1104 passnames.append(gname) | 1124 passnames.append(gname) |
1105 # trouble from spacey names in command lines avoidance | 1125 # trouble from spacey names in command lines avoidance |
1106 if gname not in self.genome_names: | 1126 if gname not in self.genome_names: |
1107 # ignore if already there - eg for duplicates among pafs. | 1127 # ignore if already there - eg for duplicates among pafs. |
1108 useuri = pgpaths[i].startswith("http://") or pgpaths[i].startswith( | 1128 useuri = pgpaths[i].startswith("http://") or pgpaths[i].startswith( |
1109 "https://" | 1129 "https://" |
1110 ) | 1130 ) |
1111 asstrack = self.make_assembly(pgpaths[i], gname, useuri) | 1131 asstrack = self.make_assembly(pgpaths[i], gname, useuri) |
1112 self.genome_names.append(gname) | 1132 self.genome_names.append(gname) |
1113 if self.config_json.get("assemblies", None): | 1133 if self.config_json.get("assemblies", None): |
1114 self.config_json["assemblies"].append(asstrack) | 1134 self.config_json["assemblies"].append(asstrack) |
1115 else: | 1135 else: |
1116 self.config_json["assemblies"] = [ | 1136 self.config_json["assemblies"] = [ |
1117 asstrack, | 1137 asstrack, |
1118 ] | 1138 ] |
1119 url = "%s.paf" % (trackData["label"]) | 1139 url = "%s.paf" % (trackData["label"]) |
1120 dest = "%s/%s" % (self.outdir, url) | 1140 dest = "%s/%s" % (self.outdir, url) |
1121 self.symlink_or_copy(os.path.realpath(data), dest) | 1141 self.symlink_or_copy(os.path.realpath(data), dest) |
1122 trackDict = { | 1142 trackDict = { |
1123 "type": "SyntenyTrack", | 1143 "type": "SyntenyTrack", |
1129 "name": tname, | 1149 "name": tname, |
1130 "adapter": { | 1150 "adapter": { |
1131 "type": "PAFAdapter", | 1151 "type": "PAFAdapter", |
1132 "pafLocation": {"uri": url}, | 1152 "pafLocation": {"uri": url}, |
1133 "assemblyNames": passnames, | 1153 "assemblyNames": passnames, |
1134 }, | 1154 } |
1135 "displays": [ | 1155 } |
1136 { | 1156 style_json = { |
1137 "type": "LinearSyntenyDisplay", | 1157 "displays": [ |
1138 "displayId": "%s-LinearSyntenyDisplay" % tId, | 1158 { "type": "LinearBasicDisplay", |
1139 }, | 1159 "displayId": "%s-LinearBasicyDisplay" % trackDict["trackId"] |
1140 { | 1160 } |
1141 "type": "DotPlotDisplay", | 1161 ] |
1142 "displayId": "%s-DotPlotDisplay" % tId, | 1162 } |
1143 }, | 1163 trackDict["style"] = style_json |
1144 ], | |
1145 } | |
1146 self.tracksToAdd.append(trackDict) | 1164 self.tracksToAdd.append(trackDict) |
1147 self.trackIdlist.append(tId) | 1165 self.trackIdlist.append(tId) |
1148 | 1166 |
1149 def process_annotations(self, track): | 1167 def process_annotations(self, track): |
1150 category = track["category"].replace("__pd__date__pd__", TODAY) | 1168 category = track["category"].replace("__pd__date__pd__", TODAY) |
1282 logging.warn("### No style data in default data for %s" % tId) | 1300 logging.warn("### No style data in default data for %s" % tId) |
1283 style_data = {"type": "LinearBasicDisplay"} | 1301 style_data = {"type": "LinearBasicDisplay"} |
1284 if "displays" in track_conf: | 1302 if "displays" in track_conf: |
1285 disp = track_conf["displays"][0]["type"] | 1303 disp = track_conf["displays"][0]["type"] |
1286 style_data["type"] = disp | 1304 style_data["type"] = disp |
1287 style_data["configuration"] = "%s-%s" % (tId, disp) | |
1288 if track_conf.get("style_labels", None): | 1305 if track_conf.get("style_labels", None): |
1289 # TODO fix this: it should probably go in a renderer block (SvgFeatureRenderer) but still does not work | 1306 # TODO fix this: it should probably go in a renderer block (SvgFeatureRenderer) but still does not work |
1290 # TODO move this to per track displays? | 1307 # TODO move this to per track displays? |
1291 style_data["labels"] = track_conf["style_labels"] | 1308 style_data["labels"] = track_conf["style_labels"] |
1292 tracks_data.append( | 1309 tracks_data.append( |
1294 "type": track_types[tId], | 1311 "type": track_types[tId], |
1295 "configuration": tId, | 1312 "configuration": tId, |
1296 "displays": [style_data], | 1313 "displays": [style_data], |
1297 } | 1314 } |
1298 ) | 1315 ) |
1299 | |
1300 # The view for the assembly we're adding | 1316 # The view for the assembly we're adding |
1301 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} | 1317 view_json = {"type": "LinearGenomeView", "tracks": tracks_data} |
1302 | 1318 |
1303 refName = None | 1319 refName = None |
1304 drdict = { | 1320 drdict = { |
1532 track_conf["style"] = { | 1548 track_conf["style"] = { |
1533 item.tag: parse_style_conf(item) for item in track.find("options/style") | 1549 item.tag: parse_style_conf(item) for item in track.find("options/style") |
1534 } | 1550 } |
1535 else: | 1551 else: |
1536 track_conf["style"] = {} | 1552 track_conf["style"] = {} |
1537 tst = track_conf["style"].get("type", None) | |
1538 if tst: | |
1539 track_conf["style"]["configuration"] = "%s-%s" % (track_conf["label"], tst) | |
1540 if track.find("options/style_labels"): | 1553 if track.find("options/style_labels"): |
1541 track_conf["style_labels"] = { | 1554 track_conf["style_labels"] = { |
1542 item.tag: parse_style_conf(item) | 1555 item.tag: parse_style_conf(item) |
1543 for item in track.find("options/style_labels") | 1556 for item in track.find("options/style_labels") |
1544 } | 1557 } |
1563 "metadata/general/defaultLocation" | 1576 "metadata/general/defaultLocation" |
1564 ).text | 1577 ).text |
1565 default_session_data["session_name"] = root.find( | 1578 default_session_data["session_name"] = root.find( |
1566 "metadata/general/session_name" | 1579 "metadata/general/session_name" |
1567 ).text | 1580 ).text |
1581 logging.warn("default_session=%s" % (default_session_data)) | |
1568 jc.zipOut = root.find("metadata/general/zipOut").text == "true" | 1582 jc.zipOut = root.find("metadata/general/zipOut").text == "true" |
1569 general_data = { | 1583 general_data = { |
1570 "analytics": root.find("metadata/general/analytics").text, | 1584 "analytics": root.find("metadata/general/analytics").text, |
1571 "primary_color": root.find("metadata/general/primary_color").text, | 1585 "primary_color": root.find("metadata/general/primary_color").text, |
1572 "secondary_color": root.find("metadata/general/secondary_color").text, | 1586 "secondary_color": root.find("metadata/general/secondary_color").text, |