-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
189 lines (126 loc) · 4.73 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from omero.gateway import *
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from omeroweb.webgateway import views as webgateway_views
from omeroweb.connector import Server
from omeroweb.webclient.decorators import login_required, render_response
from omeroweb.connector import Connector
from cStringIO import StringIO
import settings
import logging
import traceback
import omero
from omero.rtypes import rint, rstring, wrap
import omero.gateway
import random
logger = logging.getLogger(__name__)
try:
from PIL import Image
except: #pragma: nocover
try:
import Image
except:
logger.error('No PIL installed, line plots and split channel will fail!')
def index(request,**kwargs):
"""lists all projects with thumbnails"""
conn=BlitzGateway('__public__','s3cr3t5',host='localhost', port=4064)
conn.connect()
# my_expId = conn.getUser().getId()
# projects = conn.listProjects(my_expId)
# projects = conn.getObjects("Project")
# groupId = 3 #public group - this may not be necessary if public user is default for public group.
# conn.SERVICE_OPTS.setOmeroGroup(groupId)
projects = conn.listProjects() #will only list projects in user's default group - default group for __public__ is public group. Projects can be published by moving them from 'private' group to 'public' group using OMERO.insight
# proj_Ids=[]
# for project in projects:
# proj_Ids.append(project.getId())
#return HttpResponse("Welcome to GigaDV home-page!")
return render_to_response('GigaDV/index.html',
{
#'projIDs':proj_Ids,
'projects':projects,
})
def project(request, projId,**kwargs):
"""provides details on a specific project"""
conn=BlitzGateway('__public__','s3cr3t5',host='localhost',port=4064)
conn.connect()
project = conn.getObject("Project",projId)
proj_name = project.getName()
proj_desc = project.getDescription()
dataset_IDs = list(project.listChildren())
# datasets = []
# for dsID in dataset_IDs:
# datasets.append(conn.getObject("Dataset",dsID))
image_IDs = []
for dsid in dataset_IDs:
# code for getting random thumbnail image (using 'rating' of 5 to select good images)
queryService = conn.getQueryService()
params = omero.sys.ParametersI()
params.addLong('dsid', dsid.getId())
params.addLong('five', 5)
params.addString('ratingNs', omero.constants.metadata.NSINSIGHTRATING)
params.theFilter = omero.sys.Filter()
params.theFilter.limit = wrap(1)
query = "select i from Image as i"\
" left outer join i.datasetLinks as dl join dl.parent as dataset"\
" left outer join i.annotationLinks as al join al.child as ann"\
" where dataset.id = :dsid"\
" and ann.ns = :ratingNs and ann.longValue = :five"
img = queryService.findByQuery(query, params, conn.SERVICE_OPTS)
img_id= img.id.val
# end of thumbnail code
image_IDs.append( img_id)
dataset_image_pairs = zip(dataset_IDs,image_IDs)
return render_to_response('GigaDV/project.html',
{'proj_name':proj_name,
'proj_desc':proj_desc,
'datasets':dataset_image_pairs,
})
def dataset(request, projId, dsId,**kwargs):
conn=BlitzGateway('__public__','s3cr3t5',host='localhost',port=4064)
conn.connect()
project = conn.getObject("Project",projId)
ds= conn.getObject("Dataset",dsId)
return render_to_response('GigaDV/dataset.html',
{'dataset':ds,
'project':project,
})
def image(request, projId, dsId, imId,**kwargs):
conn=BlitzGateway('__public__','s3cr3t5', host='localhost', port=4064)
conn.connect()
project=conn.getObject("Project",projId)
ds=conn.getObject("Dataset",dsId)
image=conn.getObject("Image",imId)
return render_to_response('GigaDV/image.html',
{'dataset':ds,
'project':project,
'image':image,
})
def image_view(request,projId, dsId, imageId,**kwargs):
conn=BlitzGateway('root','1234',host='localhost',port=4064)
conn.connect()
project=conn.getObject("Project",projId)
ds=conn.getObject("Dataset",dsId)
return render_to_response('GigaDV/image_view.html',
{'imageId':imageId,
'project':project,
'dataset':ds,
})
def stack_preview(request,imageId,**kwargs):
"""Shows a subset of Z-planes for an image """
conn=BlitzGateway('root','1234',host='localhost',port=4064)
conn.connect()
image = conn.getObject("Image", imageId) #get image from OMERO
image_name = image.getName()
sizeZ = image.getSizeT() #get the z dimension
groupId = image.details.group.id.val
#5 Z-planes
z_indexes = [0,int(sizeZ*0.25), int(sizeZ*0.5),int(sizeZ*0.75), sizeZ-1]
return render_to_response('GigaDV/stack_preview.html',
{'imageId':imageId,
'image_name':image_name,
'z_indexes':z_indexes,
'groupId':groupId})