def test_add_autocomplete(): """Make sure we add autocomplete if there's gene annotations and chromsizes tracks.""" track1 = Track( "horizontal-chromosome-labels", server="https://higlass.io/api/v1", tilesetUid="xx", ) # chromosome labels should create a genomePositionSearchBox view_dict = View([track1], chrominfo=track1).to_dict() assert "genomePositionSearchBox" in view_dict track2 = Track( "horizontal-gene-annotations", server="https://higlass.io/api/v1", tilesetUid="xx", ) # gene labels alone shouldn't view_dict = View([track2], geneinfo=track2).to_dict() assert "genomePositionSearchBox" not in view_dict view_dict = View([track1, track2], chrominfo=track1, geneinfo=track2).to_dict() assert "genomePositionSearchBox" in view_dict
def test_divided_track(): """Test creating a divided track.""" ts1 = Tileset(uuid="ts1") tr1 = Track(track_type="heatmap", server="server1", tileset=ts1) ts2 = Tileset(uuid="ts2") tr2 = Track(track_type="heatmap", server="server2", tileset=ts2) tr3 = tr1 / tr2 assert "data" in tr3.conf assert tr3.conf["data"]["type"] == "divided"
def test_add_tracks(): """Test combining tracks using the '+' operator.""" track1 = Track("top-axis") track2 = Track("top-axis") track3 = track1 + track2 assert track1 in track3.tracks track4 = Track("top-axis") track5 = track3 + track4 assert len(track5.tracks) == 3
def test_combined_track_from_track_list(): """Test creating a CombinedTrack by providing a list of tracks when creating a View.""" track1 = Track("top-axis") track2 = Track("horizontal-line") view = View([[track1, track2]]) view_dict = view.to_dict() combined_track = view_dict["tracks"]["top"][0] assert combined_track["type"] == "combined" assert combined_track["contents"][0]["type"] == "top-axis"
def test_create_display(): """Test to make sure we can create a display.""" with patch("higlass.server.Server") as _: (_, _, viewconf) = display([View([Track("top-axis")])]) vc_dict = viewconf.to_dict() assert len(vc_dict["views"]) == 1 (_, _, viewconf) = display([[Track("top-axis")]]) vc_dict = viewconf.to_dict() assert len(vc_dict["views"]) == 1
def test_viewport_projection(): """Test creating a ViewportProjection track.""" track1 = Track("top-axis") view1 = View([track1]) vp = ViewportProjection(view1) track2 = Track("top-axis") track3 = track2 + vp assert vp.conf["type"] == "viewport-projection" assert track3.tracks[1].conf["type"] == "viewport-projection-horizontal" track4 = Track("heatmap") track5 = track4 + vp assert track5.tracks[1].conf["type"] == "viewport-projection-center"
def view( filename, hg_name, filetype, datatype, tracktype, position, public_data, assembly, chromsizes_filename, ): """ View a file in higlass. The user can specify an instance to view it in. If one is not specified the default will be used. If the default isn't running, it will be started. Parameters: ----------- hg_name: string The name of the higlass instance filename: string The name of the file to view """ try: temp_dir = get_temp_dir(hg_name) print("temp_dir:", temp_dir) except Exception: _start(hg_name=hg_name) # check if we have a running instance # if not, start one # get a list of the available tilesets # check if any match the filename of this file # if the filenames match, check if the checksums match port = get_port(hg_name) uuid = None # guess filetype and datatype if they're None (filetype, inferred_datatype) = fill_filetype_and_datatype(filename, filetype, datatype) if filetype is None or inferred_datatype is None: print( "Couldn't infer filetype or datatype ({}, {}),".format( filetype, inferred_datatype), "please specify them using the command line options", file=sys.stderr, ) return try: MAX_TILESETS = 100000 req = requests.get( "http://localhost:{}/api/v1/tilesets/?limit={}".format( port, MAX_TILESETS), timeout=10, ) tilesets = json.loads(req.content) for tileset in tilesets["results"]: import_filename = op.splitext(ntpath.basename(filename))[0] tileset_filename = ntpath.basename(tileset["datafile"]) subpath_index = tileset["datafile"].find("/tilesets/") subpath = tileset["datafile"][subpath_index + len("/tilesets/"):] data_dir = get_data_dir(hg_name) tileset_path = op.join(data_dir, subpath) # print("import_filename", import_filename) # print("tileset_filename", tileset_filename) if tileset_filename.find(import_filename) >= 0: # same filenames, make sure they're actually the same file # by comparing checksums checksum1 = md5(tileset_path) checksum2 = md5(filename) if checksum1 == checksum2: uuid = tileset["uuid"] break except requests.exceptions.ConnectionError: print("Error getting a list of existing tilesets", file=sys.stderr) return if uuid is None: # we haven't found a matching tileset so we need to ingest this one uuid = _ingest( filename, hg_name, filetype, datatype, assembly=assembly, chromsizes_filename=chromsizes_filename, ) if uuid is None: # couldn't ingest the file return from higlass.client import Track, View, ViewConf if datatype is None: datatype = inferred_datatype if tracktype is None and position is None: (tracktype, position) = datatype_to_tracktype(datatype) if tracktype is None: print("ERROR: Unknown track type for the given datatype:", datatype) return view = View([ Track( track_type=tracktype, position=position, tileset_uuid=uuid, server="http://localhost:{}/api/v1/".format(port), height=200, ), ]) viewconf = ViewConf([view]) conf = viewconf.to_dict() conf["trackSourceServers"] = [] conf["trackSourceServers"] += ["http://localhost:{}/api/v1/".format(port)] if public_data: conf["trackSourceServers"] += ["http://higlass.io/api/v1/"] # uplaod the viewconf res = requests.post("http://localhost:{}/api/v1/viewconfs/".format(port), json={"viewconf": conf}) if res.status_code != 200: print("Error posting viewconf:", res.status, res.content) return uid = json.loads(res.content)["uid"] # make sure this test passes on Travis CI and doesn't try to open # a terminal-based browser which doesn't return if not os.environ.get("HAS_JOSH_K_SEAL_OF_APPROVAL"): webbrowser.open("http://localhost:{port}/app/?config={uid}".format( port=port, uid=uid))