changeset 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 6246925692cb
children 4c517a0041a8
files autogenJB2.py jbrowse2.py jbrowse2.xml
diffstat 3 files changed, 24 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/autogenJB2.py	Thu Apr 18 10:57:29 2024 +0000
+++ b/autogenJB2.py	Sun Apr 21 04:42:29 2024 +0000
@@ -143,7 +143,7 @@
                         sys.stdout.write("#### calling %s" % " ".join(cmd))
                         jc.subprocess_check_call(cmd)
                     track_conf.update(
-                        {"conf": {"options": {"bam": {"bam_index": " %s,%s " % (trackname,ipath)}}}}
+                        {"conf": {"options": {"bam": {"bam_index": " %s:%s," % (tpath,ipath)}}}}
                     )
                 elif trext == "cram":
                     ipath = track[3]
@@ -161,7 +161,7 @@
                         ]
                         jc.subprocess_check_call(cmd)
                     track_conf.update(
-                        {"conf": {"options": {"cram": {"cram_index": "%s,%s" % (trackname,ipath)}}}}
+                        {"conf": {"options": {"cram": {"cram_index": "%s:%s," % (tpath, ipath)}}}}
                     )
                 track_conf["path"] = tpath
                 track_conf["format"] = trext
--- 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"
--- a/jbrowse2.xml	Thu Apr 18 10:57:29 2024 +0000
+++ b/jbrowse2.xml	Sun Apr 21 04:42:29 2024 +0000
@@ -232,7 +232,7 @@
                             <bam>
                             <bam_index>
                                 #for $dataset in $track.data_format.useuri.annotation:
-                                    ${dataset.name},${dataset.metadata.bam_index}
+                                    ${dataset}:${dataset.metadata.bam_index},
                                 #end for
                             </bam_index>
                             </bam>
@@ -240,7 +240,7 @@
                             <cram>
                             <cram_index>
                                 #for $dataset in $track.data_format.useuri.annotation:
-                                    ${dataset.name},${dataset.metadata.cram_index}
+                                    ${dataset}:${dataset.metadata.cram_index},
                                 #end for
                             </cram_index>
                             </cram>