Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gbrowser #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions dreg_djangoapp/output_views.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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/"

#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)

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
path = urlparse(current_ouput_path).path.replace(data_root+exp_data_dir,"",1).replace('/',"",1)
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'] +\
"/dreg/gbrowser/" + encoded_filelist + "&genome="
js = 'alert("Js is executed")';
return {
'output': render_to_string(
'dreg_djangoapp/dreg_genome_browser.html')
}
'dreg_djangoapp/dreg_genome_browser.html', {'gbURL' : gbURL}),
'js': "/static/dreg/gbrowser.js"
}
7 changes: 7 additions & 0 deletions dreg_djangoapp/static/dreg/gbrowser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$('#gbLinks').on('click', function(e) {
gb = $('#genomebuilder').val();
var gbUrl = e.target.getAttribute('data-url');
console.log(gbUrl + gb)
window.open(gbUrl + gb);
return false;
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
or input
<input type="text" id="customeGB" style="width:40px" />
<button
id="gbLinks"
id="gbLinks" data-url ={{ gbURL }}
style="color: #fff; background-color: #3e5a43; border-color: #46b8da; border: 1px solid transparent;"
>
Switch to genome browser&nbsp;<span
Expand Down
2 changes: 2 additions & 0 deletions dreg_djangoapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
app_name = 'dreg_djangoapp'
urlpatterns = [
url(r'^hello/', views.hello_world, name="hello"),
url(r'^gbrowser/(?P<filelist>[^/]+)/$', views.gbrowser_dreg, name = 'gbrowser_dreg'),
url(r'^gbfile/', views.gbfile_download, name = 'gbfile_download')
]
95 changes: 95 additions & 0 deletions dreg_djangoapp/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
import base64
import os
import json
import re

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, filelist):
print("Dreg view is called....")

#Check if the list of file is included in the request
if filelist:
#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()
print(decoded_filelist)
# 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)
dump_cleaned = re.sub(r'"(\w*?)": ', r'\1:', dump)
#print(dump)
return HttpResponse(dump_cleaned, content_type='text/plain')


def gbfile_download(request):
#TODO: decode filenames and path from the url text
text_format = 'utf-8'
file_path = ""
if 'file' in request.GET:
file = request.GET['file']
decoded_filepath = base64.b64decode(file).decode(text_format)
filename = os.path.basename(decoded_filepath)
data_root = settings.GATEWAY_DATA_STORE_DIR
# Change this to test it locally
#data_root = "/var/www/portals/gateway-user-data/cornelldna/"
#data_root = settings.MEDIA_ROOT + '/dreg/'
file_path = os.path.join(data_root, decoded_filepath.lstrip("/"))

if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/octet-stream")
response['Content-Disposition'] = 'attachment; filename=' + os.path.basename(file_path)
return response
raise Http404