Ejemplo n.º 1
0
def map_view(request, map_id):
    export = "export_button" in request.POST

    items, enzymes, metabolites = request_extract(request)
    map_data = get_reaction_map(map_id, enzymes, metabolites, export)

    if export:
        map_data = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>""" + map_data

        import wand.image
        with wand.image.Image(blob=map_data, format="svg") as image:
            png_image = image.make_blob("png")

        response = HttpResponse(png_image, content_type='image/png')
        response['Content-Disposition'] = 'attachment; filename={}.png'.format(map_id)

        return response

    return render_queryset_to_response(
        request=request,
        template="kegg/map.html",
        data={
            'map_id': map_id,
            'map_data': map_data,
            'enzymes': enzymes,
            'metabolites': metabolites,
            'items': items,
            'queries': [] if request.user.is_anonymous() else models.Query.objects.filter(user=request.user.profile),
            'is_anonymous': request.user.is_anonymous()
        }
    )
Ejemplo n.º 2
0
def map_view(request, map_id):
    export = "export_button" in request.POST

    items, enzymes, metabolites = request_extract(request)
    map_data = get_reaction_map(map_id, enzymes, metabolites, export)

    if export:
        map_data = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>""" + map_data

        import wand.image
        with wand.image.Image(blob=map_data.encode("utf-8"), format="svg") as image:
            png_image = image.make_blob("png")

        response = HttpResponse(png_image, content_type='image/png')
        response['Content-Disposition'] = 'attachment; filename={}.png'.format(map_id)

        return response

    return render_queryset_to_response(
        request=request,
        template="kegg/map.html",
        data={
            'map_id': map_id,
            'map_data': map_data,
            'enzymes': enzymes,
            'metabolites': metabolites,
            'items': items,
            'queries': [] if request.user.is_anonymous() else models.Query.objects.filter(user=request.user.profile),
            'is_anonymous': request.user.is_anonymous()
        }
    )
Ejemplo n.º 3
0
def index(request):
    items, enzymes, metabolites = request_extract(request)

    ecs = list(map(lambda x: x[0], enzymes))
    metas = list(map(lambda x: x[0], metabolites))

    query = None

    if len(metas) > 0:
        # reduce magic via https://stackoverflow.com/questions/7088173/
        query = reduce(lambda x, y: x | y, [Q(name__icontains=word) for word in metas])
        query |= reduce(lambda x, y: x | y, [Q(title__icontains=word) for word in metas])

    if len(ecs) > 0:
        if query is None:
            query = Q(ec_numbers__name__in=ecs)
        else:
            query |= Q(ec_numbers__name__in=ecs)

    if query is not None:
        kegg_maps = models.Map.objects.filter(query).distinct()
    else:
        kegg_maps = models.Map.objects.all()

    overview = filter(lambda x: x.overview, kegg_maps)
    other = filter(lambda x: not x.overview, kegg_maps)

    return render_queryset_to_response(
        request=request,
        template="kegg/index.html",
        data={
            'overview_maps': overview,
            'other_maps': other,
            'items': items,
            'queries': [] if request.user.is_anonymous() else models.Query.objects.filter(user=request.user.profile),
            'is_anonymous': request.user.is_anonymous()
        }
    )
Ejemplo n.º 4
0
def index(request):
    items, enzymes, metabolites = request_extract(request)

    ecs = list(map(lambda x: x[0], enzymes))
    metas = list(map(lambda x: x[0], metabolites))

    query = None

    if len(metas) > 0:
        # reduce magic via https://stackoverflow.com/questions/7088173/
        query = reduce(lambda x, y: x | y, [Q(name__icontains=word) for word in metas])
        query |= reduce(lambda x, y: x | y, [Q(title__icontains=word) for word in metas])

    if len(ecs) > 0:
        if query is None:
            query = Q(ec_numbers__name__in=ecs)
        else:
            query |= Q(ec_numbers__name__in=ecs)

    if query is not None:
        kegg_maps = models.Map.objects.filter(query).distinct()
    else:
        kegg_maps = models.Map.objects.all()

    overview = filter(lambda x: x.overview, kegg_maps)
    other = filter(lambda x: not x.overview, kegg_maps)

    return render_queryset_to_response(
        request=request,
        template="kegg/index.html",
        data={
            'overview_maps': overview,
            'other_maps': other,
            'items': items,
            'queries': [] if request.user.is_anonymous() else models.Query.objects.filter(user=request.user.profile),
            'is_anonymous': request.user.is_anonymous()
        }
    )