diff jbrowse2/jbrowse2.py @ 7:234cf4490901 draft

Uploaded
author fubar
date Fri, 05 Jan 2024 04:31:35 +0000
parents 88b9b105c09b
children 1e6128ccc82b
line wrap: on
line diff
--- a/jbrowse2/jbrowse2.py	Fri Jan 05 01:58:02 2024 +0000
+++ b/jbrowse2/jbrowse2.py	Fri Jan 05 04:31:35 2024 +0000
@@ -108,7 +108,7 @@
 
 
 class JbrowseConnector(object):
-    def __init__(self, jbrowse, outdir, genomes, standalone=None):
+    def __init__(self, jbrowse, outdir, genomes):
         self.debug = False
         self.usejson = True
         self.giURL = GALAXY_INFRASTRUCTURE_URL
@@ -116,7 +116,6 @@
         self.outdir = outdir
         os.makedirs(self.outdir, exist_ok=True)
         self.genome_paths = genomes
-        self.standalone = standalone
         self.trackIdlist = []
         self.tracksToAdd = []
         self.config_json = {}
@@ -174,46 +173,27 @@
             if self.debug:
                 log.info("genome_node=%s" % str(genome_node))
             genome_name = genome_node["meta"]["dataset_dname"]
-            dsId = genome_node["meta"]["dataset_id"]
             fapath = genome_node["path"]
-            if self.standalone == "complete":
-                faname = genome_name + ".fa.gz"
-                fadest = os.path.realpath(os.path.join(self.outdir, faname))
-                cmd = "bgzip -i -c %s > %s && samtools faidx %s" % (
-                    fapath,
-                    fadest,
-                    fadest,
-                )
-                self.subprocess_popen(cmd)
-                adapter = {
-                    "type": "BgzipFastaAdapter",
-                    "fastaLocation": {
-                        "uri": faname,
-                    },
-                    "faiLocation": {
-                        "uri": faname + ".fai",
-                    },
-                    "gziLocation": {
-                        "uri": faname + ".gzi",
-                    },
-                }
-            else:
-                faurl = "%s/api/datasets/%s/display" % (self.giURL, dsId)
-                faname = genome_name + ".fa.fai"
-                fastalocation = {
-                    "uri": faurl,
-                }
-                failocation = {
+            faname = genome_name + ".fa.gz"
+            fadest = os.path.realpath(os.path.join(self.outdir, faname))
+            cmd = "bgzip -i -c %s > %s && samtools faidx %s" % (
+                fapath,
+                fadest,
+                fadest,
+            )
+            self.subprocess_popen(cmd)
+            adapter = {
+                "type": "BgzipFastaAdapter",
+                "fastaLocation": {
                     "uri": faname,
-                }
-                adapter = {
-                    "type": "IndexedFastaAdapter",
-                    "fastaLocation": fastalocation,
-                    "faiLocation": failocation,
-                }
-
-                cmd = ["samtools", "faidx", fapath, "--fai-idx", faname]
-                self.subprocess_check_call(cmd)
+                },
+                "faiLocation": {
+                    "uri": faname + ".fai",
+                },
+                "gziLocation": {
+                    "uri": faname + ".gzi",
+                },
+            }
             trackDict = {
                 "name": genome_name,
                 "sequence": {
@@ -228,40 +208,23 @@
         if self.usejson:
             self.config_json["assemblies"] = assemblies
         else:
-            if self.standalone == "complete":
-                cmd = [
-                    "jbrowse",
-                    "add-assembly",
-                    faname,
-                    "-t",
-                    "bgzipFasta",
-                    "-n",
-                    genome_name,
-                    "--load",
-                    "inPlace",
-                    "--faiLocation",
-                    faname + ".fai",
-                    "--gziLocation",
-                    faname + ".gzi",
-                    "--target",
-                    self.outdir,
-                ]
-            else:
-                cmd = [
-                    "jbrowse",
-                    "add-assembly",
-                    faname,
-                    "-t",
-                    "indexedFasta",
-                    "-n",
-                    genome_name,
-                    "--load",
-                    "inPlace",
-                    "--faiLocation",
-                    faname + ".fai",
-                    "--target",
-                    self.outdir,
-                ]
+            cmd = [
+                "jbrowse",
+                "add-assembly",
+                faname,
+                "-t",
+                "bgzipFasta",
+                "-n",
+                genome_name,
+                "--load",
+                "inPlace",
+                "--faiLocation",
+                faname + ".fai",
+                "--gziLocation",
+                faname + ".gzi",
+                "--target",
+                self.outdir,
+            ]
             self.subprocess_check_call(cmd)
 
     def add_default_view(self):
@@ -279,7 +242,7 @@
             "-v",
             " LinearGenomeView",
         ]
-        if True or self.debug:
+        if self.debug:
             log.info("### calling set-default-session with cmd=%s" % "  ".join(cmd))
         self.subprocess_check_call(cmd)
 
@@ -311,19 +274,13 @@
             dsId,
         )
         hname = trackData["name"]
-        if self.standalone == "complete":
-            dest = os.path.realpath(os.path.join(self.outdir, hname))
-            url = hname
-            cmd = ["cp", data, dest]
-            self.subprocess_check_call(cmd)
-            floc = {
-                "uri": hname,
-            }
-        else:
-            url = "%s/api/datasets/%s/display?to_ext=hic" % (self.giURL, dsId)
-            floc = {
-                "uri": url,
-            }
+        dest = os.path.realpath(os.path.join(self.outdir, hname))
+        url = hname
+        cmd = ["cp", data, dest]
+        self.subprocess_check_call(cmd)
+        floc = {
+            "uri": hname,
+        }
         trackDict = {
             "type": "HicTrack",
             "trackId": tId,
@@ -509,15 +466,10 @@
 
     def add_bigwig(self, data, trackData):
         url = "%s.bw" % trackData["name"]
-        if self.standalone == "complete":
-            dest = os.path.realpath(os.path.join(self.outdir, url))
-            cmd = ["cp", data, dest]
-            self.subprocess_check_call(cmd)
-            bwloc = {"uri": url}
-        else:
-            dsId = trackData["metadata"]["dataset_id"]
-            url = "%s/api/datasets/%s/display?to_ext=fasta" % (self.giURL, dsId)
-            bwloc = {"uri": url}
+        dest = os.path.realpath(os.path.join(self.outdir, url))
+        cmd = ["cp", data, dest]
+        self.subprocess_check_call(cmd)
+        bwloc = {"uri": url}
         tId = trackData["label"]
         trackDict = {
             "type": "QuantitativeTrack",
@@ -562,15 +514,10 @@
         tId = trackData["label"]
         fname = "%s.bam" % trackData["label"]
         dest = os.path.realpath("%s/%s" % (self.outdir, fname))
-        if self.standalone == "complete":
-            url = fname
-            self.subprocess_check_call(["cp", data, dest])
-            log.info("### copied %s to %s" % (data, dest))
-            bloc = {"uri": url}
-        else:
-            dsId = trackData["metadata"]["dataset_id"]
-            url = "%s/api/datasets/%s/display?to_ext=bam" % (self.giURL, dsId)
-            bloc = {"uri": url}
+        url = fname
+        self.subprocess_check_call(["cp", data, dest])
+        log.info("### copied %s to %s" % (data, dest))
+        bloc = {"uri": url}
         if bam_index is not None and os.path.exists(os.path.realpath(bam_index)):
             # bai most probably made by galaxy and stored in galaxy dirs, need to copy it to dest
             self.subprocess_check_call(
@@ -926,6 +873,8 @@
         ]:
             cmd = ["rm", "-rf", os.path.join(self.outdir, fn)]
             self.subprocess_check_call(cmd)
+        cmd = ['cp', os.path.join(INSTALLED_TO, "servejb2.py"), self.outdir]
+        self.subprocess_check_call(cmd)
 
 
 if __name__ == "__main__":
@@ -934,11 +883,6 @@
 
     parser.add_argument("--jbrowse", help="Folder containing a jbrowse release")
     parser.add_argument("--outdir", help="Output directory", default="out")
-    parser.add_argument(
-        "--standalone",
-        choices=["complete", "minimal", "data"],
-        help="Standalone mode includes a copy of JBrowse",
-    )
     parser.add_argument("--version", "-V", action="version", version="%(prog)s 0.8.0")
     args = parser.parse_args()
 
@@ -963,7 +907,6 @@
             }
             for x in root.findall("metadata/genomes/genome")
         ],
-        standalone=args.standalone,
     )
     jc.process_genomes()