def main(): parser = argparse.ArgumentParser(description=""" python get_hitile.py filename z x """) parser.add_argument('filename') parser.add_argument('z', type=int) parser.add_argument('x', type=int) #parser.add_argument('argument', nargs=1) #parser.add_argument('-o', '--options', default='yo', # help="Some option", type='str') #parser.add_argument('-u', '--useless', action='store_true', # help='Another useless option') args = parser.parse_args() with h5py.File(args.filename, 'r') as f: tileset_info = hdft.get_tileset_info(f) max_width = tileset_info['max_width'] max_pos = tileset_info['max_pos'] tile_size = tileset_info['tile_size'] print("max_width", max_width) print("max_pos", max_pos) last_index = int(tile_size * (max_pos / max_width)) print("last_index:", last_index) tile_data = hdft.get_data(f, args.z, args.x)
def tileset_info(request): """Get information about a tileset Tilesets have information critical to their display such as the maximum number of dimensions and well as their width. This needs to be relayed to the client in order for it to know which tiles to request. Args: request (django.http.HTTPRequest): The request object containing tileset_ids in the 'd' parameter. Return: django.http.JsonResponse: A JSON object containing the tileset meta-information """ queryset = tm.Tileset.objects.all() tileset_uuids = request.GET.getlist("d") tileset_infos = {} chromsizes_error = None if "cs" in request.GET: # we need to call a different server to get the tiles if not "ci" in request.GET.getlist: chromsizes_error = "cs param present without ci" # call the request server and get the chromsizes pass else: if "ci" in request.GET: try: chromsizes = tm.Tileset.objects.get(uuid=request.GET["ci"]) data = tcs.chromsizes_array_to_series( tcs.get_tsv_chromsizes(chromsizes.datafile.path) ) except Exception as ex: pass for tileset_uuid in tileset_uuids: tileset_object = queryset.filter(uuid=tileset_uuid).first() if tileset_uuid == "osm-image": tileset_infos[tileset_uuid] = { "min_x": 0, "max_height": 134217728, "min_y": 0, "max_y": 134217728, "max_zoom": 19, "tile_size": 256, } continue if tileset_object is None: tileset_infos[tileset_uuid] = { "error": "No such tileset with uid: {}".format(tileset_uuid) } continue if tileset_object.private and request.user != tileset_object.owner: # dataset is not public tileset_infos[tileset_uuid] = {"error": "Forbidden"} continue if tileset_object.requiresAuthentication and not request.user.is_authenticated: # dataset is not public tileset_infos[tileset_uuid] = { "error": "This request required authentication" } continue #print(tileset_uuid,"accessibleTilesets" in request.session) if tileset_object.requiresAuthentication and ( ("accessibleTilesets" not in request.session) or (tileset_uuid not in request.session["accessibleTilesets"]) ): # dataset is not accessible for this user tileset_infos[tileset_uuid] = { "error": "You don't have access to this tileset" } continue if tileset_object.filetype == "hitile" or tileset_object.filetype == "hibed": tileset_info = hdft.get_tileset_info( h5py.File(tileset_object.datafile.path, "r") ) tileset_infos[tileset_uuid] = { "min_pos": [int(tileset_info["min_pos"])], "max_pos": [int(tileset_info["max_pos"])], "max_width": 2 ** math.ceil( math.log(tileset_info["max_pos"] - tileset_info["min_pos"]) / math.log(2) ), "tile_size": int(tileset_info["tile_size"]), "max_zoom": int(tileset_info["max_zoom"]), } elif tileset_object.filetype == "bigwig": chromsizes = tgt.get_chromsizes(tileset_object) tsinfo = hgbi.tileset_info(tileset_object.datafile.path, chromsizes) # print('tsinfo:', tsinfo) if "chromsizes" in tsinfo: tsinfo["chromsizes"] = [(c, int(s)) for c, s in tsinfo["chromsizes"]] tileset_infos[tileset_uuid] = tsinfo elif tileset_object.filetype == "bigbed": chromsizes = tgt.get_chromsizes(tileset_object) tsinfo = hgbi.tileset_info(tileset_object.datafile.path, chromsizes) # print('tsinfo:', tsinfo) if "chromsizes" in tsinfo: tsinfo["chromsizes"] = [(c, int(s)) for c, s in tsinfo["chromsizes"]] tileset_infos[tileset_uuid] = tsinfo elif tileset_object.filetype == "multivec": tileset_infos[tileset_uuid] = hgmu.tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "elastic_search": response = urllib.urlopen(tileset_object.datafile + "/tileset_info") tileset_infos[tileset_uuid] = json.loads(response.read()) elif tileset_object.filetype == "beddb": tileset_infos[tileset_uuid] = cdt.get_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "bed2ddb": tileset_infos[tileset_uuid] = cdt.get_2d_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "cooler": tileset_infos[tileset_uuid] = hgco.tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "time-interval-json": tileset_infos[tileset_uuid] = hgti.tileset_info( tileset_object.datafile.path ) elif ( tileset_object.filetype == "2dannodb" or tileset_object.filetype == "imtiles" ): tileset_infos[tileset_uuid] = hgim.get_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "geodb": tileset_infos[tileset_uuid] = hggo.tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == "bam": tileset_infos[tileset_uuid] = ctb.tileset_info(tileset_object.datafile.path) tileset_infos[tileset_uuid]["max_tile_width"] = hss.MAX_BAM_TILE_WIDTH else: # Unknown filetype tileset_infos[tileset_uuid] = { "error": "Unknown filetype " + tileset_object.filetype } tileset_infos[tileset_uuid]["name"] = tileset_object.name tileset_infos[tileset_uuid]["datatype"] = tileset_object.datatype tileset_infos[tileset_uuid]["coordSystem"] = tileset_object.coordSystem tileset_infos[tileset_uuid]["coordSystem2"] = tileset_object.coordSystem2 return JsonResponse(tileset_infos)
def check_tileset_info(filename): f = h5py.File(filename) ti = ch.get_tileset_info(f)
def tileset_info(request): ''' Get information about a tileset Tilesets have information critical to their display such as the maximum number of dimensions and well as their width. This needs to be relayed to the client in order for it to know which tiles to request. Args: request (django.http.HTTPRequest): The request object containing tileset_ids in the 'd' parameter. Return: django.http.JsonResponse: A JSON object containing the tileset meta-information ''' queryset = tm.Tileset.objects.all() tileset_uuids = request.GET.getlist("d") tileset_infos = {} chromsizes_error = None if 'cs' in request.GET: # we need to call a different server to get the tiles if not 'ci' in request.GET.getlist: chromsizes_error = 'cs param present without ci' # call the request server and get the chromsizes pass else: if 'ci' in request.GET: try: chromsizes = tm.Tileset.objects.get(uuid=request.GET['ci']) data = tcs.chromsizes_array_to_series( tcs.get_tsv_chromsizes(chromsizes.datafile.path)) except Exception as ex: pass for tileset_uuid in tileset_uuids: tileset_object = queryset.filter(uuid=tileset_uuid).first() if tileset_uuid == 'osm-image': tileset_infos[tileset_uuid] = { 'min_x': 0, 'max_height': 134217728, 'min_y': 0, 'max_y': 134217728, 'max_zoom': 19, 'tile_size': 256 } continue if tileset_object is None: tileset_infos[tileset_uuid] = { 'error': 'No such tileset with uid: {}'.format(tileset_uuid) } continue if tileset_object.private and request.user != tileset_object.owner: # dataset is not public tileset_infos[tileset_uuid] = {'error': "Forbidden"} continue if ( tileset_object.filetype == 'hitile' or tileset_object.filetype == 'hibed' ): tileset_info = hdft.get_tileset_info( h5py.File(tileset_object.datafile.path, 'r')) tileset_infos[tileset_uuid] = { "min_pos": [int(tileset_info['min_pos'])], "max_pos": [int(tileset_info['max_pos'])], "max_width": 2 ** math.ceil( math.log( tileset_info['max_pos'] - tileset_info['min_pos'] ) / math.log(2) ), "tile_size": int(tileset_info['tile_size']), "max_zoom": int(tileset_info['max_zoom']) } elif tileset_object.filetype == 'bigwig': chromsizes = tgt.get_chromsizes(tileset_object) tsinfo = hgbi.tileset_info( tileset_object.datafile.path, chromsizes ) #print('tsinfo:', tsinfo) if 'chromsizes' in tsinfo: tsinfo['chromsizes'] = [(c, int(s)) for c,s in tsinfo['chromsizes']] tileset_infos[tileset_uuid] = tsinfo elif tileset_object.filetype == 'bigbed': chromsizes = tgt.get_chromsizes(tileset_object) tsinfo = hgbi.tileset_info( tileset_object.datafile.path, chromsizes ) #print('tsinfo:', tsinfo) if 'chromsizes' in tsinfo: tsinfo['chromsizes'] = [(c, int(s)) for c,s in tsinfo['chromsizes']] tileset_infos[tileset_uuid] = tsinfo elif tileset_object.filetype == 'multivec': tileset_infos[tileset_uuid] = hgmu.tileset_info( tileset_object.datafile.path) elif tileset_object.filetype == "elastic_search": response = urllib.urlopen( tileset_object.datafile + "/tileset_info") tileset_infos[tileset_uuid] = json.loads(response.read()) elif tileset_object.filetype == 'beddb': tileset_infos[tileset_uuid] = cdt.get_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == 'bed2ddb': tileset_infos[tileset_uuid] = cdt.get_2d_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == 'cooler': tileset_infos[tileset_uuid] = hgco.tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == 'time-interval-json': tileset_infos[tileset_uuid] = hgti.tileset_info( tileset_object.datafile.path ) elif ( tileset_object.filetype == '2dannodb' or tileset_object.filetype == 'imtiles' ): tileset_infos[tileset_uuid] = hgim.get_tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == 'geodb': tileset_infos[tileset_uuid] = hggo.tileset_info( tileset_object.datafile.path ) elif tileset_object.filetype == 'bam': tileset_infos[tileset_uuid] = ctb.tileset_info( tileset_object.datafile.path ) tileset_infos[tileset_uuid]['max_tile_width'] = hss.MAX_BAM_TILE_WIDTH else: # Unknown filetype tileset_infos[tileset_uuid] = { 'error': 'Unknown filetype ' + tileset_object.filetype } tileset_infos[tileset_uuid]['name'] = tileset_object.name tileset_infos[tileset_uuid]['datatype'] = tileset_object.datatype tileset_infos[tileset_uuid]['coordSystem'] = tileset_object.coordSystem tileset_infos[tileset_uuid]['coordSystem2'] =\ tileset_object.coordSystem2 return JsonResponse(tileset_infos)
def tileset_info(request): ''' Get information about a tileset Tilesets have information critical to their display such as the maximum number of dimensions and well as their width. This needs to be relayed to the client in order for it to know which tiles to request. Args: request (django.http.HTTPRequest): The request object containing tileset_ids in the 'd' parameter. Return: django.http.JsonResponse: A JSON object containing the tileset meta-information ''' global mats queryset = tm.Tileset.objects.all() tileset_uuids = request.GET.getlist("d") tileset_infos = {} for tileset_uuid in tileset_uuids: tileset_object = queryset.filter(uuid=tileset_uuid).first() if tileset_object is None: return JsonResponse({ 'error': 'No such tileset with uuid: {}'.format(tileset_uuid) }, status=500) if tileset_object.private and request.user != tileset_object.owner: return JsonResponse({ 'error': 'Data set (uuid: {}) is not public'.format( tileset_uuid ) }, status=403) if ( tileset_object.filetype == "hitile" or tileset_object.filetype == 'hibed' ): tileset_info = hdft.get_tileset_info( h5py.File(get_datapath(tileset_object.datafile))) tileset_infos[tileset_uuid] = { "min_pos": [0], "max_pos": [tileset_info['max_pos']], "max_width": 2 ** math.ceil( math.log(tileset_info['max_pos'] - 0) / math.log(2) ), "tile_size": tileset_info['tile_size'], "max_zoom": tileset_info['max_zoom'] } elif tileset_object.filetype == "elastic_search": response = urllib.urlopen( tileset_object.datafile + "/tileset_info") tileset_infos[tileset_uuid] = json.loads(response.read()) elif tileset_object.filetype == 'beddb': tileset_infos[tileset_uuid] = cdt.get_tileset_info( get_datapath(tileset_object.datafile) ) elif tileset_object.filetype == 'bed2ddb': tileset_infos[tileset_uuid] = cdt.get_2d_tileset_info( get_datapath(tileset_object.datafile) ) else: dsetname = get_datapath(tileset_object.datafile) if dsetname not in mats: try: make_mats(dsetname) except Exception: return JsonResponse({ 'error': 'File not found (uuid: {})'.format( tileset_uuid ) }, status=500) tileset_infos[tileset_uuid] = mats[dsetname][1] tileset_infos[tileset_uuid]['name'] = tileset_object.name return JsonResponse(tileset_infos)