Exemplo n.º 1
0
def test_tileset_info():
    filename = op.join(
        "data",
        "wgEncodeCaltechRnaSeqHuvecR1x75dTh1014IlnaPlusSignalRep2.bigWig")

    tileset_info = hgbi.tileset_info(filename)

    assert len(tileset_info["aggregation_modes"]) == 4
    assert tileset_info["aggregation_modes"]["mean"]
    assert tileset_info["aggregation_modes"]["min"]
    assert tileset_info["aggregation_modes"]["max"]
    assert tileset_info["aggregation_modes"]["std"]

    assert len(tileset_info["range_modes"]) == 2
    assert tileset_info["range_modes"]["minMax"]
    assert tileset_info["range_modes"]["whisker"]
Exemplo n.º 2
0
def test_tileset_info():
    filename = op.join(
        'data',
        'wgEncodeCaltechRnaSeqHuvecR1x75dTh1014IlnaPlusSignalRep2.bigWig')

    tileset_info = hgbi.tileset_info(filename)

    assert len(tileset_info['aggregation_modes']) == 4
    assert tileset_info['aggregation_modes']['mean']
    assert tileset_info['aggregation_modes']['min']
    assert tileset_info['aggregation_modes']['max']
    assert tileset_info['aggregation_modes']['std']

    assert len(tileset_info['range_modes']) == 2
    assert tileset_info['range_modes']['minMax']
    assert tileset_info['range_modes']['whisker']
Exemplo n.º 3
0
    def tileset_info(cls, tileset_dict):
        filetype = tileset_dict.get("filetype", "")
        if filetype == "bam":
            info = bam_tiles.tileset_info(tileset_dict['datafile'])
            info['max_tile_width'] = int(1e5)
        elif filetype == "cooler":
            info = cooler_tiles.tileset_info(tileset_dict['datafile'])
        elif filetype == "bigwig":
            info = bigwig_tiles.tileset_info(tileset_dict['datafile'])
        else:
            info = {'error': f"Unknown tileset filetype: {filetype}"}

        for column in cls.info_colums:
            info[column] = tileset_dict.get(column)

        return info
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def test_tileset_info():
    filename = op.join(
        'data',
        'wgEncodeCaltechRnaSeqHuvecR1x75dTh1014IlnaPlusSignalRep2.bigWig')

    tileset_info = hgbi.tileset_info(filename)
def check_for_chromsizes(filename, coord_system):
    '''
    Check to see if we have chromsizes matching the coord system
    of the filename.

    Parameters
    ----------
    filename: string
        The name of the bigwig file
    coord_system: string
        The coordinate system (assembly) of this bigwig file
    '''
    tileset_info = hgbi.tileset_info(filename)
    # print("tileset chromsizes:", tileset_info['chromsizes'])
    tsinfo_chromsizes = set([(str(chrom), str(size)) for chrom, size in tileset_info['chromsizes']])
    # print("tsinfo_chromsizes:", tsinfo_chromsizes)

    chrom_info_tileset = None

    # check if we have a chrom sizes tileset that matches the coordsystem
    # of the input file
    if coord_system is not None and len(coord_system) > 0:
        try:
            chrom_info_tileset = tm.Tileset.objects.filter(
                    coordSystem=coord_system,
                    datatype='chromsizes')

            if len(chrom_info_tileset) > 1:
                raise CommandError("More than one available set of chromSizes"
                        + "for this coordSystem ({})".format(coord_system))

            chrom_info_tileset = chrom_info_tileset.first()
        except dce.ObjectDoesNotExist:
            chrom_info_tileset = None

    matches = []

    if chrom_info_tileset is None:
        # we haven't found chromsizes matching the coordsystem
        # go through every chromsizes file and see if we have a match
        for chrom_info_tileset in tm.Tileset.objects.filter(datatype='chromsizes'):
            chromsizes_set = set([tuple(t) for
                t in tcs.get_tsv_chromsizes(chrom_info_tileset.datafile.path)])

            matches += [(len(set.intersection(chromsizes_set, tsinfo_chromsizes)),
                chrom_info_tileset)]

            # print("chrom_info_tileset:", chromsizes_set)
            #print("intersection:", len(set.intersection(chromsizes_set, tsinfo_chromsizes)))
        #print("coord_system:", coord_system)
    else:
        # a set of chromsizes was provided
        chromsizes_set = set([tuple(t) for
            t in tcs.get_tsv_chromsizes(chrom_info_tileset.datafile.path)])
        matches += [(len(set.intersection(chromsizes_set, tsinfo_chromsizes)),
            chrom_info_tileset)]

    # matches that overlap some chromsizes with the bigwig file
    overlap_matches = [m for m in matches if m[0] > 0]

    if len(overlap_matches) == 0:
        raise CommandError("No chromsizes available which match the chromosomes in this bigwig"
                + "See http://docs.higlass.io/data_preparation.html#bigwig-files "
                + "for more information"
                )

    if len(overlap_matches) > 1:
        raise CommandError("Multiple matching coordSystems:"
                + "See http://docs.higlass.io/data_preparation.html#bigwig-files "
                + "for more information",
                ["({} [{}])".format(t[1].coordSystem, t[0]) for t in overlap_matches])

    if (coord_system is not None
            and len(coord_system) > 0
            and overlap_matches[0][1].coordSystem != coord_system):
        raise CommandError("Matching chromosome sizes (coordSystem: {}) do not "
            + "match the specified coordinate sytem ({}). "
            + "Either omit the coordSystem or specify a matching one."
            + "See http://docs.higlass.io/data_preparation.html#bigwig-files "
            + "for more information".format(overlap_matches[0][1].coordSystem, coord_system))

    if (coord_system is not None
            and len(coord_system) > 0
            and overlap_matches[0][1].coordSystem == coord_system):
        print("Using coordinates for coordinate system: {}".format(coord_system))

    if coord_system is None or len(coord_system) == 0:
        print("No coordinate system specified, but we found matching "
            + "chromsizes. Using coordinate system {}."
            .format(overlap_matches[0][1].coordSystem))

    return overlap_matches[0][1].coordSystem
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def tileset_info(bbpath, chromsizes=None):
    ti = hgbw.tileset_info(bbpath, chromsizes)
    ti["range_modes"] = range_modes
    return ti
Exemplo n.º 9
0
def bigwig(filepath, chromsizes=None, uuid=None):
    return Tileset(
        tileset_info=lambda: hgbi.tileset_info(filepath, chromsizes),
        tiles=lambda tids: hgbi.tiles(filepath, tids, chromsizes=chromsizes),
        uuid=uuid,
    )