From 7b5aee277e24b82c1825309a068209985c191468 Mon Sep 17 00:00:00 2001 From: Shivam Rastogi Date: Mon, 2 Sep 2019 17:17:34 -0700 Subject: [PATCH 1/5] Added code for creating the URL for genome browser. --- dreg_djangoapp/output_views.py | 52 +++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/dreg_djangoapp/output_views.py b/dreg_djangoapp/output_views.py index 6299bf7..4902874 100644 --- a/dreg_djangoapp/output_views.py +++ b/dreg_djangoapp/output_views.py @@ -1,4 +1,11 @@ from django.template.loader import render_to_string +from airavata.model.application.io.ttypes import DataType +from airavata.model.data.replica.ttypes import ( + ReplicaLocationCategory, +) +from django.conf import settings +from urllib.parse import urlparse, urlencode +import base64 class DregGenomeBrowserViewProvider: @@ -9,7 +16,50 @@ class DregGenomeBrowserViewProvider: # fixture_output_file = "" def generate_data(self, request, experiment_output, experiment, output_file=None): + #Changing test experiment as all files are not present in the provided experiment + #experiment = request.airavata_client.getExperiment(request.authz_token, 'Clone_of_dREG_peak_calling_on_Aug_9,_2019_10:30_AM_2a27c8d8-6985-4795-9bd3-f6d28619c57f') + + exp_data_dir = experiment.userConfigurationData.experimentDataDir + data_root = settings.GATEWAY_DATA_STORE_DIR + #data_root = "/var/www/portals/gateway-user-data/cornelldna/" + + if exp_data_dir.startswith(data_root): + exp_data_dir = exp_data_dir.replace(data_root, "", 1) + + param_prefix = "out" + + filelist = '' + if ( len(experiment.experimentInputs) > 0): + for input in experiment.experimentInputs: + if(input.type == DataType.URI): + data_product_model = request.airavata_client.getDataProduct( + request.authz_token, input.value) + for rp in data_product_model.replicaLocations: + if rp.replicaLocationCategory == ReplicaLocationCategory.GATEWAY_DATA_STORE: + current_ouput_path = rp.filePath + #print("*********",current_ouput_path) + path = urlparse(current_ouput_path).path.replace(data_root+exp_data_dir,"",1).replace('/',"",1) + #print("*********", path) + break + + filelist = filelist + path + "\n" + else: + filelist = filelist + input.value + "\n" + + filelist = exp_data_dir + "/\n" + filelist + filelist = filelist + param_prefix + "\n"; + + encoded_filelist = base64.b64encode(bytes(filelist, 'utf-8')).decode('utf-8') + + #build url + http_protocol = request.scheme + + gbURL = "http://epigenomegateway.wustl.edu/browser/?datahub=" + \ + http_protocol + "://" + request.META['HTTP_HOST'] +\ + "/api/gbrowser/?filelist=" + encoded_filelist + "&genome=" + return { 'output': render_to_string( - 'dreg_djangoapp/dreg_genome_browser.html') + 'dreg_djangoapp/dreg_genome_browser.html'), + 'js': '' } From e17761e9b513d26cbc7f49148c1bbf35ed733f05 Mon Sep 17 00:00:00 2001 From: Shivam Rastogi Date: Sun, 8 Sep 2019 12:39:15 -0700 Subject: [PATCH 2/5] Transfering the urls.py and view methods from django_airavata to dreg_django app --- dreg_djangoapp/output_views.py | 6 +-- dreg_djangoapp/urls.py | 2 + dreg_djangoapp/views.py | 94 ++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) diff --git a/dreg_djangoapp/output_views.py b/dreg_djangoapp/output_views.py index 4902874..184a0e3 100644 --- a/dreg_djangoapp/output_views.py +++ b/dreg_djangoapp/output_views.py @@ -56,10 +56,10 @@ def generate_data(self, request, experiment_output, experiment, output_file=None gbURL = "http://epigenomegateway.wustl.edu/browser/?datahub=" + \ http_protocol + "://" + request.META['HTTP_HOST'] +\ - "/api/gbrowser/?filelist=" + encoded_filelist + "&genome=" + "/dreg/gbrowser/?filelist=" + encoded_filelist + "&genome=" return { 'output': render_to_string( 'dreg_djangoapp/dreg_genome_browser.html'), - 'js': '' - } + 'js': "console.log('It was passed from the outputprovider')" + } diff --git a/dreg_djangoapp/urls.py b/dreg_djangoapp/urls.py index fe4b343..32c2b06 100644 --- a/dreg_djangoapp/urls.py +++ b/dreg_djangoapp/urls.py @@ -5,4 +5,6 @@ app_name = 'dreg_djangoapp' urlpatterns = [ url(r'^hello/', views.hello_world, name="hello"), + url(r'^gbrowser/', views.gbrowser_dreg, name = 'gbrowser_dreg'), + url(r'^gbfile/', views.gbfile_download, name = 'gbfile_download') ] diff --git a/dreg_djangoapp/views.py b/dreg_djangoapp/views.py index f5a69ec..082d86f 100644 --- a/dreg_djangoapp/views.py +++ b/dreg_djangoapp/views.py @@ -1,5 +1,99 @@ +import base64 +import os +import json + from django.shortcuts import render +from django.http import Http404, HttpResponse +from django.conf import settings # Create your views here. def hello_world(request): return render(request, "dynamic_djangoapp/hello.html") + + +def gbrowser_dreg(request): + print("Dreg view is called....") + + #Check if the list of file is included in the request + if 'filelist' in request.GET: + filelist = request.GET['filelist'] + data_root = settings.GATEWAY_DATA_STORE_DIR + #data_root = "/var/www/portals/gateway-user-data/cornelldna/" + http_protocol = request.scheme + text_format = 'utf-8' + json_data = [] + content = {} + + decoded_filelist = base64.b64decode(filelist).decode(text_format).split("\n") + out_prefix = decoded_filelist[3] + filelist_encoded = list() + + # input file 1 + content['type']= "bigwig" + encoded_file = base64.b64encode(bytes(decoded_filelist[0] + decoded_filelist[1], text_format)).decode(text_format) + content['url'] = http_protocol + '://' + request.META['HTTP_HOST'] + '/dreg/gbfile/?file=' + encoded_file + content['name'] = decoded_filelist[1] + content['summarymethod'] = "max" + content['colorpositive'] = "#C5000B" + content['colornegative'] = "#0084D1" + content['height'] = 100 + content['mode'] = "show" + json_data.append(dict(content)) + + # input file 2 + encoded_file = base64.b64encode(bytes(decoded_filelist[0] + decoded_filelist[2], text_format)).decode(text_format) + content['url'] = http_protocol + '://' + request.META['HTTP_HOST'] + '/dreg/gbfile/?file=' + encoded_file + content['name'] = decoded_filelist[2] + json_data.append(dict(content)) + + # out file 1 + encoded_file = base64.b64encode(bytes(decoded_filelist[0]+'ARCHIVE/out.dREG.infp.bw', text_format)).decode(text_format) + content['url'] = http_protocol + '://' + request.META['HTTP_HOST'] + '/dreg/gbfile/?file=' + encoded_file + content['name'] = "dREG Info. Sites:" + content['mode'] = "show" + content['colorpositive'] = "#B30086" + content['colornegative'] = "#0000e5" + content['backgroundcolor'] = "#ffffe5" + content["height"] = 40 + content['fixedscale'] = dict({'min':0, 'max':1}) + json_data.append(dict(content)) + + # out file 2 + encoded_file = base64.b64encode(bytes(decoded_filelist[0]+'ARCHIVE/out.dREG.peak.score.bw', text_format)).decode(text_format) + content['url'] = http_protocol + '://' + request.META['HTTP_HOST'] + '/dreg/gbfile/?file=' + encoded_file + content['name'] = "dREG Peak Calling:" + content['mode'] = "show" + content['colorpositive'] = "#B30086" + content['colornegative'] = "#0000e5" + content['backgroundcolor'] = "#ffffe5" + content["height"] = 40 + content['fixedscale'] = dict({'min':0.2, 'max':1.0}) + json_data.append(dict(content)) + print(json_data) + + dump = json.dumps(json_data) + #print(dump) + return HttpResponse(dump, content_type='text/plain') + + +def gbfile_download(request): + #TODO: decode filenames and path from the url text + text_format = 'utf-8' + if 'file' in request.GET: + file = request.GET['file'] + decoded_filepath = base64.b64decode(file).decode(text_format) + #print(decoded_filepath) + filename = os.path.basename(decoded_filepath) + #print(filename) + #data_root = settings.GATEWAY_DATA_STORE_DIR + #data_root = "/var/www/portals/gateway-user-data/cornelldna/" + data_root = settings.MEDIA_ROOT + '/dreg/' + file_path = os.path.join(data_root, decoded_filepath) + #print(file_path) + #file_path = os.path.join(settings.MEDIA_ROOT, "images/xsede.original.png") + if os.path.exists(file_path): + with open(file_path, 'rb') as fh: + response = HttpResponse(fh.read(), content_type="application/force-download") + response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path) + return response + raise Http404 From 166d7881a778f3f32cb9d848f30bd4faa7b73d97 Mon Sep 17 00:00:00 2001 From: Shivam Rastogi Date: Mon, 9 Sep 2019 01:03:49 -0700 Subject: [PATCH 3/5] Adding functionality to call js from output view and removing print statements. --- dreg_djangoapp/output_views.py | 10 +++++----- .../dreg_djangoapp/dreg_genome_browser.html | 2 +- dreg_djangoapp/views.py | 13 ++++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dreg_djangoapp/output_views.py b/dreg_djangoapp/output_views.py index 184a0e3..d172d2b 100644 --- a/dreg_djangoapp/output_views.py +++ b/dreg_djangoapp/output_views.py @@ -23,6 +23,8 @@ def generate_data(self, request, experiment_output, experiment, output_file=None data_root = settings.GATEWAY_DATA_STORE_DIR #data_root = "/var/www/portals/gateway-user-data/cornelldna/" + #remove data root from the path so that gbfile and gbrowser views can + #read the data root from settings if exp_data_dir.startswith(data_root): exp_data_dir = exp_data_dir.replace(data_root, "", 1) @@ -37,9 +39,7 @@ def generate_data(self, request, experiment_output, experiment, output_file=None for rp in data_product_model.replicaLocations: if rp.replicaLocationCategory == ReplicaLocationCategory.GATEWAY_DATA_STORE: current_ouput_path = rp.filePath - #print("*********",current_ouput_path) path = urlparse(current_ouput_path).path.replace(data_root+exp_data_dir,"",1).replace('/',"",1) - #print("*********", path) break filelist = filelist + path + "\n" @@ -57,9 +57,9 @@ def generate_data(self, request, experiment_output, experiment, output_file=None gbURL = "http://epigenomegateway.wustl.edu/browser/?datahub=" + \ http_protocol + "://" + request.META['HTTP_HOST'] +\ "/dreg/gbrowser/?filelist=" + encoded_filelist + "&genome=" - + js = 'alert("Js is executed")'; return { 'output': render_to_string( - 'dreg_djangoapp/dreg_genome_browser.html'), - 'js': "console.log('It was passed from the outputprovider')" + 'dreg_djangoapp/dreg_genome_browser.html', {'gbURL' : gbURL}), + 'js': js } diff --git a/dreg_djangoapp/templates/dreg_djangoapp/dreg_genome_browser.html b/dreg_djangoapp/templates/dreg_djangoapp/dreg_genome_browser.html index cc6d941..b759287 100644 --- a/dreg_djangoapp/templates/dreg_djangoapp/dreg_genome_browser.html +++ b/dreg_djangoapp/templates/dreg_djangoapp/dreg_genome_browser.html @@ -8,7 +8,7 @@ or input