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 import omero
26 from omero.rtypes import *
27 from django.core.urlresolvers import reverse
28 from django.utils.encoding import smart_str
29 import logging
30
31 logger = logging.getLogger('web-container')
32
33 from webclient.controller import BaseController
34
36
37 project = None
38 screen = None
39 dataset = None
40 plate = None
41 acquisition = None
42 well = None
43 image = None
44 tag = None
45 file = None
46 comment = None
47 tags = None
48
49 index = None
50 containers = None
51 experimenter = None
52
53 c_size = 0
54
55 text_annotations = None
56 txannSize = 0
57 long_annotations = None
58 file_annotations = None
59
60 orphaned = False
61
62 - def __init__(self, conn, project=None, dataset=None, image=None, screen=None, plate=None, acquisition=None, well=None, tag=None, tagset=None, file=None, comment=None, annotation=None, index=None, orphaned=None, **kw):
63 BaseController.__init__(self, conn)
64 if project is not None:
65 self.project = self.conn.getObject("Project", project)
66 if self.project is None:
67 raise AttributeError("We are sorry, but that project (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(project))
68 if self.project._obj is None:
69 raise AttributeError("We are sorry, but that project (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(project))
70 if dataset is not None:
71 self.dataset = self.conn.getObject("Dataset", dataset)
72 if self.dataset is None:
73 raise AttributeError("We are sorry, but that dataset (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(dataset))
74 if self.dataset._obj is None:
75 raise AttributeError("We are sorry, but that dataset (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(dataset))
76 if screen is not None:
77 self.screen = self.conn.getObject("Screen", screen)
78 if self.screen is None:
79 raise AttributeError("We are sorry, but that screen (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(screen))
80 if self.screen._obj is None:
81 raise AttributeError("We are sorry, but that screen (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(screen))
82 if plate is not None:
83 self.plate = self.conn.getObject("Plate", plate)
84 if self.plate is None:
85 raise AttributeError("We are sorry, but that plate (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(plate))
86 if self.plate._obj is None:
87 raise AttributeError("We are sorry, but that plate (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(plate))
88 if acquisition is not None:
89 self.acquisition = self.conn.getObject("PlateAcquisition", acquisition)
90 if self.acquisition is None:
91 raise AttributeError("We are sorry, but that plate acquisition (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(acquisition))
92 if self.acquisition._obj is None:
93 raise AttributeError("We are sorry, but that plate acquisition (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(acquisition))
94 if image is not None:
95 self.image = self.conn.getObject("Image", image)
96 if self.image is None:
97 raise AttributeError("We are sorry, but that image (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(image))
98 if self.image._obj is None:
99 raise AttributeError("We are sorry, but that image (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(image))
100 if well is not None:
101 self.well = self.conn.getObject("Well", well)
102 if self.well is None:
103 raise AttributeError("We are sorry, but that well (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(well))
104 if self.well._obj is None:
105 raise AttributeError("We are sorry, but that well (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(well))
106 if index is not None:
107 self.well.index = index
108 if tag is not None:
109 self.tag = self.conn.getObject("Annotation", tag)
110 if self.tag is None:
111 raise AttributeError("We are sorry, but that tag (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(tag))
112 if self.tag._obj is None:
113 raise AttributeError("We are sorry, but that tag (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(tag))
114 if tagset is not None:
115 self.tag = self.conn.getObject("Annotation", tagset)
116 if self.tag is None:
117 raise AttributeError("We are sorry, but that tag (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(tag))
118 if self.tag._obj is None:
119 raise AttributeError("We are sorry, but that tag (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(tag))
120 if comment is not None:
121 self.comment = self.conn.getObject("Annotation", comment)
122 if self.comment is None:
123 raise AttributeError("We are sorry, but that comment (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(comment))
124 if self.comment._obj is None:
125 raise AttributeError("We are sorry, but that comment (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(comment))
126 if file is not None:
127 self.file = self.conn.getObject("Annotation", file)
128 if self.file is None:
129 raise AttributeError("We are sorry, but that file (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(file))
130 if self.file._obj is None:
131 raise AttributeError("We are sorry, but that file (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(file))
132 if annotation is not None:
133 self.annotation = self.conn.getObject("Annotation", annotation)
134 if self.annotation is None:
135 raise AttributeError("We are sorry, but that annotation (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(annotation))
136 if self.annotation._obj is None:
137 raise AttributeError("We are sorry, but that annotation (id:%s) does not exist, or if it does, you have no permission to see it. Contact the user you think might share that data with you." % str(annotation))
138 if orphaned:
139 self.orphaned = True
140
142 """
143 Is the image suitable to be viewed with the Volume viewer 'Open Astex Viewer' applet?
144 Image must be a 'volume' of suitable dimensions and not too big.
145 """
146 from django.conf import settings
147 MAX_SIDE = settings.OPEN_ASTEX_MAX_SIDE
148 MIN_SIDE = settings.OPEN_ASTEX_MIN_SIDE
149 MAX_VOXELS = settings.OPEN_ASTEX_MAX_VOXELS
150
151 print "Max side, min side, max voxels", MAX_SIDE, MIN_SIDE, MAX_VOXELS
152 if self.image is None:
153 return False
154 sizeZ = self.image.getSizeZ()
155 if self.image.getSizeC() > 1: return False
156 sizeX = self.image.getSizeX()
157 sizeY = self.image.getSizeY()
158 if sizeZ < MIN_SIDE or sizeX < MIN_SIDE or sizeY < MIN_SIDE: return False
159 if sizeX > MAX_SIDE or sizeY > MAX_SIDE or sizeZ > MAX_SIDE: return False
160 voxelCount = (sizeX * sizeY * sizeZ)
161 if voxelCount > MAX_VOXELS: return False
162
163 try:
164 import scipy.ndimage
165 except ImportError:
166 logger.debug("Failed to import scipy.ndimage - Open Astex Viewer limited to display of smaller images.")
167 MAX_VOXELS = (160 * 160 * 160)
168 if voxelCount > MAX_VOXELS: return False
169
170 return True
171
176
189
202
211
213 pr_list = list(self.conn.getObjectsByAnnotations('Project',[self.tag.id]))
214 ds_list = list(self.conn.getObjectsByAnnotations('Dataset',[self.tag.id]))
215 im_list = list(self.conn.getObjectsByAnnotations('Image',[self.tag.id]))
216 sc_list = list(self.conn.getObjectsByAnnotations('Screen',[self.tag.id]))
217 pl_list = list(self.conn.getObjectsByAnnotations('Plate',[self.tag.id]))
218
219 pr_list_with_counters = list()
220 ds_list_with_counters = list()
221 im_list_with_counters = list()
222 sc_list_with_counters = list()
223 pl_list_with_counters = list()
224
225 pr_ids = [pr.id for pr in pr_list]
226 if len(pr_ids) > 0:
227 pr_annotation_counter = self.conn.getCollectionCount("Project", "annotationLinks", pr_ids)
228
229 for pr in pr_list:
230 pr.annotation_counter = pr_annotation_counter.get(pr.id)
231 pr_list_with_counters.append(pr)
232
233 ds_ids = [ds.id for ds in ds_list]
234 if len(ds_ids) > 0:
235 ds_annotation_counter = self.conn.getCollectionCount("Dataset", "annotationLinks", ds_ids)
236
237 for ds in ds_list:
238 ds.annotation_counter = ds_annotation_counter.get(ds.id)
239 ds_list_with_counters.append(ds)
240
241 im_ids = [im.id for im in im_list]
242 if len(im_ids) > 0:
243 im_annotation_counter = self.conn.getCollectionCount("Image", "annotationLinks", im_ids)
244
245 for im in im_list:
246 im.annotation_counter = im_annotation_counter.get(im.id)
247 im_list_with_counters.append(im)
248
249 sc_ids = [sc.id for sc in sc_list]
250 if len(sc_ids) > 0:
251 sc_annotation_counter = self.conn.getCollectionCount("Screen", "annotationLinks", sc_ids)
252
253 for sc in sc_list:
254 sc.annotation_counter = sc_annotation_counter.get(sc.id)
255 sc_list_with_counters.append(sc)
256
257 pl_ids = [pl.id for pl in pl_list]
258 if len(pl_ids) > 0:
259 pl_annotation_counter = self.conn.getCollectionCount("Plate", "annotationLinks", pl_ids)
260
261 for pl in pl_list:
262 pl.annotation_counter = pl_annotation_counter.get(pl.id)
263 pl_list_with_counters.append(pl)
264
265 self.containers={'projects': pr_list_with_counters, 'datasets': ds_list_with_counters, 'images': im_list_with_counters, 'screens':sc_list_with_counters, 'plates':pl_list_with_counters}
266 self.c_size = len(pr_list_with_counters)+len(ds_list_with_counters)+len(im_list_with_counters)+len(sc_list_with_counters)+len(pl_list_with_counters)
267
269 if eid is not None:
270 self.experimenter = self.conn.getObject("Experimenter", eid)
271
272 im_list = list(self.conn.listImagesInDataset(oid=did, eid=eid, page=page))
273
274
275
276
277
278
279
280
281
282
283
284 im_list_with_counters = im_list
285 im_list_with_counters.sort(key=lambda x: x.getName().lower())
286 self.containers = {'images': im_list_with_counters}
287 self.c_size = self.conn.getCollectionCount("Dataset", "imageLinks", [long(did)])[long(did)]
288
289 if page is not None:
290 self.paging = self.doPaging(page, len(im_list_with_counters), self.c_size)
291
293 if eid is not None:
294 self.experimenter = self.conn.getObject("Experimenter", eid)
295 else:
296 eid = self.conn.getEventContext().userId
297
298 pr_list = list(self.conn.listProjects(eid))
299 ds_list = list(self.conn.listOrphans("Dataset", eid))
300 sc_list = list(self.conn.listScreens(eid))
301 pl_list = list(self.conn.listOrphans("Plate", eid))
302
303 pr_list_with_counters = list()
304 ds_list_with_counters = list()
305 sc_list_with_counters = list()
306 pl_list_with_counters = list()
307
308 pr_ids = [pr.id for pr in pr_list]
309 if len(pr_ids) > 0:
310 pr_annotation_counter = self.conn.getCollectionCount("Project", "annotationLinks", pr_ids)
311
312 for pr in pr_list:
313 pr.annotation_counter = pr_annotation_counter.get(pr.id)
314 pr_list_with_counters.append(pr)
315
316 ds_ids = [ds.id for ds in ds_list]
317 if len(ds_ids) > 0:
318 ds_annotation_counter = self.conn.getCollectionCount("Dataset", "annotationLinks", ds_ids)
319
320 for ds in ds_list:
321 ds.annotation_counter = ds_annotation_counter.get(ds.id)
322 ds_list_with_counters.append(ds)
323
324 sc_ids = [sc.id for sc in sc_list]
325 if len(sc_ids) > 0:
326 sc_annotation_counter = self.conn.getCollectionCount("Screen", "annotationLinks", sc_ids)
327
328 for sc in sc_list:
329 sc.annotation_counter = sc_annotation_counter.get(sc.id)
330 sc_list_with_counters.append(sc)
331
332 pl_ids = [pl.id for pl in pl_list]
333 if len(pl_ids) > 0:
334 pl_annotation_counter = self.conn.getCollectionCount("Plate", "annotationLinks", ds_ids)
335
336 for pl in pl_list:
337 pl.annotation_counter = pl_annotation_counter.get(pl.id)
338 pl_list_with_counters.append(pl)
339
340 pr_list_with_counters.sort(key=lambda x: x.getName() and x.getName().lower())
341 ds_list_with_counters.sort(key=lambda x: x.getName() and x.getName().lower())
342 sc_list_with_counters.sort(key=lambda x: x.getName() and x.getName().lower())
343 pl_list_with_counters.sort(key=lambda x: x.getName() and x.getName().lower())
344
345 self.orphans = self.conn.countOrphans("Image", eid)
346
347 self.containers={'projects': pr_list_with_counters, 'datasets': ds_list_with_counters, 'screens': sc_list_with_counters, 'plates': pl_list_with_counters}
348 self.c_size = len(pr_list_with_counters)+len(ds_list_with_counters)+len(sc_list_with_counters)+len(pl_list_with_counters)
349
351 if eid is not None:
352 self.experimenter = self.conn.getObject("Experimenter", eid)
353 else:
354 eid = self.conn.getEventContext().userId
355
356 im_list = list(self.conn.listOrphans("Image", eid=eid, page=page))
357
358
359
360
361
362
363
364
365
366
367
368 im_list_with_counters = im_list
369 im_list_with_counters.sort(key=lambda x: x.getName().lower())
370 self.containers = {'orphaned': True, 'images': im_list_with_counters}
371 self.c_size = self.conn.countOrphans("Image", eid=eid)
372
373 if page is not None:
374 self.paging = self.doPaging(page, len(im_list_with_counters), self.c_size)
375
376
435
436
460
462 eid = self.conn.getGroupFromContext().isReadOnly() and self.conn.getEventContext().userId or None
463 ns = [omero.constants.namespaces.NSCOMPANIONFILE, omero.constants.namespaces.NSEXPERIMENTERPHOTO]
464
465 if self.image is not None:
466 return list(self.image.listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
467 elif self.dataset is not None:
468 return list(self.dataset.listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
469 elif self.project is not None:
470 return list(self.project.listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
471 elif self.well is not None:
472 return list(self.well.getWellSample().image().listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
473 elif self.plate is not None:
474 return list(self.plate.listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
475 elif self.screen is not None:
476 return list(self.screen.listOrphanedAnnotations(eid=eid, ns=ns, anntype='File'))
477 else:
478 eid = self.conn.getGroupFromContext().isReadOnly() and self.conn.getEventContext().userId or None
479 if eid is not None:
480 params = omero.sys.Parameters()
481 params.theFilter = omero.sys.Filter()
482 params.theFilter.ownerId = omero.rtypes.rlong(eid)
483 return list(self.conn.listFileAnnotations(params=params))
484 return list(self.conn.listFileAnnotations())
485
486
487
499
506
513
514
535
536
548
550 otype = str(otype).lower()
551 if not otype in ("project", "dataset", "image", "screen", "plate", "acquisition", "well"):
552 raise AttributeError("Object type must be: project, dataset, image, screen, plate, acquisition, well. ")
553 if otype == 'well':
554 otype = 'Image'
555 selfobject = self.well.getWellSample().image()
556 elif otype == 'acquisition':
557 otype = 'PlateAcquisition'
558 selfobject = self.acquisition
559 else:
560 selfobject = getattr(self, otype)
561 otype = otype.title()
562
563 ann = None
564 try:
565 ann = self.conn.findTag(tag, desc)._obj
566 except:
567 pass
568 if ann is None:
569 ann = omero.model.TagAnnotationI()
570 ann.textValue = rstring(str(tag))
571 ann.setDescription(rstring(str(desc)))
572 t_ann = getattr(omero.model, otype+"AnnotationLinkI")()
573 t_ann.setParent(selfobject._obj)
574 t_ann.setChild(ann)
575 self.conn.saveObject(t_ann)
576 else:
577
578 params = omero.sys.Parameters()
579 params.theFilter = omero.sys.Filter()
580 params.theFilter.ownerId = rlong(self.conn.getUser().id)
581 links = self.conn.getAnnotationLinks(otype, parent_ids=[selfobject.id], ann_ids=[ann.id.val], params=params)
582 links = list(links)
583 if len(links) == 0:
584 t_ann = getattr(omero.model, otype+"AnnotationLinkI")()
585 t_ann.setParent(selfobject._obj)
586 t_ann.setChild(ann)
587 self.conn.saveObject(t_ann)
588
590 if file_type is None or len(file_type) == 0:
591 file_type = "application/octet-stream"
592 return file_type
593
595 otype = str(otype).lower()
596 if not otype in ("project", "dataset", "image", "screen", "plate", "acquisition", "well"):
597 raise AttributeError("Object type must be: project, dataset, image, screen, plate, acquisition, well. ")
598 if otype == 'well':
599 otype = 'Image'
600 selfobject = self.well.getWellSample().image()
601 elif otype == 'acquisition':
602 otype = 'PlateAcquisition'
603 selfobject = self.acquisition
604 else:
605 selfobject = getattr(self, otype)
606 otype = otype.title()
607
608 format = self.checkMimetype(newFile.content_type)
609
610 oFile = omero.model.OriginalFileI()
611 oFile.setName(rstring(smart_str(newFile.name)));
612 oFile.setPath(rstring(smart_str(newFile.name)));
613 oFile.setSize(rlong(long(newFile.size)));
614 oFile.setSha1(rstring("pending"));
615 oFile.setMimetype(rstring(str(format)));
616
617 ofid = self.conn.saveAndReturnId(oFile);
618 of = self.conn.saveAndReturnFile(newFile, ofid)
619
620 fa = omero.model.FileAnnotationI()
621 fa.setFile(of)
622 l_ia = getattr(omero.model, otype+"AnnotationLinkI")()
623 l_ia.setParent(selfobject._obj)
624 l_ia.setChild(fa)
625 self.conn.saveObject(l_ia)
626
652
654 ann = None
655 try:
656 ann = self.conn.findTag(tag, desc)
657 except:
658 pass
659 if ann is None:
660 ann = omero.model.TagAnnotationI()
661 ann.textValue = rstring(str(tag))
662 ann.setDescription(rstring(str(desc)))
663 ann = self.conn.saveAndReturnObject(ann)
664
665 new_links = list()
666 for k in oids:
667 if len(oids[k]) > 0:
668 for ob in oids[k]:
669 if isinstance(ob._obj, omero.model.WellI):
670 t = 'Image'
671 obj = ob.getWellSample().image()
672 elif isinstance(ob._obj, omero.model.PlateAcquisitionI):
673 t = 'PlateAcquisition'
674 obj = ob
675 else:
676 t = k.lower().title()
677 obj = ob
678 l_ann = getattr(omero.model, t+"AnnotationLinkI")()
679 l_ann.setParent(obj._obj)
680 l_ann.setChild(ann._obj)
681 new_links.append(l_ann)
682 if len(new_links) > 0 :
683 self.conn.saveArray(new_links)
684
721
722
724 otype = str(otype).lower()
725 if not otype in ("project", "dataset", "image", "screen", "plate", "acquisition", "well"):
726 raise AttributeError("Object type must be: project, dataset, image, screen, plate, acquisition, well.")
727 atype = str(atype).lower()
728 if not atype in ("tag", "comment", "file"):
729 raise AttributeError("Object type must be: tag, comment, file.")
730 if otype == 'well':
731 otype = 'Image'
732 selfobject = self.well.getWellSample().image()
733 elif otype == 'acquisition':
734 otype = 'PlateAcquisition'
735 selfobject = self.acquisition
736 else:
737 selfobject = getattr(self, otype)
738 otype = otype.title()
739
740 new_links = list()
741 for a in self.conn.getObjects("Annotation", ids):
742 ann = getattr(omero.model, otype+"AnnotationLinkI")()
743 ann.setParent(selfobject._obj)
744 ann.setChild(a._obj)
745 new_links.append(ann)
746
747 failed = 0
748 try:
749 self.conn.saveArray(new_links)
750 except omero.ValidationException, x:
751 for l in new_links:
752 try:
753 self.conn.saveObject(l)
754 except:
755 failed+=1
756 return failed
757
759
760 atype = str(atype).lower()
761 if not atype.lower() in ("tag", "comment", "file"):
762 raise AttributeError("Object type must be: tag, comment, file.")
763
764 new_links = list()
765 for k in oids:
766 if len(oids[k]) > 0:
767 if k.lower() == 'acquisitions':
768 t = 'PlateAcquisition'
769 else:
770 t = k.lower().title()
771 for ob in self.conn.getObjects(t, [o.id for o in oids[k]]):
772 for a in self.conn.getObjects("Annotation", tids):
773 if isinstance(ob._obj, omero.model.WellI):
774 t = 'Image'
775 obj = ob.getWellSample().image()
776 else:
777 obj = ob
778 l_ann = getattr(omero.model, t+"AnnotationLinkI")()
779 l_ann.setParent(obj._obj)
780 l_ann.setChild(a._obj)
781 new_links.append(l_ann)
782 failed = 0
783 try:
784 self.conn.saveArray(new_links)
785 except omero.ValidationException, x:
786 for l in new_links:
787 try:
788 self.conn.saveObject(l)
789 except:
790 failed+=1
791 return failed
792
793
794
795
803
811
820
829
838
847
856
861
870
871 - def move(self, parent, destination):
872 if self.project is not None:
873 return 'Cannot move project.'
874 elif self.dataset is not None:
875 if destination[0] == 'dataset':
876 return 'Cannot move dataset to dataset'
877 elif destination[0] == 'project':
878 up_pdl = None
879 pdls = self.dataset.getParentLinks()
880 already_there = None
881
882 for pdl in pdls:
883 if pdl.parent.id.val == long(destination[1]):
884 already_there = True
885 if pdl.parent.id.val == long(parent[1]):
886 up_pdl = pdl
887 if already_there:
888 if long(parent[1]) != long(destination[1]):
889 self.conn.deleteObjectDirect(up_pdl._obj)
890 else:
891 new_pr = self.conn.getObject("Project", destination[1])
892 if parent[0] not in ('experimenter', 'orphaned'):
893 up_pdl.setParent(new_pr._obj)
894 self.conn.saveObject(up_pdl._obj)
895 else:
896 up_pdl = omero.model.ProjectDatasetLinkI()
897 up_pdl.setChild(self.dataset._obj)
898 up_pdl.setParent(new_pr._obj)
899 self.conn.saveObject(up_pdl)
900 elif destination[0] == 'experimenter':
901 up_pdl = None
902 for p in self.dataset.getParentLinks():
903 if p.parent.id.val == long(parent[1]):
904 up_pdl = p
905 self.conn.deleteObjectDirect(up_pdl._obj)
906 elif destination[0] == 'orphaned':
907 return 'Cannot move dataset to orphaned images.'
908 else:
909 return 'Destination not supported.'
910 elif self.image is not None:
911 if destination[0] == 'dataset':
912 up_dsl = None
913 dsls = self.image.getParentLinks()
914 already_there = None
915
916
917 for dsl in dsls:
918
919 if dsl.parent.id.val == long(destination[1]):
920 already_there = True
921
922 if dsl.parent.id.val == long(parent[1]):
923 up_dsl = dsl
924 if already_there:
925
926 if long(parent[1]) != long(destination[1]):
927 self.conn.deleteObjectDirect(up_dsl._obj)
928 else:
929
930 new_ds = self.conn.getObject("Dataset", destination[1])
931 if parent[0] not in ('experimenter', 'orphaned'):
932 up_dsl.setParent(new_ds._obj)
933 self.conn.saveObject(up_dsl._obj)
934 else:
935 up_dsl = omero.model.DatasetImageLinkI()
936 up_dsl.setChild(self.image._obj)
937 up_dsl.setParent(new_ds._obj)
938 self.conn.saveObject(up_dsl)
939 elif destination[0] == 'project':
940 return 'Cannot move image to project.'
941 elif destination[0] == 'experimenter' or destination[0] == 'orphaned':
942 if parent[0] != destination[0]:
943 up_dsl = None
944 dsls = list(self.image.getParentLinks())
945 if len(dsls) == 1:
946
947 if dsls[0].parent.id.val == long(parent[1]):
948 up_dsl = dsls[0]
949 self.conn.deleteObjectDirect(up_dsl._obj)
950 else:
951 return 'This image is linked in multiple places. Please unlink the image first.'
952 else:
953 return 'Destination not supported.'
954 elif self.screen is not None:
955 return 'Cannot move screen.'
956 elif self.plate is not None:
957 if destination[0] == 'plate':
958 return 'Cannot move plate to plate'
959 elif destination[0] == 'screen':
960 up_spl = None
961 spls = self.plate.getParentLinks()
962 already_there = None
963
964 for spl in spls:
965 if spl.parent.id.val == long(destination[1]):
966 already_there = True
967 if spl.parent.id.val == long(parent[1]):
968 up_spl = spl
969 if already_there:
970 if long(parent[1]) != long(destination[1]):
971 self.conn.deleteObjectDirect(up_spl._obj)
972 else:
973 new_sc = self.conn.getObject("Screen", destination[1])
974 if parent[0] not in ('experimenter', 'orphaned'):
975 up_spl.setParent(new_sc._obj)
976 self.conn.saveObject(up_spl._obj)
977 else:
978 up_spl = omero.model.ScreenPlateLinkI()
979 up_spl.setChild(self.plate._obj)
980 up_spl.setParent(new_sc._obj)
981 self.conn.saveObject(up_spl)
982 elif destination[0] == 'experimenter' or destination[0] == 'orphaned':
983 if parent[0] != destination[0]:
984 up_spl = None
985 spls = list(self.plate.getParentLinks())
986 if len(spls) == 1:
987
988 if spls[0].parent.id.val == long(parent[1]):
989 up_spl = spls[0]
990 self.conn.deleteObjectDirect(up_spl._obj)
991 else:
992 return 'This plate is linked in multiple places. Please unlink the plate first.'
993 else:
994 return 'Destination not supported.'
995 else:
996 return 'No data was choosen.'
997 return
998
1040
1048
1049
1050
1051
1052 - def paste(self, destination):
1053 if self.project is not None:
1054 return 'Cannot paste project.'
1055 elif self.dataset is not None:
1056 if destination[0] == 'dataset':
1057 return 'Cannot paste dataset to dataset'
1058 elif destination[0] == 'project':
1059 pdls = self.dataset.getParentLinks()
1060 already_there = None
1061
1062 for pdl in pdls:
1063 if pdl.parent.id.val == long(destination[1]):
1064 already_there = True
1065 if already_there:
1066 return 'Dataset is already there.'
1067 else:
1068 new_pr = self.conn.getObject("Project", destination[1])
1069 up_pdl = omero.model.ProjectDatasetLinkI()
1070 up_pdl.setChild(self.dataset._obj)
1071 up_pdl.setParent(new_pr._obj)
1072 self.conn.saveObject(up_pdl)
1073 else:
1074 return 'Destination not supported.'
1075 elif self.image is not None:
1076 if destination[0] == 'dataset':
1077 dsls = self.image.getParentLinks()
1078 already_there = None
1079
1080
1081 for dsl in dsls:
1082
1083 if dsl.parent.id.val == long(destination[1]):
1084 already_there = True
1085 if already_there:
1086 return 'Image is already there.'
1087 else:
1088
1089 new_ds = self.conn.getObject("Dataset", destination[1])
1090 up_dsl = omero.model.DatasetImageLinkI()
1091 up_dsl.setChild(self.image._obj)
1092 up_dsl.setParent(new_ds._obj)
1093 self.conn.saveObject(up_dsl)
1094 elif destination[0] == 'project':
1095 return 'Cannot copy image to project.'
1096 else:
1097 return 'Destination not supported.'
1098 elif self.screen is not None:
1099 return 'Cannot paste screen.'
1100 elif self.plate is not None:
1101 if destination[0] == 'plate':
1102 return 'Cannot move plate to plate'
1103 elif destination[0] == 'screen':
1104 spls = self.plate.getParentLinks()
1105 already_there = None
1106
1107 for spl in spls:
1108 if spl.parent.id.val == long(destination[1]):
1109 already_there = True
1110 if already_there:
1111 return 'Plate is already there.'
1112 else:
1113 new_sc = self.conn.getObject("Screen", destination[1])
1114 up_spl = omero.model.ScreenPlateLinkI()
1115 up_spl.setChild(self.plate._obj)
1116 up_spl.setParent(new_sc._obj)
1117 self.conn.saveObject(up_spl)
1118 else:
1119 return 'Destination not supported.'
1120 else:
1121 return 'No data was choosen.'
1122
1124 if destination is None:
1125 dsls = self.conn.getDatasetImageLinks(source[1])
1126 for dsl in dsls:
1127 self.conn.deleteObjectDirect(dsl._obj)
1128 else:
1129 im = self.conn.getObject("Image", source[1])
1130 ds = self.conn.getObject("Dataset", destination[1])
1131 new_dsl = omero.model.DatasetImageLinkI()
1132 new_dsl.setChild(im._obj)
1133 new_dsl.setParent(ds._obj)
1134 self.conn.saveObject(new_dsl)
1135
1137 if dataset is not None and dataset[0] is not "dataset":
1138 ims = self.conn.getObjects("Image", images)
1139 ds = self.conn.getObject("Dataset", dataset[1])
1140 link_array = list()
1141 for im in ims:
1142 new_dsl = omero.model.DatasetImageLinkI()
1143 new_dsl.setChild(im._obj)
1144 new_dsl.setParent(ds._obj)
1145 link_array.append(new_dsl)
1146 self.conn.saveArray(link_array)
1147 raise AttributeError("Destination not supported")
1148
1150 if destination is not None and destination[0] is not "project":
1151 ds = self.conn.getObject("Dataset", source[1])
1152 pr = self.conn.getObject("Project", destination[1])
1153 new_pdl = omero.model.ProjectDatasetLinkI()
1154 new_pdl.setChild(ds._obj)
1155 new_pdl.setParent(pr._obj)
1156 self.conn.saveObject(new_pdl)
1157 raise AttributeError("Destination not supported")
1158
1160 if project is not None and project[0] is not "project":
1161 dss = self.conn.getObjects("Dataset", datasets)
1162 pr = self.conn.getObject("Project", project[1])
1163 link_array = list()
1164 for ds in dss:
1165 new_pdl = omero.model.ProjectDatasetLinkI()
1166 new_pdl.setChild(ds._obj)
1167 new_pdl.setParent(pr._obj)
1168 link_array.append(new_pdl)
1169 self.conn.saveArray(link_array)
1170 raise AttributeError("Destination not supported")
1171
1173 if destination is not None and destination[0] is not "screen":
1174 pl = self.conn.getObject("Plate", source[1])
1175 sc = self.conn.getObject("Screen", destination[1])
1176 new_spl = omero.model.ScreenPlateLinkI()
1177 new_spl.setChild(pl._obj)
1178 new_spl.setParent(sc._obj)
1179 self.conn.saveObject(new_spl)
1180 raise AttributeError("Destination not supported")
1181
1183 if screen is not None and screen[0] is not "screen":
1184 pls = self.conn.getObjects("Plate", plates)
1185 sc = self.conn.getObject("Screen", screen[1])
1186 link_array = list()
1187 for pl in pls:
1188 new_spl = omero.model.ScreenPlateLinkI()
1189 new_spl.setChild(pl._obj)
1190 new_spl.setParent(sc._obj)
1191 link_array.append(new_spl)
1192 self.conn.saveArray(link_array)
1193 raise AttributeError("Destination not supported")
1194
1195
1196
1197
1198
1200 handle = None
1201 if self.image:
1202 handle = self.conn.deleteObjects("Image", [self.image.id], deleteAnns=anns)
1203 elif self.dataset:
1204 handle = self.conn.deleteObjects("Dataset", [self.dataset.id], deleteChildren=child, deleteAnns=anns)
1205 elif self.project:
1206 handle = self.conn.deleteObjects("Project", [self.project.id], deleteChildren=child, deleteAnns=anns)
1207 elif self.screen:
1208 handle = self.conn.deleteObjects("Screen", [self.screen.id], deleteChildren=child, deleteAnns=anns)
1209 elif self.plate:
1210 handle = self.conn.deleteObjects("Plate", [self.plate.id], deleteAnns=anns)
1211 elif self.comment:
1212 handle = self.conn.deleteObjects("Annotation", [self.comment.id], deleteAnns=anns)
1213 elif self.tag:
1214 handle = self.conn.deleteObjects("Annotation", [self.tag.id], deleteAnns=anns)
1215 elif self.file:
1216 handle = self.conn.deleteObjects("Annotation", [self.file.id], deleteAnns=anns)
1217 return handle
1218
1220 return self.conn.deleteObjects(otype, ids, deleteChildren=child, deleteAnns=anns)
1221