Mercurial > repos > fubar > jbrowse2
changeset 89:408781c080fc draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 03400b3f71140ce62dba0db266a1f7b94b6c1a11
author | fubar |
---|---|
date | Wed, 17 Apr 2024 22:18:47 +0000 |
parents | efd1d41f11b4 |
children | 51980e0dafd2 |
files | jbrowse2.py jbrowse2.xml macros.xml test-data/jbrowse2_result02.zip |
diffstat | 4 files changed, 103 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/jbrowse2.py Sun Apr 14 03:49:10 2024 +0000 +++ b/jbrowse2.py Wed Apr 17 22:18:47 2024 +0000 @@ -21,7 +21,8 @@ JB2VER = "v2.10.3" # version pinned if cloning - but not cloning now - +logCommands = True +# useful for seeing what's being written but not for production setups TODAY = datetime.datetime.now().strftime("%Y-%m-%d") SELF_LOCATION = os.path.dirname(os.path.realpath(__file__)) GALAXY_INFRASTRUCTURE_URL = None @@ -427,14 +428,19 @@ def subprocess_check_call(self, command, output=None, cwd=True): if output: - log.debug("cd %s && %s > %s", self.get_cwd(cwd), " ".join(command), output) + if logCommands: + log.debug( + "cd %s && %s > %s", self.get_cwd(cwd), " ".join(command), output + ) subprocess.check_call(command, cwd=self.get_cwd(cwd), stdout=output) else: - log.debug("cd %s && %s", self.get_cwd(cwd), " ".join(command)) + if logCommands: + log.debug("cd %s && %s", self.get_cwd(cwd), " ".join(command)) subprocess.check_call(command, cwd=self.get_cwd(cwd)) def subprocess_popen(self, command, cwd=True): - log.debug(command) + if logCommands: + log.debug(command) p = subprocess.Popen( command, cwd=self.get_cwd(cwd), @@ -452,7 +458,8 @@ raise RuntimeError("Command failed with exit code %s" % (retcode)) def subprocess_check_output(self, command): - log.debug(" ".join(command)) + if logCommands: + log.debug(" ".join(command)) return subprocess.check_output(command, cwd=self.outdir) def symlink_or_copy(self, src, dest): @@ -491,14 +498,14 @@ nrow = len(fl) except Exception: nrow = 0 - logging.debug("### getNrow returning %d" % nrow) + logging.debug("### getNrow %s returning %d" % (url, nrow)) return nrow def process_genomes(self, genomes): assembly = [] assmeta = [] useuri = False - genome_names = [] + primaryGenome = None for i, genome_node in enumerate(genomes): this_genome = {} if genome_node["useuri"] == "yes": @@ -509,17 +516,18 @@ if len(genome_name.split()) > 1: genome_name = genome_name.split()[0] # spaces and cruft break scripts when substituted - if genome_name not in genome_names: - # pafs with shared references + if not primaryGenome: + primaryGenome = genome_name + if genome_name not in self.genome_names: + self.genome_names.append(genome_name) fapath = genome_node["path"] if not useuri: fapath = os.path.realpath(fapath) assem, first_contig = self.make_assembly(fapath, genome_name, useuri) assembly.append(assem) self.ass_first_contigs.append(first_contig) - if len(genome_names) == 0: + if genome_name == primaryGenome: # first one this_genome["genome_name"] = genome_name # first one for all tracks - genome_names.append(genome_name) this_genome["genome_sequence_adapter"] = assem["sequence"][ "adapter" ] @@ -551,10 +559,9 @@ ) assmeta.append(this_genome) self.assemblies += assembly - self.assmeta[genome_names[0]] = assmeta - self.tracksToAdd[genome_names[0]] = [] - self.genome_names += genome_names - return this_genome["genome_name"] + self.assmeta[primaryGenome] = assmeta + self.tracksToAdd[primaryGenome] = [] + return primaryGenome def make_assembly(self, fapath, gname, useuri): """added code to grab the first contig name and length for broken default session from Anthony and Helena's code @@ -743,10 +750,11 @@ sampu = list(dict.fromkeys(samp)) samples = [x.split(".")[0] for x in sampu] samples.sort() - logging.debug( - "$$$$ cmd=%s, mafss=%s samp=%s samples=%s" - % (" ".join(cmd), mafss, samp, samples) - ) + if logCommands: + logging.debug( + "$$$$ cmd=%s, mafss=%s samp=%s samples=%s" + % (" ".join(cmd), mafss, samp, samples) + ) trackDict = { "type": "MafTrack", "trackId": tId, @@ -1172,34 +1180,28 @@ url = data nrow = self.getNrow(url) categ = trackData["category"] - pgnames = [x.strip() for x in pafOpts["genome_label"].split(",")] - pgpaths = [ - x.strip() for x in pafOpts["genome"].split(",") if len(x.strip()) > 0 - ] + pg = pafOpts["genome"].split(",") + pgc = [x.strip() for x in pg if x.strip() > ""] + gnomes = [x.split(":") for x in pgc] passnames = [trackData["assemblyNames"]] # always first - for i, gp in enumerate(pgpaths): - if len(pgnames[i].strip()) == 0: - # user may have left it blank - cannot make non-optional if want optional tracks. - gn = os.path.basename(gp) - pgnames[i] = os.path.splitext(gn)[0] - logging.debug( - "### add_paf got pafOpts=%s, pgnames=%s, pgpaths=%s for %s" - % (pafOpts, pgnames, pgpaths, tId) - ) - for i, gp in enumerate(pgpaths): - gname = pgnames[i] + for i, (gpath, gname) in enumerate(gnomes): + # may have been forgotten by user for uri + if len(gname) == 0: + gn = os.path.basename(gpath) + gname = os.path.splitext(gn)[0] + # trouble from spacey names in command lines avoidance if len(gname.split()) > 1: gname = gname.split()[0] - passnames.append(gname) - # trouble from spacey names in command lines avoidance - useuri = gp.startswith("http://") or gp.startswith("https://") - + if gname not in passnames: + passnames.append(gname) + useuri = gpath.startswith("http://") or gpath.startswith("https://") if gname not in self.genome_names: # ignore if already there - eg for duplicates among pafs. - asstrack, first_contig = self.make_assembly(gp, gname, useuri) + asstrack, first_contig = self.make_assembly(gpath, gname, useuri) self.genome_names.append(gname) self.tracksToAdd[gname] = [] self.assemblies.append(asstrack) + self.ass_first_contigs.append(first_contig) trackDict = { "type": "SyntenyTrack", "trackId": tId, @@ -1271,15 +1273,15 @@ outputTrackConfig["ext"] = dataset_ext outputTrackConfig["trackset"] = track.get("trackset", {}) - outputTrackConfig["label"] = "%s_%d.%s" % ( - track_human_label, - self.trackCounter, - dataset_ext, - ) - self.trackCounter += 1 + outputTrackConfig["label"] = track["label"] outputTrackConfig["metadata"] = extra_metadata outputTrackConfig["name"] = track_human_label - + if track["label"] in self.trackIdlist: + logging.error( + "### not adding %s already in %s" + % (track["label"], self.trackIdlist) + ) + yield None if dataset_ext in ("gff", "gff3"): self.add_gff( dataset_path, @@ -1416,9 +1418,6 @@ "minimized": False, "tracks": tracks_data, } - logging.debug( - "Looking for %s in self.ass_ %s" % (gnome, self.ass_first_contigs) - ) first = [x for x in self.ass_first_contigs if x[0] == gnome] if len(first) > 0: [gnome, refName, end] = first[0] @@ -1477,6 +1476,8 @@ def add_defsess_to_index(self, data): """ + PROBABLY NOW BROKEN by changes since this was deprecated temporarily as at April 18 + Included on request of the new codeowner, from Anthony's IUC PR. Had to be fixed to keep each assembly with the associated tracks for a default view. Originally used only the first assembly, putting all tracks there and so breaking some @@ -1626,6 +1627,7 @@ jc = JbrowseConnector(outdir=args.outdir, jbrowse2path=args.jbrowse2path) default_session_data = {} + trackI = 0 for ass in root.findall("assembly"): genomes = [ { @@ -1636,9 +1638,9 @@ } for x in ass.findall("metadata/genomes/genome") ] - assref_name = jc.process_genomes(genomes) - if not default_session_data.get(assref_name, None): - default_session_data[assref_name] = { + primaryGenome = jc.process_genomes(genomes) + if not default_session_data.get(primaryGenome, None): + default_session_data[primaryGenome] = { "tracks": [], "style": {}, "style_labels": {}, @@ -1650,7 +1652,7 @@ for track in ass.find("tracks"): track_conf = {} track_conf["trackfiles"] = [] - track_conf["assemblyNames"] = assref_name + track_conf["assemblyNames"] = primaryGenome is_multi_bigwig = False try: if track.find("options/wiggle/multibigwig") and ( @@ -1664,13 +1666,14 @@ trackfiles = track.findall("files/trackFile") if trackfiles: for x in trackfiles: - track_conf["label"] = x.attrib["label"] + track_conf["label"] = "%s_%d" % (x.attrib["label"], trackI) + trackI += 1 track_conf["useuri"] = x.attrib["useuri"] if is_multi_bigwig: multi_bigwig_paths.append( ( - x.attrib["label"], - x.attrib["useuri"], + track_conf["label"], + track_conf["useuri"], os.path.realpath(x.attrib["path"]), ) ) @@ -1685,7 +1688,7 @@ x.attrib["path"], x.attrib["ext"], x.attrib["useuri"], - x.attrib["label"], + track_conf["label"], metadata, ) else: @@ -1693,7 +1696,7 @@ os.path.realpath(x.attrib["path"]), x.attrib["ext"], x.attrib["useuri"], - x.attrib["label"], + track_conf["label"], metadata, ) track_conf["trackfiles"].append(tfa) @@ -1714,14 +1717,13 @@ track_conf["format"] = track.attrib["format"] track_conf["conf"] = etree_to_dict(track.find("options")) keys = jc.process_annotations(track_conf) - if keys: for key in keys: vis = track.attrib.get("visibility", "default_off") if not vis: vis = "default_off" - default_session_data[assref_name]["visibility"][vis].append(key) - trakdat = jc.tracksToAdd[assref_name] + default_session_data[primaryGenome]["visibility"][vis].append(key) + trakdat = jc.tracksToAdd[primaryGenome] stile = {} for trak in trakdat: if trak["trackId"] == key: @@ -1732,21 +1734,20 @@ for item in track.find("options/style") } stile.update(supdate) - default_session_data[assref_name]["style"][key] = stile - logging.debug("@@@ for %s got style=%s" % (key, stile)) + default_session_data[primaryGenome]["style"][key] = stile if track.find("options/style_labels"): - default_session_data[assref_name]["style_labels"][key] = { + default_session_data[primaryGenome]["style_labels"][key] = { item.tag: parse_style_conf(item) for item in track.find("options/style_labels") } - default_session_data[assref_name]["tracks"].append(key) + default_session_data[primaryGenome]["tracks"].append(key) default_session_data["defaultLocation"] = root.find( "metadata/general/defaultLocation" ).text default_session_data["session_name"] = root.find( "metadata/general/session_name" ).text - logging.debug("default_session=%s" % (default_session_data)) + logging.debug("default_session=%s" % (json.dumps(default_session_data, indent=2))) jc.zipOut = root.find("metadata/general/zipOut").text == "true" general_data = { "analytics": root.find("metadata/general/analytics").text, @@ -1759,12 +1760,28 @@ jc.add_general_configuration(general_data) trackconf = jc.config_json.get("tracks", []) for gnome in jc.genome_names: - trackconf += jc.tracksToAdd[gnome] + gtracks = jc.tracksToAdd[gnome] + if len(gtracks) > 0: + logging.debug( + "for genome %s adding gtracks %s" + % (gnome, json.dumps(gtracks, indent=2)) + ) + trackconf += gtracks jc.config_json["tracks"] = trackconf assconf = jc.config_json.get("assemblies", []) assconf += jc.assemblies jc.config_json["assemblies"] = assconf - logging.debug("assemblies=%s, gnames=%s" % (assconf, jc.genome_names)) + logging.debug( + "assmeta=%s, first_contigs=%s, assemblies=%s, gnames=%s, trackidlist=%s, tracks=%s" + % ( + jc.assmeta, + jc.ass_first_contigs, + json.dumps(assconf, indent=2), + jc.genome_names, + jc.trackIdlist, + json.dumps(trackconf, indent=2), + ) + ) jc.write_config() jc.add_default_session(default_session_data) # note that this can be left in the config.json but has NO EFFECT if add_defsess_to_index is called.
--- a/jbrowse2.xml Sun Apr 14 03:49:10 2024 +0000 +++ b/jbrowse2.xml Wed Apr 17 22:18:47 2024 +0000 @@ -263,25 +263,15 @@ #if $track.data_format.pafuseuri.insource == "history": <genome> #for $anno in $track.data_format.pafuseuri.annotation: - ${anno}, + ${anno}:${anno.name}, #end for </genome> - <genome_label> - #for $anno in $track.data_format.pafuseuri.annotation: - ${anno.name}, - #end for - </genome_label> #else: <genome> #for $refgenome in $track.data_format.pafuseuri.refuri: - $refgenome.annotation, + ${refgenome.annotation}:${refgenome.annoname}, #end for </genome> - <genome_label> - #for $refgenome in $track.data_format.pafuseuri.refuri: - ${refgenome.annoname}, - #end for - </genome_label> #end if </paf> #else if str($track.data_format.data_format_select) == "hic": @@ -477,7 +467,7 @@ <param type="hidden" name="uglyTestingHack" value="" /> </inputs> <outputs> - <data format="html" name="output" label="JBrowse2"> + <data format="html" name="output" label="JBrowse2: ${jbgen.session_name}"> <change_format> <when input="zipOut" value="true" format="zip" /> </change_format> @@ -643,6 +633,7 @@ </repeat> <section name="jbgen"> <param name="zipOut" value="true" /> + <param name="session_name" value="New test session"/> </section> <output name="output" file="jbrowse2_result02.zip" ftype="zip" compare="sim_size"> <assert_contents> @@ -656,25 +647,24 @@ <has_archive_member path="galaxy.xml"> <is_valid_xml /> <xml_element path="./metadata/general/session_name" n="1"> - <has_text_matching expression="New session"/> + <has_text_matching expression="New test session"/> <not_has_text text="Newton"/> </xml_element> </has_archive_member> - <has_archive_member path="merlin.gff3_0.gff3.gz"/> - <has_archive_member path="merlin.bw_1.bigwig"/> - <has_archive_member path="test-6.bed_2.bed.gz"/> - <has_archive_member path="merlin.vcf_3.vcf.tbi"/> - <has_archive_member path="merlin.cram_4.cram"/> - <has_archive_member path="merlin-sample.bam_5.bam"/> - <has_archive_member path="merlinlastz.maf_6.maf.sorted.bed.gz.tbi"/> - <has_archive_member path="merlin.blastxml_7.blastxml.gz"/> - <has_archive_member path="dm3test.cool_9.cool.hic"/> - <has_archive_member path="peach-grape-map.paf_10.paf"/> + <has_archive_member path="merlin.gff3_0.gz"/> + <has_archive_member path="merlin.bw_1"/> + <has_archive_member path="test-6.bed_2.gz"/> + <has_archive_member path="merlin.vcf_3.tbi"/> + <has_archive_member path="merlin.cram_4"/> + <has_archive_member path="merlin-sample.bam_5"/> + <has_archive_member path="merlinlastz.maf_6.sorted.bed.gz.tbi"/> + <has_archive_member path="merlin.blastxml_7.gz"/> + <has_archive_member path="dm3test.cool_9.hic"/> + <has_archive_member path="peach-grape-map.paf_10"/> <has_archive_member path="Merlin.fa.gz.fai"/> <has_archive_member path="config.json"> <has_json_property_with_text property="name" text="Merlin" /> </has_archive_member> - </assert_contents> </output> </test>
--- a/macros.xml Sun Apr 14 03:49:10 2024 +0000 +++ b/macros.xml Wed Apr 17 22:18:47 2024 +0000 @@ -28,8 +28,8 @@ <token name="@WRAPPER_VERSION@">galaxy2</token> <token name="@ATTRIBUTION@"><![CDATA[ **Attribution** -This Galaxy tool relies on the JBrowse2, maintained by the GMOD Community. The Galaxy wrapper is maintained by Ross Lazarus -until the IUC complete their own. +This Galaxy tool relies on the JBrowse2, maintained by the GMOD Community. The Galaxy wrapper is +maintained by Ross Lazarus and Bjoern Gruening until the IUC complete their own. ]]> </token> <xml name="genome_selector" @@ -157,7 +157,7 @@ <param label="Create a zip archive for downloading rather than viewing " name="zipOut" help="Default is to make an interactive browser appear when the 'eye' icon is activated" type="boolean" checked="false" truevalue="true" falsevalue="false" /> <param label="Subset to display to new users" type="text" name="defaultLocation" value="" help="Initial subset to be shown for users who have never visited the browser before. Example: 'ctgA:1234..5678'"/> - <param label="Session name" type="text" name="session_name" value="New session" help="Displayed at the top of the window"/> + <param label="Session name" type="text" name="session_name" value="New JB2 session" help="Displayed at the top of the window"/> <param label="Enable analytics" help="Will send usage data to Google Analytics, see https://github.com/GMOD/jbrowse-components/issues/1166" name="enableAnalytics" type="boolean" checked="false" truevalue="true" falsevalue="false" /> <param name="primary_color" type="color" label="Primary color" value="#0D233F">