Commit 6ba6357c authored by Anton Petrov's avatar Anton Petrov
Browse files

Add miRBase word clouds

Fixes #422
parent 2f1ad82a
var mirbaseWordCloud = {
bindings: {
mirbaseId: '<'
},
controller: ['$http', '$interpolate', function($http, $interpolate) {
var ctrl = this;
/**
* Launch a modal showing miRBase word cloud
*/
ctrl.openMirbaseModal = function() {
var mirbase_url = ctrl.getMirbaseWordCloudUrl(ctrl.mirbaseId);
var html = '<img src="' + mirbase_url + '">' +
'<p>' +
'<a target="_blank" href="http://www.mirbase.org/cgi-bin/mirna_entry.pl?acc='+ ctrl.mirbaseId + '">' +
'View ' + ctrl.mirbaseId + ' in miRBase</a>' +
'</p>';
$('#modal-mirbase-word-cloud-image').html(html);
$('#mirbase-modal-parent').detach().appendTo('body');
$('#mirbase-modal-parent').modal();
};
/**
* Get miRBase word cloud URL. Example ID: MI0006423.
*/
ctrl.getMirbaseWordCloudUrl = function() {
return '/api/internal/proxy?url=http://www.mirbase.org/images/wordcloud/' +
ctrl.mirbaseId.slice(2,4) + '/' + ctrl.mirbaseId.slice(4,6) + '/' +
ctrl.mirbaseId.slice(6,8) + '/' + ctrl.mirbaseId + '.png';
}
}],
templateUrl: '/static/js/components/sequence/xrefs/mirbase-word-cloud/mirbase-word-cloud.html',
};
angular.module("rnaSequence").component("mirbaseWordCloud", mirbaseWordCloud);
<div class="col-md-1" style="padding-left: 0;">
<span class="thumbnail" style="cursor: pointer; margin-bottom: 0;" uib-tooltip="Click to expand word cloud"> {{ctrl.mirbaseid}} {{$ctrl.mirbaseid}}
<img onerror="this.parentNode.parentNode.style.display = 'none'" ng-src="{{ $ctrl.getMirbaseWordCloudUrl() }}" ng-click="$ctrl.openMirbaseModal()" alt="miRBase word cloud">
</span>
</div>
......@@ -94,6 +94,7 @@
<!-- miRBase -->
<span ng-switch-when="miRBase">
miRBase:
<mirbase-word-cloud mirbase-id="xref.accession.external_id"></mirbase-word-cloud>
<a class="mirbase-external-url" ng-href="{{ xref.accession.expert_db_url }}" target="_blank">{{ xref.accession.external_id }}</a>
<span ng-if="xref.mirbase_mature_products">
......@@ -437,3 +438,17 @@
<div class="clearfix"></div>
</div>
</div>
<div id="mirbase-modal-parent" class="modal fade" tabindex='-1'>
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<h2>miRBase word cloud based on literature analysis</h2>
<div id="modal-mirbase-word-cloud-image"></div>
</div> <!-- modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
......@@ -198,6 +198,7 @@ limitations under the License.
<script src="{% static "js/components/sequence/xrefs/xref-publications/xref-publications.component.js" %}"></script>
<script src="{% static "js/components/sequence/2d/2d.component.js" %}"></script>
<script src="{% static "js/components/sequence/go-annotations/go-annotations.component.js" %}"></script>
<script src="{% static "js/components/sequence/xrefs/mirbase-word-cloud/mirbase-word-cloud.component.js" %}"></script>
<script src="{% static "js/components/sequence/protein-targets/protein-targets.component.js" %}"></script>
<script src="{% static "js/components/sequence/lncrna-targets/lncrna-targets.component.js" %}"></script>
<script src="{% static "js/components/sequence/rfam/rfam.component.js" %}"></script>
......
......@@ -212,20 +212,22 @@ def proxy(request):
"""
Internal API. Used for:
- EBeye search URL - bypasses EBeye same-origin policy.
- Rfam images - avoids mixed content warnings due to lack of https support in Rfam.
- Rfam and miRBase images - avoids mixed content warnings due to lack of https support in Rfam.
"""
url = request.GET['url']
# check domain for security - we don't want someone to abuse this endpoint
domain = urlparse(url).netloc
if domain != 'www.ebi.ac.uk' and domain != 'wwwdev.ebi.ac.uk' and domain != 'rfam.org':
return HttpResponseForbidden("This proxy is for www.ebi.ac.uk, wwwdev.ebi.ac.uk or rfam.org only.")
if domain != 'www.ebi.ac.uk' and domain != 'wwwdev.ebi.ac.uk' and domain != 'rfam.org' and domain != 'www.mirbase.org':
return HttpResponseForbidden("This proxy is for www.ebi.ac.uk, wwwdev.ebi.ac.uk, mirbase.org or rfam.org only.")
try:
proxied_response = requests.get(url)
if proxied_response.status_code == 200:
if domain == 'rfam.org': # for rfam images don't forget to set content-type header
response = HttpResponse(proxied_response.text, content_type="image/svg+xml")
elif 'mirbase.org' in domain:
response = HttpResponse(proxied_response.content, content_type="image/png")
else:
response = HttpResponse(proxied_response.text)
return response
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment