Mercurial > repos > fubar > jbrowse2
diff jbrowse2.py @ 92:3c4db8203fad draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit f2fba2e6b169256dc9adfa141e3bd59665f08f78
author | fubar |
---|---|
date | Sun, 21 Apr 2024 04:42:29 +0000 |
parents | 408781c080fc |
children | 4c517a0041a8 |
line wrap: on
line diff
--- a/jbrowse2.py Thu Apr 18 10:57:29 2024 +0000 +++ b/jbrowse2.py Sun Apr 21 04:42:29 2024 +0000 @@ -864,7 +864,7 @@ def add_bam(self, data, trackData, bam_indexes=None, **kwargs): tId = trackData["label"] - realFName = trackData["key"] + realFName = trackData["path"] useuri = trackData["useuri"].lower() == "yes" categ = trackData["category"] if useuri: @@ -872,36 +872,24 @@ else: fname = tId dest = "%s/%s" % (self.outdir, fname) + self.subprocess_check_call(["cp", data, dest]) url = fname bindex = fname + ".bai" - self.subprocess_check_call(["cp", data, dest]) - bi = bam_indexes.split() + bi = bam_indexes.split(",") bam_index = [ - x.split(",")[1].strip() + x.split(":")[1].strip() for x in bi - if "," in x and x.split(",")[0].strip() == realFName + if ":" in x and x.split(":")[0].strip() == realFName ] - if len(bam_index) > 0: - bam_index = bam_index[0] - else: - bam_index = None logging.debug( - "===realFName=%s got %s as bi, %s for bam_index" - % (realFName, bi, bam_index) + "===realFName=%s got %s as bam_indexes %s as bi, %s for bam_index" + % (realFName, bam_indexes, bi, bam_index) ) - if bam_index is not None and os.path.exists(bam_index): - if not os.path.exists(bindex): - # bai most probably made by galaxy and stored in galaxy dirs, need to copy it to dest - self.subprocess_check_call(["cp", bam_index, bindex]) - else: - # Can happen in exotic condition - # e.g. if bam imported as symlink with datatype=unsorted.bam, then datatype changed to bam - # => no index generated by galaxy, but there might be one next to the symlink target - # this trick allows to skip the bam sorting made by galaxy if already done outside - if os.path.exists(os.path.realpath(data) + ".bai"): - self.symlink_or_copy(os.path.realpath(data) + ".bai", bindex) - else: - log.warn("Could not find a bam index (.bai file) for %s", data) + if len(bam_index) > 0 and os.path.exists(os.path.realpath(bam_index[0])): + self.subprocess_check_call(["cp", bam_index[0], bindex]) + else: + cmd = ["samtools", "index", "-b", "-o", bindex, data] + self.subprocess_check_call(cmd) trackDict = { "type": "AlignmentsTrack", "trackId": tId, @@ -933,7 +921,7 @@ def add_cram(self, data, trackData, cram_indexes=None, **kwargs): tId = trackData["label"] - realFName = trackData["key"] + realFName = trackData["path"] categ = trackData["category"] useuri = trackData["useuri"].lower() == "yes" gsa = self.assmeta.get(trackData["assemblyNames"], None) @@ -949,25 +937,21 @@ dest = os.path.join(self.outdir, fname) url = fname self.subprocess_check_call(["cp", data, dest]) - ci = cram_indexes.split() + ci = cram_indexes.split(",") cram_index = [ - x.split(",")[1].strip() + x.split(":")[1].strip() for x in ci - if "," in x and x.split(",")[0] == realFName + if ":" in x and x.split(":")[0].strip() == realFName ] - if len(cram_index) > 0: - cram_index = cram_index[0] - else: - cram_index = None logging.debug( - "=== for %s got %s as cram_indexes, %s for cram_index" - % (realFName, cram_indexes, cram_index) + "===realFName=%s got %s as cram_indexes %s as ci, %s for cram_index" + % (realFName, cram_indexes, ci, cram_index) ) - if cram_index and os.path.exists(cram_index): + if len(cram_index) > 0 and os.path.exists(cram_index[0]): if not os.path.exists(dest + ".crai"): # most probably made by galaxy and stored in galaxy dirs, need to copy it to dest self.subprocess_check_call( - ["cp", os.path.realpath(cram_index), dest + ".crai"] + ["cp", os.path.realpath(cram_index[0]), dest + ".crai"] ) else: cpath = os.path.realpath(dest) + ".crai"