comparison jbrowse2.py @ 63:ac00dcfb5d1d draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit f450a9a7bec7ae695a85a061bf59956b73196976
author fubar
date Thu, 28 Mar 2024 07:46:04 +0000
parents ab0d6782a95f
children 497fd2d27aa2
comparison
equal deleted inserted replaced
62:ab0d6782a95f 63:ac00dcfb5d1d
13 import tempfile 13 import tempfile
14 import urllib.request 14 import urllib.request
15 import xml.etree.ElementTree as ET 15 import xml.etree.ElementTree as ET
16 from collections import defaultdict 16 from collections import defaultdict
17 17
18 logging.basicConfig(level=logging.DEBUG) 18 logging.basicConfig(level=logging.INFO)
19 log = logging.getLogger("jbrowse") 19 log = logging.getLogger("jbrowse")
20 20
21 JB2VER = "v2.10.3" 21 JB2VER = "v2.10.3"
22 # version pinned for cloning 22 # version pinned for cloning
23 23
491 else: 491 else:
492 this_genome["genome_firstcontig"] = fl 492 this_genome["genome_firstcontig"] = fl
493 else: 493 else:
494 try: 494 try:
495 fl = urllib.request.urlopen(fapath + ".fai").readline() 495 fl = urllib.request.urlopen(fapath + ".fai").readline()
496 except: 496 except Exception:
497 fl = None 497 fl = None
498 if fl: # is first row of the text fai so the first contig name 498 if fl: # is first row of the text fai so the first contig name
499 this_genome["genome_firstcontig"] = ( 499 this_genome["genome_firstcontig"] = (
500 fl.decode("utf8").strip().split()[0] 500 fl.decode("utf8").strip().split()[0]
501 ) 501 )
620 """ 620 """
621 tId = trackData["label"] 621 tId = trackData["label"]
622 # can be served - if public. 622 # can be served - if public.
623 # dsId = trackData["metadata"]["dataset_id"] 623 # dsId = trackData["metadata"]["dataset_id"]
624 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId) 624 # url = "%s/api/datasets/%s/display?to_ext=hic " % (self.giURL, dsId)
625 hic_path = trackData.get("hic_path", None)
626 useuri = trackData["useuri"].lower() == "yes" 625 useuri = trackData["useuri"].lower() == "yes"
627 if useuri: 626 if useuri:
628 uri = data 627 uri = data
629 else: 628 else:
630 uri = "%s.hic" % trackData["label"] 629 uri = "%s.hic" % trackData["label"]
680 mafss = [x for x in mafs if (x.startswith("s\t") or x.startswith("s "))] 679 mafss = [x for x in mafs if (x.startswith("s\t") or x.startswith("s "))]
681 samp = [x.split()[1] for x in mafss if len(x.split()) > 0] 680 samp = [x.split()[1] for x in mafss if len(x.split()) > 0]
682 sampu = list(dict.fromkeys(samp)) 681 sampu = list(dict.fromkeys(samp))
683 samples = [x.split(".")[0] for x in sampu] 682 samples = [x.split(".")[0] for x in sampu]
684 samples.sort() 683 samples.sort()
685 logging.warn( 684 logging.debug(
686 "$$$$ cmd=%s, mafss=%s samp=%s samples=%s" 685 "$$$$ cmd=%s, mafss=%s samp=%s samples=%s"
687 % (" ".join(cmd), mafss, samp, samples) 686 % (" ".join(cmd), mafss, samp, samples)
688 ) 687 )
689 trackDict = { 688 trackDict = {
690 "type": "MafTrack", 689 "type": "MafTrack",
735 str(min_gap), 734 str(min_gap),
736 xml, 735 xml,
737 ] 736 ]
738 subprocess.check_call(cmd, cwd=self.outdir, stdout=gff3_unrebased) 737 subprocess.check_call(cmd, cwd=self.outdir, stdout=gff3_unrebased)
739 gff3_unrebased.close() 738 gff3_unrebased.close()
740 logging.warn("### blastxml to gff3 cmd = %s" % " ".join(cmd)) 739 logging.debug("### blastxml to gff3 cmd = %s" % " ".join(cmd))
741 return gff3_unrebased.name 740 return gff3_unrebased.name
742 741
743 def add_blastxml(self, data, trackData, blastOpts, **kwargs): 742 def add_blastxml(self, data, trackData, blastOpts, **kwargs):
744 gff3 = self._blastxml_to_gff3(data, min_gap=blastOpts["min_gap"]) 743 gff3 = self._blastxml_to_gff3(data, min_gap=blastOpts["min_gap"])
745 if "parent" in blastOpts and blastOpts["parent"] != "None": 744 if "parent" in blastOpts and blastOpts["parent"] != "None":
747 cmd = ["python", os.path.join(INSTALLED_TO, "gff3_rebase.py")] 746 cmd = ["python", os.path.join(INSTALLED_TO, "gff3_rebase.py")]
748 if blastOpts.get("protein", "false") == "true": 747 if blastOpts.get("protein", "false") == "true":
749 cmd.append("--protein2dna") 748 cmd.append("--protein2dna")
750 cmd.extend([os.path.realpath(blastOpts["parent"]), gff3]) 749 cmd.extend([os.path.realpath(blastOpts["parent"]), gff3])
751 subprocess.check_call(cmd, cwd=self.outdir, stdout=gff3_rebased) 750 subprocess.check_call(cmd, cwd=self.outdir, stdout=gff3_rebased)
752 logging.warn("### gff3rebase cmd = %s" % " ".join(cmd)) 751 logging.debug("### gff3rebase cmd = %s" % " ".join(cmd))
753 gff3_rebased.close() 752 gff3_rebased.close()
754 # Replace original gff3 file 753 # Replace original gff3 file
755 shutil.copy(gff3_rebased.name, gff3) 754 shutil.copy(gff3_rebased.name, gff3)
756 os.unlink(gff3_rebased.name) 755 os.unlink(gff3_rebased.name)
757 url = "%s.gff3.gz" % trackData["label"] 756 url = "%s.gff3.gz" % trackData["label"]
1305 for track_conf in self.tracksToAdd[gnome]: 1304 for track_conf in self.tracksToAdd[gnome]:
1306 tId = track_conf["trackId"] 1305 tId = track_conf["trackId"]
1307 track_types[tId] = track_conf["type"] 1306 track_types[tId] = track_conf["type"]
1308 style_data = default_data["style"].get(tId, None) 1307 style_data = default_data["style"].get(tId, None)
1309 if not style_data: 1308 if not style_data:
1310 logging.warn( 1309 logging.debug(
1311 "### No style data in default data %s for %s" 1310 "### No style data in default data %s for %s"
1312 % (default_data, tId) 1311 % (default_data, tId)
1313 ) 1312 )
1314 style_data = {"type": "LinearBasicDisplay"} 1313 style_data = {"type": "LinearBasicDisplay"}
1315 if "displays" in track_conf: 1314 if "displays" in track_conf:
1486 "useuri": x.attrib["useuri"], 1485 "useuri": x.attrib["useuri"],
1487 "meta": metadata_from_node(x.find("metadata")), 1486 "meta": metadata_from_node(x.find("metadata")),
1488 } 1487 }
1489 for x in ass.findall("metadata/genomes/genome") 1488 for x in ass.findall("metadata/genomes/genome")
1490 ] 1489 ]
1491 logging.warn("#!!! genomes=%s" % genomes)
1492 assref_name = jc.process_genomes(genomes) 1490 assref_name = jc.process_genomes(genomes)
1493 1491
1494 for track in ass.find("tracks"): 1492 for track in ass.find("tracks"):
1495 track_conf = {} 1493 track_conf = {}
1496 track_conf["trackfiles"] = [] 1494 track_conf["trackfiles"] = []