comparison jbrowse2.py @ 93:4c517a0041a8 draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit aeef2fbc0f90a9366851941ff51baeba410c56e4
author fubar
date Wed, 24 Apr 2024 02:29:32 +0000
parents 3c4db8203fad
children 74074746ccd8
comparison
equal deleted inserted replaced
92:3c4db8203fad 93:4c517a0041a8
17 from collections import defaultdict 17 from collections import defaultdict
18 18
19 logging.basicConfig(level=logging.DEBUG) 19 logging.basicConfig(level=logging.DEBUG)
20 log = logging.getLogger("jbrowse") 20 log = logging.getLogger("jbrowse")
21 21
22 JB2VER = "v2.10.3" 22 JB2VER = "v2.11.0"
23 # version pinned if cloning - but not cloning now 23 # version pinned if cloning - but not cloning now
24 logCommands = True 24 logCommands = True
25 # useful for seeing what's being written but not for production setups 25 # useful for seeing what's being written but not for production setups
26 TODAY = datetime.datetime.now().strftime("%Y-%m-%d") 26 TODAY = datetime.datetime.now().strftime("%Y-%m-%d")
27 SELF_LOCATION = os.path.dirname(os.path.realpath(__file__)) 27 SELF_LOCATION = os.path.dirname(os.path.realpath(__file__))
529 if genome_name == primaryGenome: # first one 529 if genome_name == primaryGenome: # first one
530 this_genome["genome_name"] = genome_name # first one for all tracks 530 this_genome["genome_name"] = genome_name # first one for all tracks
531 this_genome["genome_sequence_adapter"] = assem["sequence"][ 531 this_genome["genome_sequence_adapter"] = assem["sequence"][
532 "adapter" 532 "adapter"
533 ] 533 ]
534 this_genome["genome_firstcontig"] = None 534 this_genome["genome_firstcontig"] = first_contig
535 if not useuri:
536 fl = open(fapath, "r").readline()
537 fls = fl.strip().split(">")
538 if len(fls) > 1:
539 fl = fls[1]
540 if len(fl.split()) > 1:
541 this_genome["genome_firstcontig"] = fl.split()[
542 0
543 ].strip()
544 else:
545 this_genome["genome_firstcontig"] = fl
546 else:
547 try:
548 scontext = ssl.SSLContext(ssl.PROTOCOL_TLS)
549 scontext.verify_mode = ssl.VerifyMode.CERT_NONE
550 with urllib.request.urlopen(
551 url=fapath + ".fai", context=scontext
552 ) as f:
553 fl = f.readline()
554 except Exception:
555 fl = None
556 if fl: # is first row of the text fai so the first contig name
557 this_genome["genome_firstcontig"] = (
558 fl.decode("utf8").strip().split()[0]
559 )
560 assmeta.append(this_genome) 535 assmeta.append(this_genome)
561 self.assemblies += assembly 536 self.assemblies += assembly
562 self.assmeta[primaryGenome] = assmeta 537 self.assmeta[primaryGenome] = assmeta
563 self.tracksToAdd[primaryGenome] = [] 538 self.tracksToAdd[primaryGenome] = []
564 return primaryGenome 539 return primaryGenome
567 """added code to grab the first contig name and length for broken default session from Anthony and Helena's code 542 """added code to grab the first contig name and length for broken default session from Anthony and Helena's code
568 that poor Bjoern is trying to figure out. 543 that poor Bjoern is trying to figure out.
569 """ 544 """
570 if useuri: 545 if useuri:
571 faname = fapath 546 faname = fapath
572 adapter = {
573 "type": "BgzipFastaAdapter",
574 "fastaLocation": {"uri": faname, "locationType": "UriLocation"},
575 "faiLocation": {"uri": faname + ".fai", "locationType": "UriLocation"},
576 "gziLocation": {"uri": faname + ".gzi", "locationType": "UriLocation"},
577 }
578 scontext = ssl.SSLContext(ssl.PROTOCOL_TLS) 547 scontext = ssl.SSLContext(ssl.PROTOCOL_TLS)
579 scontext.verify_mode = ssl.VerifyMode.CERT_NONE 548 scontext.verify_mode = ssl.VerifyMode.CERT_NONE
580 with urllib.request.urlopen(url=faname + ".fai", context=scontext) as f: 549 with urllib.request.urlopen(url=faname + ".fai", context=scontext) as f:
581 fl = f.readline() 550 fl = f.readline()
582 contig = fl.decode("utf8").strip() 551 contig = fl.decode("utf8").strip()
589 fadest, 558 fadest,
590 fadest, 559 fadest,
591 fadest, 560 fadest,
592 ) 561 )
593 self.subprocess_popen(cmd) 562 self.subprocess_popen(cmd)
594
595 adapter = {
596 "type": "BgzipFastaAdapter",
597 "fastaLocation": {
598 "uri": faname,
599 },
600 "faiLocation": {
601 "uri": faname + ".fai",
602 },
603 "gziLocation": {
604 "uri": faname + ".gzi",
605 },
606 }
607 contig = open(fadest + ".fai", "r").readline().strip() 563 contig = open(fadest + ".fai", "r").readline().strip()
564 adapter = {
565 "type": "BgzipFastaAdapter",
566 "fastaLocation": {
567 "uri": faname,
568 },
569 "faiLocation": {
570 "uri": faname + ".fai",
571 },
572 "gziLocation": {
573 "uri": faname + ".gzi",
574 },
575 }
608 first_contig = contig.split()[:2] 576 first_contig = contig.split()[:2]
609 first_contig.insert(0, gname) 577 first_contig.insert(0, gname)
610 trackDict = { 578 trackDict = {
611 "name": gname, 579 "name": gname,
612 "sequence": { 580 "sequence": {
875 self.subprocess_check_call(["cp", data, dest]) 843 self.subprocess_check_call(["cp", data, dest])
876 url = fname 844 url = fname
877 bindex = fname + ".bai" 845 bindex = fname + ".bai"
878 bi = bam_indexes.split(",") 846 bi = bam_indexes.split(",")
879 bam_index = [ 847 bam_index = [
880 x.split(":")[1].strip() 848 x.split(" ~ ")[1].strip()
881 for x in bi 849 for x in bi
882 if ":" in x and x.split(":")[0].strip() == realFName 850 if " ~ " in x and x.split(" ~ ")[0].strip() == realFName
883 ] 851 ]
884 logging.debug( 852 logging.debug(
885 "===realFName=%s got %s as bam_indexes %s as bi, %s for bam_index" 853 "===realFName=%s got %s as bam_indexes %s as bi, %s for bam_index"
886 % (realFName, bam_indexes, bi, bam_index) 854 % (realFName, bam_indexes, bi, bam_index)
887 ) 855 )
937 dest = os.path.join(self.outdir, fname) 905 dest = os.path.join(self.outdir, fname)
938 url = fname 906 url = fname
939 self.subprocess_check_call(["cp", data, dest]) 907 self.subprocess_check_call(["cp", data, dest])
940 ci = cram_indexes.split(",") 908 ci = cram_indexes.split(",")
941 cram_index = [ 909 cram_index = [
942 x.split(":")[1].strip() 910 x.split(" ~ ")[1].strip()
943 for x in ci 911 for x in ci
944 if ":" in x and x.split(":")[0].strip() == realFName 912 if " ~ " in x and x.split(" ~ ")[0].strip() == realFName
945 ] 913 ]
946 logging.debug( 914 logging.debug(
947 "===realFName=%s got %s as cram_indexes %s as ci, %s for cram_index" 915 "===realFName=%s got %s as cram_indexes %s as ci, %s for cram_index"
948 % (realFName, cram_indexes, ci, cram_index) 916 % (realFName, cram_indexes, ci, cram_index)
949 ) 917 )
1164 url = data 1132 url = data
1165 nrow = self.getNrow(url) 1133 nrow = self.getNrow(url)
1166 categ = trackData["category"] 1134 categ = trackData["category"]
1167 pg = pafOpts["genome"].split(",") 1135 pg = pafOpts["genome"].split(",")
1168 pgc = [x.strip() for x in pg if x.strip() > ""] 1136 pgc = [x.strip() for x in pg if x.strip() > ""]
1169 gnomes = [x.split(":") for x in pgc] 1137 gnomes = [x.split(" ~ ") for x in pgc]
1138 logging.debug("pg=%s, gnomes=%s" % (pg, gnomes))
1170 passnames = [trackData["assemblyNames"]] # always first 1139 passnames = [trackData["assemblyNames"]] # always first
1171 for i, (gpath, gname) in enumerate(gnomes): 1140 for i, (gpath, gname) in enumerate(gnomes):
1172 # may have been forgotten by user for uri 1141 # may have been forgotten by user for uri
1173 if len(gname) == 0: 1142 if len(gname) == 0:
1174 gn = os.path.basename(gpath) 1143 gn = os.path.basename(gpath)
1176 # trouble from spacey names in command lines avoidance 1145 # trouble from spacey names in command lines avoidance
1177 if len(gname.split()) > 1: 1146 if len(gname.split()) > 1:
1178 gname = gname.split()[0] 1147 gname = gname.split()[0]
1179 if gname not in passnames: 1148 if gname not in passnames:
1180 passnames.append(gname) 1149 passnames.append(gname)
1181 useuri = gpath.startswith("http://") or gpath.startswith("https://") 1150 useuri = pafOpts["useuri"] == "true"
1182 if gname not in self.genome_names: 1151 if gname not in self.genome_names:
1183 # ignore if already there - eg for duplicates among pafs. 1152 # ignore if already there - eg for duplicates among pafs.
1184 asstrack, first_contig = self.make_assembly(gpath, gname, useuri) 1153 asstrack, first_contig = self.make_assembly(gpath, gname, useuri)
1185 self.genome_names.append(gname) 1154 self.genome_names.append(gname)
1186 self.tracksToAdd[gname] = [] 1155 self.tracksToAdd[gname] = []
1614 trackI = 0 1583 trackI = 0
1615 for ass in root.findall("assembly"): 1584 for ass in root.findall("assembly"):
1616 genomes = [ 1585 genomes = [
1617 { 1586 {
1618 "path": x.attrib["path"], 1587 "path": x.attrib["path"],
1619 "label": x.attrib["label"], 1588 "label": x.attrib["label"].split(" ")[0].replace(",", ""),
1620 "useuri": x.attrib["useuri"], 1589 "useuri": x.attrib["useuri"],
1621 "meta": metadata_from_node(x.find("metadata")), 1590 "meta": metadata_from_node(x.find("metadata")),
1622 } 1591 }
1623 for x in ass.findall("metadata/genomes/genome") 1592 for x in ass.findall("metadata/genomes/genome")
1624 ] 1593 ]
1648 pass 1617 pass
1649 1618
1650 trackfiles = track.findall("files/trackFile") 1619 trackfiles = track.findall("files/trackFile")
1651 if trackfiles: 1620 if trackfiles:
1652 for x in trackfiles: 1621 for x in trackfiles:
1653 track_conf["label"] = "%s_%d" % (x.attrib["label"], trackI) 1622 track_conf["label"] = "%s_%d" % (
1623 x.attrib["label"].replace(" ", "_").replace(",", ""),
1624 trackI,
1625 )
1654 trackI += 1 1626 trackI += 1
1655 track_conf["useuri"] = x.attrib["useuri"] 1627 track_conf["useuri"] = x.attrib["useuri"]
1656 if is_multi_bigwig: 1628 if is_multi_bigwig:
1657 multi_bigwig_paths.append( 1629 multi_bigwig_paths.append(
1658 ( 1630 (