changeset 60:81d535970196 draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 403a35e1245fa5e62f4be6116a725b9e4d9c353a
author fubar
date Mon, 25 Mar 2024 02:10:05 +0000
parents f807e219cec3
children e7a6f7a7148d
files autogenJB2.py jbrowse2.py jbrowse2.xml macros.xml
diffstat 4 files changed, 84 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/autogenJB2.py	Fri Mar 22 22:04:08 2024 +0000
+++ b/autogenJB2.py	Mon Mar 25 02:10:05 2024 +0000
@@ -172,8 +172,7 @@
                     for key in keys:
                         if trext in [
                             "bigwig",
-                            "gff3",
-                            "gff",
+                            "gff", "gff3",
                             "vcf",
                             "maf",
                         ]:
@@ -182,6 +181,16 @@
                             default_session_data["visibility"]["default_off"].append(
                                 key
                             )
+                        if trext in ["gff", "gff3", "bed", "vcf", "maf", "blastxml"]:
+                            ttype = "LinearBasicDisplay"
+                            if trext == "vcf":
+                                ttype = "LinearVariantDisplay"
+                            style_json = {
+                            "type": ttype,
+                            "trackShowLabels": False,
+                            "trackShowDescriptions": False
+                            }
+                            default_session_data["style"][key] = style_json
             # general_data = {
             # "analytics": root.find("metadata/general/analytics").text,
             # "primary_color": root.find("metadata/general/primary_color").text,
--- a/jbrowse2.py	Fri Mar 22 22:04:08 2024 +0000
+++ b/jbrowse2.py	Mon Mar 25 02:10:05 2024 +0000
@@ -1,5 +1,5 @@
  #!/usr/bin/env python
-# change to accumulating all configuration for config.json based on the default from the clone
+
 import argparse
 import binascii
 import datetime
@@ -24,8 +24,6 @@
 TODAY = datetime.datetime.now().strftime("%Y-%m-%d")
 GALAXY_INFRASTRUCTURE_URL = None
 
-# version pinned for cloning
-
 mapped_chars = {
     ">": "__gt__",
     "<": "__lt__",
@@ -458,7 +456,7 @@
                 genome_name = genome_name.split()[0]
                 # spaces and cruft break scripts when substituted
             if genome_name not in self.genome_names:
-                # ignore dupes - can have multiple pafs with same references?
+                # pafs with shared references
                 fapath = genome_node["path"]
                 if not useuri:
                     fapath = os.path.realpath(fapath)
@@ -467,7 +465,7 @@
                 self.genome_names.append(genome_name)
                 if self.genome_name is None:
                     self.genome_name = (
-                        genome_name  # first one for all tracks - other than paf
+                        genome_name  # first one for all tracks
                     )
                     self.genome_sequence_adapter = assem["sequence"]["adapter"]
                     self.genome_firstcontig = None
@@ -481,11 +479,16 @@
                             else:
                                 self.genome_firstcontig = fl
                     else:
-                        fl = urllib.request.urlopen(fapath + ".fai").readline()
+                        try:
+                            fl = urllib.request.urlopen(fapath + ".fai").readline()
+                        except:
+                            fl = None
                         if fl:  # is first row of the text fai so the first contig name
                             self.genome_firstcontig = (
                                 fl.decode("utf8").strip().split()[0]
                             )
+                        else:
+                            self.genome_firstcontig = None
         if self.config_json.get("assemblies", None):
             self.config_json["assemblies"] += assemblies
         else:
@@ -606,6 +609,8 @@
             gziLocation:
             uri: 'https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/fasta/GRCh38.fa.gz.gzi',
         Cool will not be likely to be a good fit - see discussion at https://github.com/GMOD/jbrowse-components/issues/2438
+
+
         """
         tId = trackData["label"]
         # can be served - if public.
@@ -615,29 +620,25 @@
         if useuri:
             uri = data
         else:
-            uri = trackData["hic_url"]
+            uri = "%s.hic" % trackData["label"]
+            # slashes in names cause path trouble
+            dest = os.path.join(self.outdir, uri)
+            cmd = ["cp", data, dest]
+            self.subprocess_check_call(cmd)
         categ = trackData["category"]
         trackDict = {
             "type": "HicTrack",
             "trackId": tId,
-            "name": uri,
+            "name":  trackData["name"],
             "assemblyNames": [self.genome_name],
             "category": [
                 categ,
             ],
             "adapter": {
                 "type": "HicAdapter",
-                "hicLocation": uri,
-            },
-            "displays": [
-                {
-                    "type": "LinearHicDisplay",
-                    "displayId": "%s-LinearHicDisplay" % tId,
-                },
-            ],
+                "hicLocation": { "uri": uri }
+            }
         }
-        style_json = self._prepare_track_style(trackDict)
-        trackDict["style"] = style_json
         self.tracksToAdd.append(trackDict)
         self.trackIdlist.append(tId)
 
@@ -793,14 +794,6 @@
         os.unlink(gff3)
 
     def add_bigwig(self, data, trackData):
-        """ "type": "LinearWiggleDisplay",
-        "configuration": {},
-        "selectedRendering": "",
-        "resolution": 1,
-        "posColor": "rgb(228, 26, 28)",
-        "negColor": "rgb(255, 255, 51)",
-        "constraints": {}
-        """
         useuri = trackData["useuri"].lower() == "yes"
         if useuri:
             url = data
@@ -1278,26 +1271,23 @@
 
     def add_default_session(self, default_data):
         """
-        Add some default session settings: set some assemblies/tracks on/off
+        default session settings are hard and fragile.
+        .add_default_view() and other configuration code adapted from
+         https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py
         """
         tracks_data = []
-
         # TODO using the default session for now, but check out session specs in the future https://github.com/GMOD/jbrowse-components/issues/2708
-
-        # We need to know the track type from the config.json generated just before
         track_types = {}
         with open(self.config_json_file, "r") as config_file:
             config_json = json.load(config_file)
         if self.config_json:
             config_json.update(self.config_json)
-
         for track_conf in self.tracksToAdd:
-            track_types[track_conf["trackId"]] = track_conf["type"]
             tId = track_conf["trackId"]
-            #if tId in data["visibility"]["default_on"]:
+            track_types[tId] = track_conf["type"]
             style_data = default_data["style"].get(tId,  None)
             if not style_data:
-                logging.warn("### No style data in default data for %s" % tId)
+                logging.warn("### No style data in default data %s for %s" % (default_data, tId))
                 style_data = {"type": "LinearBasicDisplay"}
             if "displays" in track_conf:
                 disp = track_conf["displays"][0]["type"]
@@ -1315,7 +1305,7 @@
             )
         # The view for the assembly we're adding
         view_json = {"type": "LinearGenomeView", "tracks": tracks_data}
-
+        logging.warn("### view_json=%s" % view_json)
         refName = None
         drdict = {
             "reversed": False,
@@ -1408,8 +1398,10 @@
         with open(config_path, "w") as config_file:
             json.dump(self.config_json, config_file, indent=2)
 
-    def clone_jbrowse(self, realclone=True):
-        """Clone a JBrowse directory into a destination directory. This also works in Biocontainer testing now"""
+    def clone_jbrowse(self, realclone=False):
+        """Clone a JBrowse directory into a destination directory. This also works in Biocontainer testing now
+        Leave as True between version updates on temporary tools - requires manual conda trigger :(
+        """
         dest = self.outdir
         if realclone:
             self.subprocess_check_call(
@@ -1472,7 +1464,6 @@
     )
     jc.process_genomes()
 
-    # .add_default_view() replace from https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py
     default_session_data = {
         "visibility": {
             "default_on": [],
@@ -1500,6 +1491,7 @@
         if trackfiles:
             for x in track.findall("files/trackFile"):
                 track_conf["label"] = x.attrib["label"]
+                trackkey = track_conf["label"]
                 track_conf["useuri"] = x.attrib["useuri"]
                 if is_multi_bigwig:
                     multi_bigwig_paths.append(
@@ -1544,18 +1536,6 @@
             )
         track_conf["category"] = track.attrib["cat"]
         track_conf["format"] = track.attrib["format"]
-        if track.find("options/style"):
-            track_conf["style"] = {
-                item.tag: parse_style_conf(item) for item in track.find("options/style")
-            }
-        else:
-            track_conf["style"] = {}
-        if track.find("options/style_labels"):
-            track_conf["style_labels"] = {
-                item.tag: parse_style_conf(item)
-                for item in track.find("options/style_labels")
-            }
-
         track_conf["conf"] = etree_to_dict(track.find("options"))
         track_conf["category"] = track.attrib["cat"]
         track_conf["format"] = track.attrib["format"]
@@ -1566,12 +1546,20 @@
                 default_session_data["visibility"][
                     track.attrib.get("visibility", "default_off")
                 ].append(key)
-                if track_conf.get("style", None):
-                    default_session_data["style"][key] = track_conf["style"]
-                if track_conf.get("style_lables", None):
-                    default_session_data["style_labels"][key] = track_conf.get(
-                        "style_labels", None
-                    )
+            if track.find("options/style"):
+                default_session_data["style"][key] = {
+                    item.tag: parse_style_conf(item) for item in track.find("options/style")
+                }
+                logging.warn("### added %s to defsess %s for %s" % (trackkey, default_session_data, key ))
+            else:
+                default_session_data["style"][key] = {}
+                logging.warn("@@@@ no options/style found for %s" % (key))
+
+            if track.find("options/style_labels"):
+                default_session_data["style_labels"][key] = {
+                    item.tag: parse_style_conf(item)
+                    for item in track.find("options/style_labels")
+                }
     default_session_data["defaultLocation"] = root.find(
         "metadata/general/defaultLocation"
     ).text
--- a/jbrowse2.xml	Fri Mar 22 22:04:08 2024 +0000
+++ b/jbrowse2.xml	Mon Mar 25 02:10:05 2024 +0000
@@ -11,12 +11,8 @@
     <version_command>python '${__tool_directory__}/jbrowse2.py' --version</version_command>
     <command detect_errors="aggressive"><![CDATA[
 mkdir -p '$output.files_path' &&
-## Copy the XML file into the directory, mostly for debugging
-## but nice if users want to reproduce locally
 cp '$trackxml' '$output.files_path/galaxy.xml' &&
-
 export JBROWSE2_PATH=\$(dirname \$(which jbrowse))/../opt/jbrowse2  &&
-
 #if $jbgen.ucol.formcoll=="collect":
     python '$__tool_directory__/autogenJB2.py'
     #for $key in $autoCollection.keys():
@@ -139,17 +135,15 @@
         #for $tg in $track_groups:
             #for $track in $tg.data_tracks:
                 #if $track.data_format.useuri.insource == "uri":
-                    <track cat="${tg.category}" format="paf" visibility="${track.data_format.track_visibility}">
+                    <track cat="${tg.category}" format="${track.data_format.data_format_select}" visibility="${track.data_format.track_visibility}">
                         <files>
-                             <trackFile path="${ $track.data_format.useuri.insource.annouri}" ext="paf"
-                                label="${track.data_format.useuri.insource.annoname}" useuri="yes">
+                             <trackFile path="${track.data_format.useuri.annouri}" ext="${track.data_format.data_format_select}"
+                                label="${track.data_format.useuri.annoname}" useuri="yes">
                                 <metadata>
-                                <dataset id = "${track.data_format.useuri.insource.annouri}" />
+                                <dataset id = "${track.data_format.useuri.annouri}" />
                                 </metadata>
                              </trackFile>
                         </files>
-                        <options/>
-                    </track>
                 #else if $track.data_format.useuri.insource == "history":
                     #if $track.data_format.useuri.annotation:
                     <track cat="${tg.category}" format="${track.data_format.data_format_select}" visibility="${track.data_format.track_visibility}">
@@ -157,7 +151,6 @@
                         #for $dataset in $track.data_format.useuri.annotation:
                               <trackFile path="${dataset}" ext="${dataset.ext}" label="${dataset.name}" useuri="no">
                                 <metadata>
-
                                   <dataset id="${__app__.security.encode_id($dataset.id)}" hid="${dataset.hid}"
                                       size="${dataset.get_size(nice_size=True)}"
                                       edam_format="${dataset.datatype.edam_format}"
@@ -193,23 +186,27 @@
                               </trackFile>
                        #end for
                     </files>
-
-                    <options>
-                        <style>
-                        #if str($track.data_format.data_format_select) in ["gff", "bed", "vcf", "maf", "blastxml"]:
-                            <type>${track.data_format.jbstyle.track_style.display}</type>
-                            #if str($track.data_format.jbstyle.track_style.display) in ["LinearBasicDisplay", "LinearVariantDisplay"]:
-                                <trackShowLabels>${track.data_format.jbstyle.track_style.show_labels}</trackShowLabels>
-                                <trackShowDescriptions>${track.data_format.jbstyle.track_style.show_descriptions}</trackShowDescriptions>
-                            #end if
+                    #end if
+                  #end if
+                  <options>
+                    <style>
+                    #if str($track.data_format.data_format_select) in ["gff", "bed", "vcf", "maf", "blastxml"]:
+                        <type>${track.data_format.jbstyle.track_style.display}</type>
+                        #if str($track.data_format.jbstyle.track_style.display) in ["LinearBasicDisplay", "LinearVariantDisplay"]:
+                            <trackShowLabels>${track.data_format.jbstyle.track_style.show_labels}</trackShowLabels>
+                            <trackShowDescriptions>${track.data_format.jbstyle.track_style.show_descriptions}</trackShowDescriptions>
                         #end if
-                        #if str($track.data_format.data_format_select) in ["bam", "cram"]:
-                            <type>LinearAlignmentsDisplay</type>
-                        #end if
-                        #if str($track.data_format.data_format_select) in ["paf"]:
-                            <type>LinearBasicDisplay</type>
-                        #end if
-                        </style>
+                    #end if
+                    #if str($track.data_format.data_format_select) in ["bam", "cram"]:
+                        <type>LinearAlignmentsDisplay</type>
+                    #end if
+                    #if str($track.data_format.data_format_select) in ["paf"]:
+                        <type>LinearBasicDisplay</type>
+                    #end if
+                    #if str($track.data_format.data_format_select) in ["hic"]:
+                        <type>LinearHicDisplay</type>
+                    #end if
+                    </style>
                     #if str($track.data_format.data_format_select) == "bam":
                         <bam>
                             #for $dataset in $track.data_format.useuri.annotation:
@@ -268,8 +265,6 @@
                     #end if
                     </options>
                   </track>
-                  #end if
-                #end if
             #end for
         #end for
     </tracks>
--- a/macros.xml	Fri Mar 22 22:04:08 2024 +0000
+++ b/macros.xml	Mon Mar 25 02:10:05 2024 +0000
@@ -542,12 +542,12 @@
     <xml name="pafref_conditional" token_label="Track Data" token_format="data">
         <conditional name="pafuseuri">
                 <param name="insource" type="select" label="PAF reference data from a history file or an internet URI?"
-                    help="A public URI implies that all the associated tabix files are also in place. They are created for history files">
-                    <option value="history" selected="true">PAF genome reference data from a history file</option>
-                    <option value="uri">PAF genome reference data from tabix data URI - index files must be available at corresponding URI</option>
+                    help="Multiple references can be used for mashmap PAF. A URI source requires all the associated tabix index files to be in place.">
+                    <option value="history" selected="true">PAF reference comparison genome from a history file</option>
+                    <option value="uri">PAF reference comparison genome tabix .gz URI with index files at the corresponding URIs</option>
                 </param>
                 <when value="history">
-                    <repeat name="refgenomes" title="Add one or more comparison genomes used to make the PAF">
+                    <repeat name="refgenomes" title="PAF reference comparison genome used to make the PAF">
                        <param label="@LABEL@" format="@FORMAT@" name="annotation" multiple="True" optional="true" type="data" />
                        <param label="Short name for track display" name="annoname" type="text" >
                              <sanitizer invalid_char="_">
@@ -559,7 +559,7 @@
                     </repeat>
                 </when>
                 <when value="uri">
-                    <repeat name="refgenomes" title="Provide URI for a comparison genomesused to make the PAF">
+                    <repeat name="refgenomes" title="PAF reference comparison genome URI">
                        <param label="@LABEL@" name="annotation"  type="text" />
                        <param label="Short name for track display" name="annoname" type="text" >
                              <sanitizer invalid_char="_">