Skip to content

Commit

Permalink
Add explicit "synchDatasets" property to session json, defaults to tr…
Browse files Browse the repository at this point in the history
…ue (current behavior). See issue #365
  • Loading branch information
jrobinso committed May 9, 2021
1 parent acc7798 commit 03e95e9
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 13 deletions.
87 changes: 87 additions & 0 deletions dev/non_synched_maps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016-2017 The Regents of the University of California
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
~ associated documentation files (the "Software"), to deal in the Software without restriction, including
~ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
~ following conditions:
~
~ The above copyright notice and this permission notice shall be included in all copies or substantial
~ portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
~ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
~ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
~ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
~ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
~ THE SOFTWARE.
~
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>Juicebox</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>

<!-- Font Awesome CSS-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">

<!-- Juicebox CSS-->
<link rel="stylesheet" type="text/css" href="../css/juicebox.css">


</head>

<body>


<div id="app-container"></div>


<script type="module">

import hic from "../js/index.js";
import {Alert} from "../node_modules/igv-ui/dist/igv-ui.js"

const container = document.getElementById("app-container");


const config = {
"syncDatasets": false,
"browsers": [
{
"backgroundColor": "255,255,255",
"url": "https://hicfiles.s3.amazonaws.com/external/dekker/4dn/h1hesc.hic",
"name": "4DN H1 hESC",
"state": "3,3,2,0,0,640,640,1.454380698186564,NONE",
"colorScale": "602,255,0,0",
"nvi": "23671753603,36479"
},
{
"backgroundColor": "255,255,255",
"url": "https://hicfiles.s3.amazonaws.com/external/dekker/4dn/h1hesc_rep1.hic",
"name": "4DN H1 hESC rep1",
"state": "4,4,2,0,0,640,640,1.5066364510726402,NONE",
"colorScale": "602,255,0,0",
"nvi": "23671754721,36479"
}
]
}

hic.init(container, config)
.then(function (hicBrowser) {

})


</script>

</body>

</html>
19 changes: 12 additions & 7 deletions js/createBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ async function createBrowser(hic_container, config, callback) {
* @param hic_container
* @param configList
*/
async function createBrowserList(hic_container, configList) {
async function createBrowserList(hic_container, session) {

const $hic_container = $(hic_container);
const configList = session.browsers || [session];


allBrowsers = [];
Expand All @@ -73,7 +74,12 @@ async function createBrowserList(hic_container, configList) {
if (StringUtils.isString(config.backgroundColor)) {
config.backgroundColor = ContactMatrixView.parseBackgroundColor(config.backgroundColor);
}
if(false === session.syncDatasets) {
config.synchable = false;
}

const browser = new HICBrowser($hic_container, config);

allBrowsers.push(browser);
initPromises.push(browser.init(config));
}
Expand Down Expand Up @@ -136,17 +142,16 @@ function getCurrentBrowser() {
}

function syncBrowsers(browsers) {
const browsersWithMaps = (browsers || allBrowsers).filter(b => b.dataset !== undefined);

const synchableBrowsers = (browsers || allBrowsers).filter(b => (false !== b.synchable) && (b.dataset !== undefined));

// Sync compatible maps only
const incompatibleDatasets = [];
for (let b1 of browsersWithMaps) {
for (let b2 of browsersWithMaps) {
for (let b1 of synchableBrowsers) {
for (let b2 of synchableBrowsers) {
if (b1 === b2) continue;
if (b1.dataset.isCompatible(b2.dataset)) {
b1.synchedBrowsers.push(b2);
b2.synchedBrowsers.push(b1);
} else {
incompatibleDatasets.push(b1.dataset.genomeId);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions js/hicBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class HICBrowser {
this.tracks2D = [];
this.normVectorFiles = [];

this.synchable = config.synchable !== false;
this.synchedBrowsers = [];

this.isMobile = hicUtils.isMobile();
Expand Down Expand Up @@ -1119,6 +1120,8 @@ class HICBrowser {
*/
canBeSynched(syncState) {

if(false === this.synchable) return false; // Explicitly not synchable

return this.dataset &&
(this.dataset.getChrIndexFromName(syncState.chr1Name) !== undefined) &&
(this.dataset.getChrIndexFromName(syncState.chr2Name) !== undefined);
Expand All @@ -1131,6 +1134,8 @@ class HICBrowser {
*/
syncState(syncState) {

if(!syncState || false === this.synchable) return;

if (!this.dataset) return;

var chr1 = this.genome.getChromosome(syncState.chr1Name),
Expand Down
10 changes: 4 additions & 6 deletions js/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ async function restoreSession(container, session) {
}
}

await createBrowserList(container, session);

// Browser config. Session json could be multi-browser, or a single browser
const configList = session.browsers || [session];

await createBrowserList(container, configList);

syncBrowsers();
if (false !== session.syncDatasets) {
syncBrowsers();
}

}

Expand Down

0 comments on commit 03e95e9

Please sign in to comment.