Example #1
0
def index(request):
    file_object = file_store.models.get_file_object(
        "/Users/isytchev/Sites/tdf/"
        "TCGA-AG-4007-01A-01D-1115-02_101122_SN177_0123_B20APUABXX_s_5.rg"
        ".sorted.chr21.bam.tdf")
    tdf_file = tdf_module.TDFFile(file_object)
    tdf_file.cache()

    for track_name in tdf_file.get_track_names():
        print(track_name)

    for data_set_name in tdf_file.get_data_set_names():
        print(data_set_name)
        window_function = ""
        if len(data_set_name.split("/")) == 4:
            window_function = data_set_name.split("/")[3]
        data_set = tdf_file.get_data_set(
            data_set_name.split("/")[1],
            data_set_name.split("/")[2], window_function)
        data_set.read()
        print("Tile Count: " + str(len(data_set.tile_index)))
        print("Tile Width: " + str(data_set.tile_width))

    print(data_set)

    tile = data_set.get_tile(0)
    print(tile)

    tile = data_set.get_tile(1)
    print(tile)

    tile = data_set.get_tile(2)
    print(tile)

    tile = data_set.get_tile(3)
    print(tile)

    tile = data_set.get_tile(4)
    print(tile)

    tile = data_set.get_tile(5)
    print(tile)

    tile = data_set.get_tile(6)
    print(tile)

    tile = data_set.get_tile(7)
    print(tile)

    profile = tdf_file.get_profile("chr21",
                                   "z0", ["mean"],
                                   start_location=13591070,
                                   end_location=14845362)

    file_object.close()

    return HttpResponse(json.dumps(profile), mimetype='application/json')
Example #2
0
def cache_tdf(request, uuid, refresh=False):
    try:
        file_store_item = FileStoreItem.objects.get(uuid=uuid)
    except (FileStoreItem.DoesNotExist,
            FileStoreItem.MultipleObjectsReturned) as e:
        logger.error("Couldn't properly fetch FileStoreItem: %s", e)
    else:
        if not _is_cached_tdf_file(request.session, uuid):
            logger.debug("Caching file: %s ...", uuid)
            tdf = tdf_module.TDFFile(file_store_item.get_file_object())
            tdf.cache()
            _cache_tdf_file(request.session, uuid, tdf)
        else:
            logger.debug("Retrieved file: %s ...", uuid)
            tdf = _get_tdf_file_from_cache(request.session, uuid)

        if not _is_cached_tdf_data_set_information(request.session,
                                                   uuid) or refresh:
            logger.debug("Caching data set information: %s ...", uuid)

            for data_set_name in tdf.get_data_set_names():
                # decompose data set name
                components = tdf.decompose_data_set_name(data_set_name)
                data_set = tdf.get_data_set(components["sequence_name"],
                                            components["zoom_level"],
                                            components["window_function"])
                data_set_information = {
                    "data_set_name": data_set_name,
                    "tile_width": data_set.tile_width,
                    "tile_count": str(len(data_set.tile_index))
                }

                _cache_tdf_data_set_information(request.session, uuid,
                                                components,
                                                data_set_information)
        else:
            logger.debug(
                "%s data set information is cached and refresh not "
                "requested", uuid)

        return HttpResponse(json.dumps(
            _get_tdf_data_set_information_from_cache(request.session, uuid),
            sort_keys=True,
            indent=4),
                            content_type='application/json')
Example #3
0
 def get_profile(self, zoom, seq, window, start, end):
     """Calculates and returns a profile from TDF file.
     :param seq: Sequence name.
     :type seq: str.
     :param zoom: Zoom level.
     :type zoom: int.
     :param window: Window function.
     :type window: str.
     :param start: Start position.
     :type start: int.
     :param end: End position.
     :type end: int.
     :returns: JSON
     """
     with self.get_file_object() as file_object:
         tdf_file = tdf_module.TDFFile(file_object)
         tdf_file.cache()
         profile = tdf_file.get_profile(seq, zoom, ["mean"], start, end)
     return json.dumps(profile)
Example #4
0
def cache_tdf(request, uuid, refresh=False):

    # TODO: call asynchronously
    file_store_item = file_store.tasks.read(uuid)

    if not _is_cached_tdf_file(request.session, uuid):
        print("Caching file " + str(uuid) + " ...")
        tdf = tdf_module.TDFFile(file_store_item.get_file_object())
        tdf.cache()
        _cache_tdf_file(request.session, uuid, tdf)
    else:
        print("Retrieved file " + str(uuid) + " ...")
        tdf = _get_tdf_file_from_cache(request.session, uuid)

    if not _is_cached_tdf_data_set_information(request.session,
                                               uuid) or refresh:
        print("Caching data set information " + str(uuid) + " ...")

        for data_set_name in tdf.get_data_set_names():

            # decompose data set name
            components = tdf.decompose_data_set_name(data_set_name)
            data_set = tdf.get_data_set(components["sequence_name"],
                                        components["zoom_level"],
                                        components["window_function"])
            data_set_information = {
                "data_set_name": data_set_name,
                "tile_width": data_set.tile_width,
                "tile_count": str(len(data_set.tile_index))
            }

            _cache_tdf_data_set_information(request.session, uuid, components,
                                            data_set_information)
    else:
        print(
            str(uuid) +
            " data set information is cached and refresh not requested")

    return HttpResponse(simplejson.dumps(
        _get_tdf_data_set_information_from_cache(request.session, uuid),
        sort_keys=True,
        indent=4),
                        mimetype='application/json')