From 0761afdfd358c7348574464b587bef423b245605 Mon Sep 17 00:00:00 2001 From: "Louwen, Nico" Date: Wed, 13 Sep 2023 09:51:58 +0200 Subject: [PATCH 01/18] Add query_bgc input validation --- src/parameters/input.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/parameters/input.py b/src/parameters/input.py index e406eaa6..576bdef9 100644 --- a/src/parameters/input.py +++ b/src/parameters/input.py @@ -67,6 +67,7 @@ def validate(self): validate_input_mode(self.input_mode) validate_pfam(self.pfam_path) validate_reference(self.reference_dir) + validate_query_bgc(self.query_bgc_path) validate_cds_overlap_cutoff(self.cds_overlap_cutoff) @@ -94,6 +95,19 @@ def validate_reference(reference_dir): raise InvalidArgumentError("--reference_dir", reference_dir) +def validate_query_bgc(query_bgc_path): + """Validates the query_gbc_path property""" + + # given single query bgc file, file must exist + if query_bgc_path and not query_bgc_path.exists(): + logging.error("Query BGC file does not exist!") + raise InvalidArgumentError("--query_bgc_path", query_bgc_path) + + if query_bgc_path and not query_bgc_path.is_file(): + logging.error("Query BGC file is not a file!") + raise InvalidArgumentError("--query_bgc_path", query_bgc_path) + + def validate_input_dir(input_dir): """Validates the gbk_dir property""" if input_dir is None: From 721c5e5e8c56d2bc73901159b1debd4be10aa694 Mon Sep 17 00:00:00 2001 From: "Louwen, Nico" Date: Wed, 13 Sep 2023 10:02:28 +0200 Subject: [PATCH 02/18] query_bgc validation tests --- test/parameters/test_validation.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/parameters/test_validation.py b/test/parameters/test_validation.py index b75a71b4..7264d5f8 100644 --- a/test/parameters/test_validation.py +++ b/test/parameters/test_validation.py @@ -11,6 +11,7 @@ from src.parameters.input import ( validate_input_dir, validate_input_mode, + validate_query_bgc, validate_cds_overlap_cutoff, ) from src.parameters.hmmer import validate_includelist, validate_hsp_overlap_cutoff @@ -70,6 +71,20 @@ def test_validate_cds_overlap_cutoff_high(self): """ self.assertRaises(InvalidArgumentError, validate_cds_overlap_cutoff, 2.0) + def test_validate_query_bgc_path_not_exist(self): + """Tests whether validate_query_bgc raises an exception if the given path does + not exist""" + missing_file_path = Path("test/test_data/non_existent_path") + + self.assertRaises(InvalidArgumentError, validate_query_bgc, missing_file_path) + + def test_validate_query_bgc_path_not_a_file(self): + """Tests whether validate_query_bgc raises and exception if the given path is + not a file""" + not_a_file_path = Path("test/test_data/") + + self.assertRaises(InvalidArgumentError, validate_query_bgc, not_a_file_path) + class TestHMMerValidation(TestCase): """Contains tests on the HMMer validation functions""" From 2dc2ab089423f7404bc7c52324b3fc2f13972bfa Mon Sep 17 00:00:00 2001 From: "Louwen, Nico" Date: Wed, 20 Sep 2023 15:36:26 +0200 Subject: [PATCH 03/18] minor formatting --- .../output/html_content/js/bigscape.js | 435 +++++++++--------- 1 file changed, 219 insertions(+), 216 deletions(-) diff --git a/src/output/html_template/output/html_content/js/bigscape.js b/src/output/html_template/output/html_content/js/bigscape.js index 9058128d..004e7807 100644 --- a/src/output/html_template/output/html_content/js/bigscape.js +++ b/src/output/html_template/output/html_content/js/bigscape.js @@ -35,7 +35,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con for (var j in bs_data[i]["orfs"]) { for (var k in bs_data[i]["orfs"][j]["domains"]) { var pfam = bs_data[i]["orfs"][j]["domains"][k]["code"]; - var bspf = bs_pfam.find(function(bsp){ return bsp["code"] === pfam; }); + var bspf = bs_pfam.find(function (bsp) { return bsp["code"] === pfam; }); if (bspf === undefined) { bspf = { idx: bs_pfam.length, code: pfam, bgc: [i] }; bs_pfam.push(bspf); @@ -56,23 +56,23 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con var sprLen = 100; var layout = Viva.Graph.Layout.forceDirected(graph, { springLength: sprLen, - springCoeff : 0.001, - gravity : -1, + springCoeff: 0.001, + gravity: -1, springTransform: function (link, spring) { spring.length = sprLen - (sprLen * (link.data.weight)); } }); var renderer = Viva.Graph.View.renderer(graph, { container: net_ui[0], - layout : layout, - graphics : graphics, + layout: layout, + graphics: graphics, interactive: 'node drag' }); // var desc_ui = $("
"); var desc_btn = $(""); - desc_btn.click(function(handler){ + desc_btn.click(function (handler) { if ($(handler.target).hasClass("active")) { $(handler.target).removeClass("active"); $(handler.target).parent().removeClass("active"); @@ -81,7 +81,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con $(handler.target).addClass("active"); $(handler.target).parent().addClass("active"); desc_ui.removeClass("hidden"); - desc_ui.find("svg.arrower-svg").each(function(){ + desc_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -95,7 +95,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con var search_ui = $("
"); var search_bar = $(""); var search_result_ui = $(""); - search_bar.keyup({ bigscape: bigscape, bs_data: bs_data, bs_families: bs_families, bs_pfam: bs_pfam, search_result_ui: search_result_ui }, function(handler) { + search_bar.keyup({ bigscape: bigscape, bs_data: bs_data, bs_families: bs_families, bs_pfam: bs_pfam, search_result_ui: search_result_ui }, function (handler) { var keyword = handler.target.value; var bigscape = handler.data.bigscape; if (keyword.length > 0) { @@ -126,7 +126,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con } } var div_bgcfam = $("
" + res_bgcfam.length + " Families (select)
"); - div_bgcfam.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_bgcfam }, function(handler){ + div_bgcfam.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_bgcfam }, function (handler) { handler.data.bigscape.setHighlightedNodes(handler.data.sels); handler.data.bigscape.highlightNodes(handler.data.sels); handler.data.bigscape.updateDescription(handler.data.sels); @@ -141,7 +141,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con sels_bgc.push(parseInt(res_bgc[i]["item"])); } var div_bgc = $("
" + sels_bgc.length + " BGCs (select)
"); - div_bgc.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_bgc }, function(handler){ + div_bgc.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_bgc }, function (handler) { handler.data.bigscape.setHighlightedNodes(handler.data.sels); handler.data.bigscape.highlightNodes(handler.data.sels); handler.data.bigscape.updateDescription(handler.data.sels); @@ -162,7 +162,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con } } var div_pfam = $("
" + res_pfam.length + " PFams (select)
"); - div_pfam.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_pfam }, function(handler){ + div_pfam.find("a.selectbgcs").click({ bigscape: bigscape, sels: sels_pfam }, function (handler) { handler.data.bigscape.setHighlightedNodes(handler.data.sels); handler.data.bigscape.highlightNodes(handler.data.sels); handler.data.bigscape.updateDescription(handler.data.sels); @@ -182,14 +182,14 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con // var info_ui = $("
"); var info_btn = $(""); - info_btn.click(function(handler){ + info_btn.click(function (handler) { if ($(handler.target).hasClass("active")) { $(handler.target).removeClass("active"); info_ui.addClass("hidden"); } else { $(handler.target).addClass("active"); info_ui.removeClass("hidden"); - info_ui.find("svg.arrower-svg").each(function(){ + info_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -204,7 +204,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con nav_ui.append("
"); nav_ui.append("
"); var nav_btn = $(""); - nav_btn.click(function(handler){ + nav_btn.click(function (handler) { if ($(handler.target).hasClass("active")) { $(handler.target).removeClass("active"); nav_ui.addClass("hidden"); @@ -222,7 +222,7 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con net_ui.after(""); var det_ui = $("
"); var det_btn = $(""); - det_btn.click(function(handler){ + det_btn.click(function (handler) { $(handler.target).parent().addClass("hidden"); handler.stopPropagation(); }); @@ -237,30 +237,30 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con net_ui.parent().find(".hover-container").append(hover_ui); // window clicks - document.addEventListener('keydown', function(e) { + document.addEventListener('keydown', function (e) { if (e.which === 16 && !multiSelectOverlay) { // shift key multiSelectOverlay = BigscapeFunc.startMultiSelect(graph, graphics, renderer, layout, bigscape); net_ui.css("cursor", "crosshair"); } }); - document.addEventListener('keyup', function(e) { + document.addEventListener('keyup', function (e) { if (e.which === 16 && multiSelectOverlay) { multiSelectOverlay.destroy(); multiSelectOverlay = null; net_ui.css("cursor", "default"); } }); - net_ui.parent().contextmenu(function(handler) { + net_ui.parent().contextmenu(function (handler) { handler.preventDefault(); handler.stopPropagation(); }); - net_ui.click({ context_ui: context_ui, bigscape: bigscape }, function(handler) { + net_ui.click({ context_ui: context_ui, bigscape: bigscape }, function (handler) { if (!handler.data.context_ui.hasClass("hidden")) { handler.data.context_ui.addClass("hidden"); } handler.stopPropagation(); }); - net_ui.mousedown({ bigscape: bigscape }, function(handler) { + net_ui.mousedown({ bigscape: bigscape }, function (handler) { if (handler.which === 1) { // left click if (!multiSelectOverlay) { handler.data.bigscape.setHighlightedNodes([]); @@ -271,38 +271,38 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con } } }); - net_ui.mouseup({ bigscape: bigscape }, function(handler) { + net_ui.mouseup({ bigscape: bigscape }, function (handler) { if (handler.which === 1) { // left click if (!multiSelectOverlay) { $(handler.target).css("cursor", "default"); } } }); - net_ui.bind('mousewheel DOMMouseScroll', {renderer: renderer}, function(handler) { + net_ui.bind('mousewheel DOMMouseScroll', { renderer: renderer }, function (handler) { if (multiSelectOverlay) { if (handler.originalEvent.wheelDelta > 0 || handler.originalEvent.detail < 0) { handler.data.renderer.zoomIn(); - } else { - handler.data.renderer.zoomOut(); - } - handler.stopPropagation(); + } else { + handler.data.renderer.zoomOut(); + } + handler.stopPropagation(); } }); // options - var intra_cutoff = options.intra_cutoff? options.intra_cutoff : 0; - var inter_cutoff = options.inter_cutoff? options.inter_cutoff : 0.25; - var fam_colors = options.fam_colors? options.fam_colors : []; + var intra_cutoff = options.intra_cutoff ? options.intra_cutoff : 0; + var inter_cutoff = options.inter_cutoff ? options.inter_cutoff : 0.25; + var fam_colors = options.fam_colors ? options.fam_colors : []; // public functions - var showSingletons = function(isOn) { BigscapeFunc.showSingletons(graph, graphics, net_ui, isOn); }; + var showSingletons = function (isOn) { BigscapeFunc.showSingletons(graph, graphics, net_ui, isOn); }; this.showSingletons = showSingletons; - var highlightNodes = function(ids) { BigscapeFunc.highlightNodes(graph, graphics, ids, bs_svg, bs_data, bs_to_cl, bs_families, net_ui, desc_ui); }; + var highlightNodes = function (ids) { BigscapeFunc.highlightNodes(graph, graphics, ids, bs_svg, bs_data, bs_to_cl, bs_families, net_ui, desc_ui); }; this.highlightNodes = highlightNodes; - this.setHighlightedNodes = function(ids) { highlighted_nodes = ids; }; - this.getHighlightedNodes = function() { return highlighted_nodes; }; - var updateDescription = function(ids = highlighted_nodes) { + this.setHighlightedNodes = function (ids) { highlighted_nodes = ids; }; + this.getHighlightedNodes = function () { return highlighted_nodes; }; + var updateDescription = function (ids = highlighted_nodes) { BigscapeFunc.updateDescription(ids, bs_svg, bs_data, bs_to_cl, bs_families, bs_similarity, bs_alignment, desc_ui, nav_ui, det_ui, bigscape); }; this.updateDescription = updateDescription; @@ -313,9 +313,9 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con } for (var c = 0; c < bs_families.length; c++) { if (c >= fam_colors.length) { - fam_colors.push('rgb('+Math.round(Math.random()*256)+','+ - Math.round(Math.random()*256)+','+ - Math.round(Math.random()*256)+')'); + fam_colors.push('rgb(' + Math.round(Math.random() * 256) + ',' + + Math.round(Math.random() * 256) + ',' + + Math.round(Math.random() * 256) + ')'); } for (var i = 0; i < bs_families[c]["members"].length; i++) { var a = bs_families[c]["members"][i]; @@ -335,35 +335,35 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con continue; } var weight = bs_similarity[a][b]; - graph.addLink(a, b, {weight: weight}); + graph.addLink(a, b, { weight: weight }); } } } // set nodes & links behavior & appearance - graphics.node(function(node) { - var ui = Viva.Graph.svg('circle') - .attr('r', 10) - .attr('fill', (fam_colors[bs_to_cl[node.id]])); - if (bs_data[node.id]["mibig"]) { - ui.attr("stroke", "blue"); - ui.attr("stroke-width", "4px"); - } - $(ui).hover(function() { // mouse over - var temp_highlight = []; - for (var i in highlighted_nodes) { - temp_highlight.push(highlighted_nodes[i]); - } - if (temp_highlight.indexOf(node.id) < 0) { - temp_highlight.push(node.id); + graphics.node(function (node) { + var ui = Viva.Graph.svg('circle') + .attr('r', 10) + .attr('fill', (fam_colors[bs_to_cl[node.id]])); + if (bs_data[node.id]["mibig"]) { + ui.attr("stroke", "blue"); + ui.attr("stroke-width", "4px"); } - highlightNodes(temp_highlight); - updateDescription(temp_highlight); - }, function() { // mouse out - highlightNodes(highlighted_nodes); - updateDescription(highlighted_nodes); - }); - $(ui).click(function(handler){ + $(ui).hover(function () { // mouse over + var temp_highlight = []; + for (var i in highlighted_nodes) { + temp_highlight.push(highlighted_nodes[i]); + } + if (temp_highlight.indexOf(node.id) < 0) { + temp_highlight.push(node.id); + } + highlightNodes(temp_highlight); + updateDescription(temp_highlight); + }, function () { // mouse out + highlightNodes(highlighted_nodes); + updateDescription(highlighted_nodes); + }); + $(ui).click(function (handler) { if (highlighted_nodes.indexOf(node.id) > -1) { highlighted_nodes.splice(highlighted_nodes.indexOf(node.id), 1); } else { @@ -373,15 +373,15 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con updateDescription(highlighted_nodes); handler.stopPropagation(); }); - $(ui).contextmenu({id: node.id, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_similarity: bs_similarity, bs_to_cl: bs_to_cl, det_ui: det_ui, context_ui: context_ui}, function(handler) { + $(ui).contextmenu({ id: node.id, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_similarity: bs_similarity, bs_to_cl: bs_to_cl, det_ui: det_ui, context_ui: context_ui }, function (handler) { var ul = $("
    "); // var aShowDetail = $("Show details"); - aShowDetail.click({id: handler.data.id, bs_svg: handler.data.bs_svg, bs_data: handler.data.bs_data, bs_families: handler.data.bs_families, bs_to_cl: handler.data.bs_to_cl, det_ui: handler.data.det_ui, context_ui: handler.data.context_ui}, function(handler){ + aShowDetail.click({ id: handler.data.id, bs_svg: handler.data.bs_svg, bs_data: handler.data.bs_data, bs_families: handler.data.bs_families, bs_to_cl: handler.data.bs_to_cl, det_ui: handler.data.det_ui, context_ui: handler.data.context_ui }, function (handler) { BigscapeFunc.openDetail(handler.data.id, handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.det_ui); handler.data.context_ui.addClass("hidden"); handler.data.det_ui.parent().removeClass("hidden"); - handler.data.det_ui.find("svg.arrower-svg").each(function(){ + handler.data.det_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -390,11 +390,11 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con ($("
  • ").appendTo(ul)).append(aShowDetail); // var aShowFamDetail = $("Show family details"); - aShowFamDetail.click({id: handler.data.id, id_fam: bs_to_cl[handler.data.id], bs_svg: handler.data.bs_svg, bs_data: handler.data.bs_data, bs_families: handler.data.bs_families, bs_similarity: handler.data.bs_similarity, bs_to_cl: handler.data.bs_to_cl, det_ui: handler.data.det_ui, context_ui: handler.data.context_ui}, function(handler){ + aShowFamDetail.click({ id: handler.data.id, id_fam: bs_to_cl[handler.data.id], bs_svg: handler.data.bs_svg, bs_data: handler.data.bs_data, bs_families: handler.data.bs_families, bs_similarity: handler.data.bs_similarity, bs_to_cl: handler.data.bs_to_cl, det_ui: handler.data.det_ui, context_ui: handler.data.context_ui }, function (handler) { BigscapeFunc.openFamDetail(handler.data.id_fam, [handler.data.id], handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.bs_similarity, handler.data.det_ui);; handler.data.context_ui.addClass("hidden"); handler.data.det_ui.parent().removeClass("hidden"); - handler.data.det_ui.find("svg.arrower-svg").each(function(){ + handler.data.det_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -412,35 +412,35 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con handler.data.context_ui.append("

    " + handler.data.bs_data[handler.data.id]["id"] + "

    "); handler.data.context_ui.append(ul); handler.data.context_ui.css({ - top: handler.pageY + "px", - left: handler.pageX + "px", + top: handler.pageY + "px", + left: handler.pageX + "px", }); handler.data.context_ui.removeClass("hidden"); handler.stopPropagation(); }); - $(ui).mouseenter({id: node.id, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, hover_ui: hover_ui}, function(handler){ + $(ui).mouseenter({ id: node.id, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, hover_ui: hover_ui }, function (handler) { handler.data.hover_ui.html("" + handler.data.bs_data[handler.data.id]["id"]); if (handler.data.bs_data[handler.data.id].hasOwnProperty("desc")) { handler.data.hover_ui.append("" + "
    " + handler.data.bs_data[handler.data.id]["desc"]); } handler.data.hover_ui.parent().css({ - top: (handler.pageY - handler.data.hover_ui.parent().height() - 20) + "px", - left: (handler.pageX) + "px", + top: (handler.pageY - handler.data.hover_ui.parent().height() - 20) + "px", + left: (handler.pageX) + "px", }); handler.data.hover_ui.parent().removeClass("hidden"); }); - $(ui).mouseleave({hover_ui: hover_ui}, function(handler){ + $(ui).mouseleave({ hover_ui: hover_ui }, function (handler) { handler.data.hover_ui.parent().addClass("hidden"); }); - return ui; - }).placeNode(function(nodeUI, pos){ + return ui; + }).placeNode(function (nodeUI, pos) { nodeUI.attr('cx', pos.x).attr('cy', pos.y); }); - graphics.link(function(link) { + graphics.link(function (link) { return Viva.Graph.svg('line') - .attr("stroke", "#777") - .attr("stroke-width", link["data"]["weight"] * 10); + .attr("stroke", "#777") + .attr("stroke-width", link["data"]["weight"] * 10); }); // run renderer and forceDirected layout @@ -452,20 +452,22 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con var perZoom = 5; var zoomCount = 0; info_ui.append("
    Adjusting network layout for... " + countDown + " second(s)
    "); - var interval = setInterval(function(){ + var interval = setInterval(function () { countDown--; if (countDown >= 0) { info_ui.find(".network-layout-counter").text(countDown); var scale = 3 * (graphics.getSvgRoot().getElementsByTagName("g")[0].getBoundingClientRect().width / graphics.getSvgRoot().getBoundingClientRect().width); - var point = {x: graphics.getSvgRoot().getBoundingClientRect().width / 2, - y: graphics.getSvgRoot().getBoundingClientRect().height / 2}; + var point = { + x: graphics.getSvgRoot().getBoundingClientRect().width / 2, + y: graphics.getSvgRoot().getBoundingClientRect().height / 2 + }; if (scale !== 0) { graphics.scale((1 / scale), point); } } else { info_ui.html(""); var nodes_with_edges_count = 0; - graph.forEachNode(function(node) { + graph.forEachNode(function (node) { if (node.links.length > 0) { nodes_with_edges_count++; } @@ -474,20 +476,21 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con info_ui.append("
    Total BGCs: " + graph.getNodesCount() + " (" + singleton_count + " singleton/s), links: " + graph.getLinksCount() + ", families: " + bs_families.length + "
    "); if (singleton_count > 0) { var checkbox = $("
    Singletons
    "); - checkbox.find("input[type=checkbox]").change(function() { showSingletons($(this).is(":checked")); }); + checkbox.find("input[type=checkbox]").change(function () { showSingletons($(this).is(":checked")); }); nav_ui.find(".show-singletons").html(checkbox); } renderer.pause(); clearInterval(interval); - }}, 1000); + } + }, 1000); - return this; + return this; } // input: VivaGraph graph object, network container jQuery object, on/off -BigscapeFunc.showSingletons = function(graph, graphics, net_ui, isOn) { +BigscapeFunc.showSingletons = function (graph, graphics, net_ui, isOn) { if (!isOn) { // show - graph.forEachNode(function(node){ + graph.forEachNode(function (node) { if (node.links.length < 1) { var node_ui = graphics.getNodeUI(node.id); $(node_ui).addClass("hidden"); @@ -499,14 +502,14 @@ BigscapeFunc.showSingletons = function(graph, graphics, net_ui, isOn) { } // ... -BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_families, bs_similarity, bs_alignment, desc_ui, nav_ui, det_ui, bigscape) { +BigscapeFunc.updateDescription = function (ids, bs_svg, bs_data, bs_to_cl, bs_families, bs_similarity, bs_alignment, desc_ui, nav_ui, det_ui, bigscape) { if (desc_ui.children().length < 1) { // first time rendering desc_ui desc_ui.html(""); // top part of the desc_ui var top = $("
    "); var showCompBtn = $("details").appendTo($("
    ").appendTo(top)); - showCompBtn.click({bigscape: bigscape, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_alignment: bs_alignment, bs_to_cl: bs_to_cl, desc_ui: desc_ui, det_ui: det_ui}, function(handler){ + showCompBtn.click({ bigscape: bigscape, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_alignment: bs_alignment, bs_to_cl: bs_to_cl, desc_ui: desc_ui, det_ui: det_ui }, function (handler) { var rendered_ids = handler.data.bigscape.getHighlightedNodes(); BigscapeFunc.openCompDetail(rendered_ids, handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.bs_alignment, handler.data.det_ui); handler.data.det_ui.parent().removeClass("hidden"); @@ -515,7 +518,7 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam var compDiv = $("
    "); top.append(compDiv); var showHideDomainBtn = $("").prependTo($("
    domains
    ").appendTo(top)); - showHideDomainBtn.change({ top: top }, function(handler){ + showHideDomainBtn.change({ top: top }, function (handler) { BigscapeFunc.showHideDomains(handler.data.top, $(handler.target).is(":checked")); handler.stopPropagation(); }); @@ -523,7 +526,7 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam // bottom part of the desc_ui var bot = $("
    "); var filterList = $("
    Filter: all selected
    "); - filterList.change({bigscape: bigscape}, function(handler){ + filterList.change({ bigscape: bigscape }, function (handler) { var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); handler.data.bigscape.updateDescription(); }); @@ -532,10 +535,10 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam var li = $("
  • "); li.append(""); li.append("" + bs_families[i]["id"] + ""); - li.find("a.li-opendetail").click({id_fam: i, ids_highlighted: ids, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui, bs_similarity: bs_similarity}, function(handler){ + li.find("a.li-opendetail").click({ id_fam: i, ids_highlighted: ids, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui, bs_similarity: bs_similarity }, function (handler) { BigscapeFunc.openFamDetail(handler.data.id_fam, handler.data.ids_highlighted, handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.bs_similarity, handler.data.det_ui); handler.data.det_ui.parent().removeClass("hidden"); - handler.data.det_ui.find("svg.arrower-svg").each(function(){ + handler.data.det_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -546,7 +549,7 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam }); handler.stopPropagation(); }); - li.find("a.li-check").click({bigscape: bigscape, fam: bs_families[i]}, function(handler) { + li.find("a.li-check").click({ bigscape: bigscape, fam: bs_families[i] }, function (handler) { var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); var isChecked = false; if (handler.data.fam.hasOwnProperty("members")) { @@ -581,24 +584,24 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam handler.data.bigscape.highlightNodes(highlighted_nodes); handler.data.bigscape.updateDescription(highlighted_nodes); }); - li.find("a").mouseenter({bigscape: bigscape, fam: bs_families[i]}, function(handler) { // mouse over + li.find("a").mouseenter({ bigscape: bigscape, fam: bs_families[i] }, function (handler) { // mouse over var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); var temp_highlight = []; for (var i in highlighted_nodes) { - temp_highlight.push(highlighted_nodes[i]); + temp_highlight.push(highlighted_nodes[i]); } if (handler.data.fam.hasOwnProperty("members")) { for (i in handler.data.fam.members) { var id = handler.data.fam.members[i]; if (temp_highlight.indexOf(id) < 0) { - temp_highlight.push(id); + temp_highlight.push(id); } } } handler.data.bigscape.highlightNodes(temp_highlight); handler.data.bigscape.updateDescription(temp_highlight); }); - li.find("a").mouseout({bigscape: bigscape}, function(handler) { // mouse out + li.find("a").mouseout({ bigscape: bigscape }, function (handler) { // mouse out var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); handler.data.bigscape.highlightNodes(highlighted_nodes); handler.data.bigscape.updateDescription(highlighted_nodes); @@ -613,16 +616,16 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam if (bs_data[id]["mibig"]) { linktext.addClass("mibig"); } - lii.find("a.li-opendetail").click({id: id, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui}, function(handler){ + lii.find("a.li-opendetail").click({ id: id, bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui }, function (handler) { BigscapeFunc.openDetail(handler.data.id, handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.det_ui); handler.data.det_ui.parent().removeClass("hidden"); - handler.data.det_ui.find("svg.arrower-svg").each(function(){ + handler.data.det_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); handler.stopPropagation(); }); - lii.find("a.li-check").click({bigscape: bigscape, id: id}, function(handler) { + lii.find("a.li-check").click({ bigscape: bigscape, id: id }, function (handler) { var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); if (highlighted_nodes.indexOf(handler.data.id) < 0) { highlighted_nodes.push(handler.data.id); @@ -633,20 +636,20 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam handler.data.bigscape.highlightNodes(highlighted_nodes); handler.data.bigscape.updateDescription(highlighted_nodes); }); - lii.find("a").mouseenter({bigscape: bigscape, id: id}, function(handler) { // mouse over + lii.find("a").mouseenter({ bigscape: bigscape, id: id }, function (handler) { // mouse over var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); var temp_highlight = []; var id = handler.data.id; for (var i in highlighted_nodes) { - temp_highlight.push(highlighted_nodes[i]); + temp_highlight.push(highlighted_nodes[i]); } if (temp_highlight.indexOf(id) < 0) { - temp_highlight.push(id); + temp_highlight.push(id); } handler.data.bigscape.highlightNodes(temp_highlight); handler.data.bigscape.updateDescription(temp_highlight); }); - lii.find("a").mouseout({bigscape: bigscape}, function(handler) { // mouse out + lii.find("a").mouseout({ bigscape: bigscape }, function (handler) { // mouse out var highlighted_nodes = handler.data.bigscape.getHighlightedNodes(); handler.data.bigscape.highlightNodes(highlighted_nodes); handler.data.bigscape.updateDescription(highlighted_nodes); @@ -664,7 +667,7 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam // calculate variables var rendered_ids = []; - desc_ui.find(".bs-desc_ui-svg").each(function(idx, elm){ + desc_ui.find(".bs-desc_ui-svg").each(function (idx, elm) { rendered_ids.push(parseInt($(elm).attr("id").split("-")[3])); }); var sel_fam = []; @@ -678,7 +681,7 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam fam_sels[bs_to_cl[id]].push(id); } } - sel_fam.sort(function(a, b) { // TODO: why not working?? + sel_fam.sort(function (a, b) { // TODO: why not working?? var id1 = bs_families[a]["id"].toUpperCase(); var id2 = bs_families[b]["id"].toUpperCase(); if (id1 < id2) { return -1; } @@ -731,22 +734,22 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam } if (true) { // update nav_ui if (nav_ui.find(".selection-text").children().length < 1) { - var clearSel = $("clear").click({bigscape: bigscape}, function(handler){ + var clearSel = $("clear").click({ bigscape: bigscape }, function (handler) { handler.data.bigscape.setHighlightedNodes([]); handler.data.bigscape.highlightNodes([]); handler.data.bigscape.updateDescription(); handler.stopPropagation(); }); var textSel = $("").text( - "Selected: " + ids.length + " BGC" + (ids.length > 1? "s":"") - + ", " + sel_fam.length + " Famil" + (sel_fam.length > 1? "ies":"y") + "Selected: " + ids.length + " BGC" + (ids.length > 1 ? "s" : "") + + ", " + sel_fam.length + " Famil" + (sel_fam.length > 1 ? "ies" : "y") + " " ); nav_ui.find(".selection-text").append(textSel).append(clearSel); } else { nav_ui.find("span").text( - "Selected: " + ids.length + " BGC" + (ids.length > 1? "s":"") - + ", " + sel_fam.length + " Famil" + (sel_fam.length > 1? "ies":"y") + "Selected: " + ids.length + " BGC" + (ids.length > 1 ? "s" : "") + + ", " + sel_fam.length + " Famil" + (sel_fam.length > 1 ? "ies" : "y") + " " ); } @@ -759,31 +762,31 @@ BigscapeFunc.updateDescription = function(ids, bs_svg, bs_data, bs_to_cl, bs_fam } // ... -BigscapeFunc.highlightNodes = function(graph, graphics, ids, bs_svg, bs_data, bs_to_cl, bs_families, net_ui, desc_ui) { +BigscapeFunc.highlightNodes = function (graph, graphics, ids, bs_svg, bs_data, bs_to_cl, bs_families, net_ui, desc_ui) { net_ui.find("svg line").attr("stroke", "gray"); net_ui.find("svg circle").attr("r", "10"); for (var i in ids) { var id = ids[i]; var nodeUI = graphics.getNodeUI(id); nodeUI.attr("r", "20"); - graph.forEachLinkedNode(id, function(node, link){ - var linkUI = graphics.getLinkUI(link.id); - if (linkUI) { - $(linkUI).attr("stroke", "red"); - } + graph.forEachLinkedNode(id, function (node, link) { + var linkUI = graphics.getLinkUI(link.id); + if (linkUI) { + $(linkUI).attr("stroke", "red"); + } }); } } // ... -BigscapeFunc.openDetail = function(id, bs_svg, bs_data, bs_to_cl, bs_families, det_ui) { +BigscapeFunc.openDetail = function (id, bs_svg, bs_data, bs_to_cl, bs_families, det_ui) { det_ui.html(""); det_ui.append("

    " + bs_data[id]["id"] + "

    "); det_ui.append(bs_svg[id].clone(true, true)); } // ... -BigscapeFunc.openCompDetail = function(ids, bs_svg, bs_data, bs_to_cl, bs_families, bs_alignment, det_ui) { +BigscapeFunc.openCompDetail = function (ids, bs_svg, bs_data, bs_to_cl, bs_families, bs_alignment, det_ui) { det_ui.html(""); var svgs = []; for (var i in ids) { @@ -798,7 +801,7 @@ BigscapeFunc.openCompDetail = function(ids, bs_svg, bs_data, bs_to_cl, bs_famili } // ... -BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, bs_to_cl, bs_families, bs_similarity, det_ui) { +BigscapeFunc.openFamDetail = function (id_fam, ids_highlighted, bs_svg, bs_data, bs_to_cl, bs_families, bs_similarity, det_ui) { id_fam = parseInt(id_fam); det_ui.html(""); det_ui.append("

    " + bs_families[id_fam]["id"] + "

    "); @@ -824,7 +827,7 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, if (true) {//(bs_families[i]["id"] !== bs_families[id_fam]["id"]) { if (bs_families[i].hasOwnProperty("clan")) { if (bs_families[i]["clan"] === bs_families[id_fam]["clan"]) { - var bs_sim = (i > id_fam)? bs_similarity_families[i][id_fam]:bs_similarity_families[id_fam][i]; + var bs_sim = (i > id_fam) ? bs_similarity_families[i][id_fam] : bs_similarity_families[id_fam][i]; related_families.push({ "idx": i, "id": bs_families[i]["id"], @@ -837,14 +840,14 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, } } } - related_families = related_families.sort(function(a, b) { return b["average"] - a["average"] }); + related_families = related_families.sort(function (a, b) { return b["average"] - a["average"] }); for (var i in related_families) { if (related_families[i]["average"] > 0.5) { - var famLink = $("" + related_families[i]["id"] +""); - famLink.click({id_fam: related_families[i]["idx"], bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui, bs_similarity: bs_similarity}, function(handler){ + var famLink = $("" + related_families[i]["id"] + ""); + famLink.click({ id_fam: related_families[i]["idx"], bs_svg: bs_svg, bs_data: bs_data, bs_families: bs_families, bs_to_cl: bs_to_cl, det_ui: det_ui, bs_similarity: bs_similarity }, function (handler) { BigscapeFunc.openFamDetail(handler.data.id_fam, [], handler.data.bs_svg, handler.data.bs_data, handler.data.bs_to_cl, handler.data.bs_families, handler.data.bs_similarity, handler.data.det_ui);; handler.data.det_ui.parent().removeClass("hidden"); - handler.data.det_ui.find("svg.arrower-svg").each(function(){ + handler.data.det_ui.find("svg.arrower-svg").each(function () { $(this).attr("width", $(this).find("g")[0].getBoundingClientRect().width); $(this).attr("height", $(this).find("g")[0].getBoundingClientRect().height); }); @@ -890,9 +893,9 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, treeData.Parse(fam_aln["newick"]); var treeSVG = $("").appendTo(treeContainer); var treeDrawer = new PhylogramTreeDrawer(); - treeDrawer.Init(treeData, { svg_id: 'det_fam_tree', height: ((treeData.num_leaves - 1) * 40), width: 400 } ); + treeDrawer.Init(treeData, { svg_id: 'det_fam_tree', height: ((treeData.num_leaves - 1) * 40), width: 400 }); treeDrawer.draw_scale_bar = false; - treeDrawer.CalcCoordinates(); + treeDrawer.CalcCoordinates(); treeDrawer.Draw(); // draw leaves var n = new NodeIterator(treeData.root); @@ -900,7 +903,7 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, var bgcOffsets = []; var minOffset = 0; while (q != null) { // UGLY IMPLEMENTATION, PLEASE FIX - if (q.IsLeaf()) { + if (q.IsLeaf()) { var bgcId = parseInt(q.label); var bgcFamIdx = -1; for (var i = 0; i < bs_families[id_fam]["members"].length; i++) { @@ -915,8 +918,8 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, } var bgcReverse = bgcOffset[1] < 0; bgcOffsets.push([bgcId, q, bgcOffset[0], bgcReverse]); - } - q = n.Next(); + } + q = n.Next(); } var lastY = 0; for (var i = 0; i < bgcOffsets.length; i++) { // UGLY IMPLEMENTATION, PLEASE FIX @@ -927,15 +930,15 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, if (q.xy["y"] > lastY) { lastY = q.xy["y"]; } - drawDashedLine('det_fam_tree', '1,10', q.xy, {'x': 500, 'y': q.xy['y']}); - drawDashedLine('det_fam_tree', '1,3', {'x': 510, 'y': q.xy['y']}, {'x': (510 + bgcOffset), 'y': q.xy['y']}); + drawDashedLine('det_fam_tree', '1,10', q.xy, { 'x': 500, 'y': q.xy['y'] }); + drawDashedLine('det_fam_tree', '1,3', { 'x': 510, 'y': q.xy['y'] }, { 'x': (510 + bgcOffset), 'y': q.xy['y'] }); var jqG = bs_svg[bgcId].clone(true, true).children("g"); jqG.attr('transform', 'translate(' + (510 + bgcOffset) + ',' + (q.xy['y'] - 10) + ')'); if (bgcReverse) { var bgcLength = parseInt(parseInt(jqG.find("line.arrower-line").attr("x2")) / 2); jqG.attr('transform', jqG.attr('transform') + ' scale(-1,1)' + ' translate(' + (-1 * bgcLength) + ',0)'); jqG.find(".arrower-label").attr('transform', 'scale(-1,1)' + ' translate(' + (-2 * bgcLength) + ',0)') - .attr("font-style", "italic"); + .attr("font-style", "italic"); } if (bs_data[bgcId]["mibig"]) { jqG.attr("font-weight", "bold") @@ -996,87 +999,87 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, } } // move tree svg into a so that it can be collectively manipulated - var tempG = document.createElementNS('http://www.w3.org/2000/svg','g'); + var tempG = document.createElementNS('http://www.w3.org/2000/svg', 'g'); tempG.setAttribute('transform', 'translate(5,25) scale(0.5)'); - treeSVG.children().each(function(idx, elm){ + treeSVG.children().each(function (idx, elm) { tempG.appendChild(elm); }); treeSVG.html(""); treeSVG.append($(tempG)); - // add buttons to zoom in/out and pan tree svg - function zoomInOut(handler) { - var transformAttr = handler.data.tempG.getAttribute("transform"); - var panLevelsHorizontal = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[1]); - var panLevelsVertical = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[2]); - var zoomLevel = parseFloat(/scale\((\d*\.?\d+)\)/gm.exec(transformAttr)[1]); - var svgWidth = handler.data.treeSVG.attr("width"); - var svgHeight = handler.data.treeSVG.attr("height"); - if (handler.data.isZoomIn) { - zoomLevel = zoomLevel * 1.1; - svgWidth = svgWidth * 1.1; - svgHeight = svgHeight * 1.1; - } else { - zoomLevel = zoomLevel / 1.1; - svgWidth = svgWidth / 1.1; - svgHeight = svgHeight / 1.1; - } - handler.data.tempG.setAttribute('transform', 'translate(' + panLevelsHorizontal + ',' + panLevelsVertical + ') scale(' + zoomLevel.toFixed(2) + ')'); - handler.data.treeSVG.attr("width", svgWidth); - handler.data.treeSVG.attr("height", svgHeight); - } - function panDirection(handler) { - var transformAttr = handler.data.tempG.getAttribute("transform"); - var panLevelsHorizontal = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[1]); - var panLevelsVertical = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[2]); - var zoomLevel = parseFloat(/scale\((\d*\.?\d+)\)/gm.exec(transformAttr)[1]); - switch(handler.data.direction) { - case "up": - panLevelsVertical = panLevelsVertical - 5; - break; - case "down": - panLevelsVertical = panLevelsVertical + 5; - break; - case "left": - panLevelsHorizontal = panLevelsHorizontal - 5; - break; - case "right": - panLevelsHorizontal = panLevelsHorizontal + 5; - break; - } - handler.data.tempG.setAttribute('transform', 'translate(' + panLevelsHorizontal + ',' + panLevelsVertical + ') scale(' + zoomLevel.toFixed(2) + ')'); - } - var panZoomTree = $("
    ").insertBefore(treeSVG); - var btnZoomIn = $("").click({treeSVG: treeSVG, tempG: tempG, isZoomIn: true}, zoomInOut).appendTo(panZoomTree); - var btnZoomOut = $("").click({treeSVG: treeSVG, tempG: tempG, isZoomIn: false}, zoomInOut).appendTo(panZoomTree); - var btnPanUp = $("").click({treeSVG: treeSVG, tempG: tempG, direction: "up"}, panDirection).appendTo(panZoomTree); - var btnPanDown = $("").click({treeSVG: treeSVG, tempG: tempG, direction: "down"}, panDirection).appendTo(panZoomTree); - var btnPanUp = $("").click({treeSVG: treeSVG, tempG: tempG, direction: "left"}, panDirection).appendTo(panZoomTree); - var btnPanDown = $("").click({treeSVG: treeSVG, tempG: tempG, direction: "right"}, panDirection).appendTo(panZoomTree); + // add buttons to zoom in/out and pan tree svg + function zoomInOut(handler) { + var transformAttr = handler.data.tempG.getAttribute("transform"); + var panLevelsHorizontal = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[1]); + var panLevelsVertical = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[2]); + var zoomLevel = parseFloat(/scale\((\d*\.?\d+)\)/gm.exec(transformAttr)[1]); + var svgWidth = handler.data.treeSVG.attr("width"); + var svgHeight = handler.data.treeSVG.attr("height"); + if (handler.data.isZoomIn) { + zoomLevel = zoomLevel * 1.1; + svgWidth = svgWidth * 1.1; + svgHeight = svgHeight * 1.1; + } else { + zoomLevel = zoomLevel / 1.1; + svgWidth = svgWidth / 1.1; + svgHeight = svgHeight / 1.1; + } + handler.data.tempG.setAttribute('transform', 'translate(' + panLevelsHorizontal + ',' + panLevelsVertical + ') scale(' + zoomLevel.toFixed(2) + ')'); + handler.data.treeSVG.attr("width", svgWidth); + handler.data.treeSVG.attr("height", svgHeight); + } + function panDirection(handler) { + var transformAttr = handler.data.tempG.getAttribute("transform"); + var panLevelsHorizontal = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[1]); + var panLevelsVertical = parseInt(/translate\((-?\d+)\,\ ?(-?\d+)\)/gm.exec(transformAttr)[2]); + var zoomLevel = parseFloat(/scale\((\d*\.?\d+)\)/gm.exec(transformAttr)[1]); + switch (handler.data.direction) { + case "up": + panLevelsVertical = panLevelsVertical - 5; + break; + case "down": + panLevelsVertical = panLevelsVertical + 5; + break; + case "left": + panLevelsHorizontal = panLevelsHorizontal - 5; + break; + case "right": + panLevelsHorizontal = panLevelsHorizontal + 5; + break; + } + handler.data.tempG.setAttribute('transform', 'translate(' + panLevelsHorizontal + ',' + panLevelsVertical + ') scale(' + zoomLevel.toFixed(2) + ')'); + } + var panZoomTree = $("
    ").insertBefore(treeSVG); + var btnZoomIn = $("").click({ treeSVG: treeSVG, tempG: tempG, isZoomIn: true }, zoomInOut).appendTo(panZoomTree); + var btnZoomOut = $("").click({ treeSVG: treeSVG, tempG: tempG, isZoomIn: false }, zoomInOut).appendTo(panZoomTree); + var btnPanUp = $("").click({ treeSVG: treeSVG, tempG: tempG, direction: "up" }, panDirection).appendTo(panZoomTree); + var btnPanDown = $("").click({ treeSVG: treeSVG, tempG: tempG, direction: "down" }, panDirection).appendTo(panZoomTree); + var btnPanUp = $("").click({ treeSVG: treeSVG, tempG: tempG, direction: "left" }, panDirection).appendTo(panZoomTree); + var btnPanDown = $("").click({ treeSVG: treeSVG, tempG: tempG, direction: "right" }, panDirection).appendTo(panZoomTree); - // button to save .svg - function exportSVG(handler) { - var toBeExported = handler.data.treeSVG.clone(false, false); - toBeExported.find("*").removeAttr("svgjs:data"); - toBeExported.attr({ - "version": "1.1", - "baseprofile": "full", - "xmlns": "http://www.w3.org/2000/svg", - "xmlns:xlink": "http://www.w3.org/1999/xlink", - "xmlns:ev": "http://www.w3.org/2001/xml-events" - }); - var svg_text = toBeExported[0].outerHTML; - downloadLink = $("download"); - downloadLink.attr({ - "href": 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg_text), - "download": handler.data.gcf_id + ".svg", - "display": "none" - }); - downloadLink.appendTo($("body")); - downloadLink[0].click(); - downloadLink.remove(); - } - var btnExport = $("").click({treeSVG: treeSVG, gcf_id: bs_families[id_fam]["id"]}, exportSVG).appendTo(panZoomTree); + // button to save .svg + function exportSVG(handler) { + var toBeExported = handler.data.treeSVG.clone(false, false); + toBeExported.find("*").removeAttr("svgjs:data"); + toBeExported.attr({ + "version": "1.1", + "baseprofile": "full", + "xmlns": "http://www.w3.org/2000/svg", + "xmlns:xlink": "http://www.w3.org/1999/xlink", + "xmlns:ev": "http://www.w3.org/2001/xml-events" + }); + var svg_text = toBeExported[0].outerHTML; + downloadLink = $("download"); + downloadLink.attr({ + "href": 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg_text), + "download": handler.data.gcf_id + ".svg", + "display": "none" + }); + downloadLink.appendTo($("body")); + downloadLink[0].click(); + downloadLink.remove(); + } + var btnExport = $("").click({ treeSVG: treeSVG, gcf_id: bs_families[id_fam]["id"] }, exportSVG).appendTo(panZoomTree); // hide domains....*temp* //treeSVG.find("polygon.arrower-domain").css("display", "none"); @@ -1086,7 +1089,7 @@ BigscapeFunc.openFamDetail = function(id_fam, ids_highlighted, bs_svg, bs_data, } // --- highlighter --- -BigscapeFunc.startMultiSelect = function(graph, graphics, renderer, layout, bigscape) { +BigscapeFunc.startMultiSelect = function (graph, graphics, renderer, layout, bigscape) { var domOverlay = document.querySelector('.network-overlay'); var overlay = BigscapeFunc.createOverlay(domOverlay, bigscape); overlay.onAreaSelected(handleAreaSelected); @@ -1098,7 +1101,7 @@ BigscapeFunc.startMultiSelect = function(graph, graphics, renderer, layout, bigs var bottomRight = toSvgCoordinate(area.x + area.width, area.y + area.height, graphics.getSvgRoot()); var ids = []; - graph.forEachNode(function(node){ + graph.forEachNode(function (node) { var nodeUI = graphics.getNodeUI(node.id); if (isInside(node.id, topLeft, bottomRight)) { ids.push(node.id); @@ -1116,7 +1119,7 @@ BigscapeFunc.startMultiSelect = function(graph, graphics, renderer, layout, bigs pt.x = x; pt.y = y; var svgP = pt.matrixTransform(svgContainer.getCTM().inverse()); - return {x: svgP.x, y: svgP.y}; + return { x: svgP.x, y: svgP.y }; } function isInside(nodeId, topLeft, bottomRight) { @@ -1127,7 +1130,7 @@ BigscapeFunc.startMultiSelect = function(graph, graphics, renderer, layout, bigs } } -BigscapeFunc.createOverlay = function(overlayDom, bigscape) { +BigscapeFunc.createOverlay = function (overlayDom, bigscape) { var selectionClasName = 'graph-selection-indicator'; var selectionIndicator = overlayDom.querySelector('.' + selectionClasName); if (!selectionIndicator) { @@ -1150,7 +1153,7 @@ BigscapeFunc.createOverlay = function(overlayDom, bigscape) { var startX = 0; var startY = 0; - dragndrop.onStart(function(e) { + dragndrop.onStart(function (e) { startX = selectedArea.x = e.clientX; startY = selectedArea.y = e.clientY; selectedArea.width = selectedArea.height = 0; @@ -1158,13 +1161,13 @@ BigscapeFunc.createOverlay = function(overlayDom, bigscape) { selectionIndicator.style.display = 'block'; }); - dragndrop.onDrag(function(e) { + dragndrop.onDrag(function (e) { recalculateSelectedArea(e); updateSelectedAreaIndicator(); notifyAreaSelected(); }); - dragndrop.onStop(function(handler) { + dragndrop.onStop(function (handler) { selectionIndicator.style.display = 'none'; handler.stopPropagation(); }); @@ -1172,7 +1175,7 @@ BigscapeFunc.createOverlay = function(overlayDom, bigscape) { overlayDom.style.display = 'block'; return { - onAreaSelected: function(cb) { + onAreaSelected: function (cb) { notify.push(cb); }, destroy: function () { @@ -1182,7 +1185,7 @@ BigscapeFunc.createOverlay = function(overlayDom, bigscape) { }; function notifyAreaSelected() { - notify.forEach(function(cb) { + notify.forEach(function (cb) { cb(selectedArea); }); } @@ -1202,7 +1205,7 @@ BigscapeFunc.createOverlay = function(overlayDom, bigscape) { } } -BigscapeFunc.showHideDomains = function(cont_ui, isOn) { +BigscapeFunc.showHideDomains = function (cont_ui, isOn) { if (isOn) { cont_ui.find(".arrower-domain").css("display", ""); } else { From 452dae1e9b2968ba34e37351451a6ae9c0fc4cc2 Mon Sep 17 00:00:00 2001 From: "Louwen, Nico" Date: Wed, 20 Sep 2023 15:37:24 +0200 Subject: [PATCH 04/18] update search optimization --- .../output/html_content/js/bigscape.js | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/output/html_template/output/html_content/js/bigscape.js b/src/output/html_template/output/html_content/js/bigscape.js index 004e7807..8f83574c 100644 --- a/src/output/html_template/output/html_content/js/bigscape.js +++ b/src/output/html_template/output/html_content/js/bigscape.js @@ -26,25 +26,10 @@ function Bigscape(bs_data, bs_families, bs_alignment, bs_similarity, network_con bs_svg.push(svg); } // for search optimization - for (var i in bs_families) { - bs_families[i]["idx"] = i; - } - var bs_pfam = []; - for (var i in bs_data) { - bs_data[i]["idx"] = i; - for (var j in bs_data[i]["orfs"]) { - for (var k in bs_data[i]["orfs"][j]["domains"]) { - var pfam = bs_data[i]["orfs"][j]["domains"][k]["code"]; - var bspf = bs_pfam.find(function (bsp) { return bsp["code"] === pfam; }); - if (bspf === undefined) { - bspf = { idx: bs_pfam.length, code: pfam, bgc: [i] }; - bs_pfam.push(bspf); - } else { - if (bspf["bgc"].indexOf(i) < 0) { - bspf["bgc"].push(i); - } - } - } + for (fam of bs_families) { + for (member of fam["members"]) { + bs_data[member]["family"] = fam["id"] + bs_data[member]["idx"] = member } } $("#" + network_container).html("