Ejemplo n.º 1
0
    def getImageMetadata(self):
        metadata = WebServiceArray()

        if self.user and self.user.is_authenticated():
            if self.unlimited:
                allowedImages = (
                    Picture.objects.filter(isPrivate=False)
                    | Picture.objects.filter(user__exact=self.user,
                                             isPrivate=True))[self.offset:]
            else:
                allowedImages = (Picture.objects.filter(isPrivate=False)
                                 | Picture.objects.filter(
                                     user__exact=self.user,
                                     isPrivate=True))[self.offset:self.offset +
                                                      self.limit]
        else:
            if self.unlimited:
                allowedImages = Picture.objects.filter(
                    isPrivate=False)[self.offset:]
            else:
                allowedImages = Picture.objects.filter(
                    isPrivate=False)[self.offset:self.offset + self.limit]

        imageMetadataAPI = ImageMetadataAPI(self.user, self.fields)

        for image in allowedImages:
            metadata.put(
                imageMetadataAPI.getImageMetadata(image, False).getObject())

        return metadata
Ejemplo n.º 2
0
    def doProcessRender(self, request):
        self.setLayout('admin/imageEditor.html')
        try:
            imageKey = request.GET.get('imageId', None)
            if (imageKey):
                image = Picture.objects.get(pk__exact=imageKey)

                # initialize tagging APIs
                tagGroupAPI = TagGroupAPI(unlimited=True)
                tagAPI = TagAPI(unlimited=True)
                geneLinkAPI = GeneLinkAPI(unlimited=True)
                tagGroups = tagGroupAPI.getTagGroupsByImage(image,
                                                            False).getObject()

                for group in tagGroups:

                    tags = tagAPI.getTagsByTagGroup(group['id']).getObject()
                    #tags = tagAPI.getTagsByImage(group['imageId']).getObject()
                    #print('tags= ' + json.dumps(tags))
                    #print('group id= ' + json.dumps(group))
                    for tag in tags:
                        geneLinks = geneLinkAPI.getGeneLinksByTag(
                            tag['id']).getObject()
                        tag['geneLinks'] = geneLinks
                        #print('tag= ' + json.dumps(tag))
                    group['tags'] = tags

                #print('tagGroups= ' + json.dumps(tagGroups))

                # initialize image metadata API
                imageMetadataAPI = ImageMetadataAPI(request.user)
                imageMetadata = imageMetadataAPI.getImageMetadata(
                    image, isKey=False).getObject()

                # add to recently viewed images - modified by ktcho, 2017.10.09
                # moved from get.py to here (add only when user view image via image editor/viewer)
                if (request.user):
                    RecentlyViewedPicture.objects.get_or_create(
                        user=request.user, picture=image)[0].save()

                return {
                    'imageMetadata': json.dumps(imageMetadata),
                    'tagGroups': json.dumps(tagGroups),
                    'image': image
                }
            else:
                self.setLayout('public/404Media.html')
                return {}
        except ObjectDoesNotExist:
            self.setLayout('public/404Media.html')
            return {}
        except KeyError:
            self.setLayout('public/404Media.html')
            return {}
Ejemplo n.º 3
0
    def getImageMetadataByOrganism(self, organismId):
        metadata = WebServiceObject()
        
        if self.user and self.user.is_authenticated():
            allowedImages = Picture.objects.filter(isPrivate=False) | Picture.objects.filter(user__exact=self.user, isPrivate=True) 
        else:
            allowedImages = Picture.objects.filter(isPrivate=False)
        
        defTags = []    
        
        if self.unlimited:
            for orgId in organismId:
                defTags.append(PictureDefinitionTag.objects.filter(organism__exact=orgId, picture__in=allowedImages)[self.offset:])
        else:
            for orgId in organismId:
                defTags.append(PictureDefinitionTag.objects.filter(organism__exact=orgId, picture__in=allowedImages)[self.offset:self.offset + self.limit])   

        closedSet = {}
        imageMetadata = {}
        imageFields = set(['id' , 'url', 'uploadDate', 'description', 'uploadedBy'])
        if self.fields:
            newImageFields = imageFields.intersection(set(self.fields))
            if newImageFields:
                imageFields = newImageFields
        imageMetadataAPI = ImageMetadataAPI(self.user, imageFields)
        
        for orgTags in defTags:
            for tag in orgTags:
                if not closedSet.has_key(tag.picture.pk):
                    closedSet[tag.picture.pk] = imageMetadataAPI.getImageMetadata(tag.picture, False).getObject()
                if imageMetadata.has_key(tag.organism.pk):
                    imageMetadata[tag.organism.pk]['images'].append(closedSet[tag.picture.pk])
                else:
                    imageMetadata[tag.organism.pk] = {
                        'images' : [closedSet[tag.picture.pk]],
                        'organism' : {
                            'id' : tag.organism.pk,
                            'commonName' : tag.organism.common_name,
                            'abbreviation' : tag.organism.abbreviation,
                            'genus' : tag.organism.genus,
                            'species' : tag.organism.species      
                        }
                    }
                    
        if len(imageMetadata) != len(organismId):
            for orgId in organismId:
                if not imageMetadata.has_key(orgId):
                    imageMetadata[orgId] = []
        
        metadata.setObject(LimitDict(self.fields, imageMetadata))
        
        return metadata
Ejemplo n.º 4
0
    def doProcessRender(self, request):
        self.setLayout('admin/imageEditor.html')
        try:
            imageKey = request.GET.get('imageId', None)
            if (imageKey):
                image = Picture.objects.get(pk__exact=imageKey)

                # initialize tagging APIs
                tagGroupAPI = TagGroupAPI(unlimited=True)
                tagAPI = TagAPI(unlimited=True)
                geneLinkAPI = GeneLinkAPI(unlimited=True)

                tagGroups = tagGroupAPI.getTagGroupsByImage(image,
                                                            False).getObject()

                for group in tagGroups:
                    tags = tagAPI.getTagsByTagGroup(group['id']).getObject()
                    for tag in tags:
                        geneLinks = geneLinkAPI.getGeneLinksByTag(
                            tag['id']).getObject()
                        tag['geneLinks'] = geneLinks
                    group['tags'] = tags

                # initialize image metadata API
                imageMetadataAPI = ImageMetadataAPI(request.user)
                imageMetadata = imageMetadataAPI.getImageMetadata(
                    image, isKey=False).getObject()

                return {
                    'imageMetadata': json.dumps(imageMetadata),
                    'tagGroups': json.dumps(tagGroups),
                    'image': image
                }
            else:
                self.setLayout('public/404Media.html')
                return {}
        except ObjectDoesNotExist:
            self.setLayout('public/404Media.html')
            return {}
        except KeyError:
            self.setLayout('public/404Media.html')
            return {}
Ejemplo n.º 5
0
 def getImageMetadata(self):
     metadata = WebServiceArray()
     
     if self.user and self.user.is_authenticated():
         if self.unlimited:
             allowedImages = (Picture.objects.filter(isPrivate=False) | Picture.objects.filter(user__exact=self.user, isPrivate=True))[self.offset:]
         else:
             allowedImages = (Picture.objects.filter(isPrivate=False) | Picture.objects.filter(user__exact=self.user, isPrivate=True))[self.offset:self.offset+self.limit]
     else:
         if self.unlimited:
             allowedImages = Picture.objects.filter(isPrivate=False)[self.offset:]
         else:
             allowedImages = Picture.objects.filter(isPrivate=False)[self.offset:self.offset+self.limit]
     
     imageMetadataAPI = ImageMetadataAPI(self.user, self.fields)
     
     for image in allowedImages:
         metadata.put(imageMetadataAPI.getImageMetadata(image, False).getObject())
     
     return metadata
 def doProcessRender(self, request):
     self.setLayout('admin/imageEditor.html')
     try:
         imageKey = request.GET.get('imageId', None)
         if (imageKey):
             image = Picture.objects.get(pk__exact=imageKey)
             
             # initialize tagging APIs
             tagGroupAPI = TagGroupAPI(unlimited=True)
             tagAPI = TagAPI(unlimited=True)
             geneLinkAPI = GeneLinkAPI(unlimited=True)
             
             tagGroups = tagGroupAPI.getTagGroupsByImage(image, False).getObject()
             
             for group in tagGroups:
                 tags = tagAPI.getTagsByTagGroup(group['id']).getObject()
                 for tag in tags:
                     geneLinks = geneLinkAPI.getGeneLinksByTag(tag['id']).getObject()
                     tag['geneLinks'] = geneLinks
                 group['tags'] = tags
                 
             # initialize image metadata API
             imageMetadataAPI = ImageMetadataAPI(request.user)
             imageMetadata = imageMetadataAPI.getImageMetadata(image, isKey=False).getObject()
     
             return {
                 'imageMetadata' : json.dumps(imageMetadata),
                 'tagGroups' : json.dumps(tagGroups),
                 'image' : image
             }
         else:
             self.setLayout('public/404Media.html')
             return {}
     except ObjectDoesNotExist:
         self.setLayout('public/404Media.html')
         return {}
     except KeyError:
         self.setLayout('public/404Media.html')
         return {}
Ejemplo n.º 7
0
    def getImageMetadataByOrganism(self, organismId):
        metadata = WebServiceObject()

        if self.user and self.user.is_authenticated():
            allowedImages = Picture.objects.filter(
                isPrivate=False) | Picture.objects.filter(
                    user__exact=self.user, isPrivate=True)
        else:
            allowedImages = Picture.objects.filter(isPrivate=False)

        defTags = []

        if self.unlimited:
            for orgId in organismId:
                defTags.append(
                    PictureDefinitionTag.objects.filter(
                        organism__exact=orgId,
                        picture__in=allowedImages)[self.offset:])
        else:
            for orgId in organismId:
                defTags.append(
                    PictureDefinitionTag.objects.filter(
                        organism__exact=orgId,
                        picture__in=allowedImages)[self.offset:self.offset +
                                                   self.limit])

        closedSet = {}
        imageMetadata = {}
        imageFields = set(
            ['id', 'url', 'uploadDate', 'description', 'uploadedBy'])
        if self.fields:
            newImageFields = imageFields.intersection(set(self.fields))
            if newImageFields:
                imageFields = newImageFields
        imageMetadataAPI = ImageMetadataAPI(self.user, imageFields)

        for orgTags in defTags:
            for tag in orgTags:
                if not closedSet.has_key(tag.picture.pk):
                    closedSet[
                        tag.picture.pk] = imageMetadataAPI.getImageMetadata(
                            tag.picture, False).getObject()
                if imageMetadata.has_key(tag.organism.pk):
                    imageMetadata[tag.organism.pk]['images'].append(
                        closedSet[tag.picture.pk])
                else:
                    imageMetadata[tag.organism.pk] = {
                        'images': [closedSet[tag.picture.pk]],
                        'organism': {
                            'id': tag.organism.pk,
                            'commonName': tag.organism.common_name,
                            'abbreviation': tag.organism.abbreviation,
                            'genus': tag.organism.genus,
                            'species': tag.organism.species
                        }
                    }

        if len(imageMetadata) != len(organismId):
            for orgId in organismId:
                if not imageMetadata.has_key(orgId):
                    imageMetadata[orgId] = []

        metadata.setObject(LimitDict(self.fields, imageMetadata))

        return metadata
Ejemplo n.º 8
0
    def getImageMetadataForiSearch(self, query):
        metadata = WebServiceArray()
        imageMetadata = {}

        # Image description
        iDescImages = Picture.objects.filter(
            description__icontains=query[0])[self.offset:self.offset +
                                             self.limit]

        # Image notes
        iNoteImages = []
        picturesIN = []
        iNotes = PictureNotes.objects.filter(notes__icontains=query[0])
        for note in iNotes:
            pictureID = note.picture.pk
            if pictureID not in picturesIN:
                iNoteImages.extend(Picture.objects.filter(id__exact=pictureID))
                picturesIN.append(pictureID)
        iNoteImages = iNoteImages[self.offset:self.offset + self.limit]

        # Gene name
        gNameImages = []
        picturesGN = []
        pMgdbs = PictureMgdb.objects.filter(
            locus_full_name__icontains=query[0])
        for pMgdb in pMgdbs:
            pictureID = pMgdb.picture.pk
            if pictureID not in picturesGN:
                gNameImages.extend(Picture.objects.filter(id__exact=pictureID))
                picturesGN.append(pictureID)
        gNameImages = gNameImages[self.offset:self.offset + self.limit]

        # Gene Symbol
        gSymbolImages = []
        picturesGS = []
        pMgdbs = PictureMgdb.objects.filter(locus_name__icontains=query[0])
        for pMgdb in pMgdbs:
            pictureID = pMgdb.picture.pk
            if pictureID not in picturesGS:
                gSymbolImages.extend(
                    Picture.objects.filter(id__exact=pictureID))
                picturesGS.append(pictureID)
        gSymbolImages = gSymbolImages[self.offset:self.offset + self.limit]

        # Gene ID
        gIDImages = []
        pictureGIs = []
        pIDs = PictureGeneID.objects.filter(gene_id__icontains=query[0])
        for pID in pIDs:
            pictureID = pID.picture.pk
            if pictureID not in pictureGIs:
                gIDImages.extend(Picture.objects.filter(id__exact=pictureID))
                pictureGIs.append(pictureID)
        gIDImages = gIDImages[self.offset:self.offset + self.limit]

        imageMetadataAPI = ImageMetadataAPI(self.user, self.fields)

        for image in iDescImages:
            if imageMetadata.has_key(0):
                imageMetadata[0]['images'].append(
                    imageMetadataAPI.getImageMetadata(image,
                                                      False).getObject())
            else:
                imageMetadata[0] = {
                    'images': [
                        imageMetadataAPI.getImageMetadata(image,
                                                          False).getObject()
                    ]
                }
        for image in iNoteImages:
            if imageMetadata.has_key(1):
                imageMetadata[1]['images'].append(
                    imageMetadataAPI.getImageMetadata(image,
                                                      False).getObject())
            else:
                imageMetadata[1] = {
                    'images': [
                        imageMetadataAPI.getImageMetadata(image,
                                                          False).getObject()
                    ]
                }
        for image in gNameImages:
            if imageMetadata.has_key(2):
                imageMetadata[2]['images'].append(
                    imageMetadataAPI.getImageMetadata(image,
                                                      False).getObject())
            else:
                imageMetadata[2] = {
                    'images': [
                        imageMetadataAPI.getImageMetadata(image,
                                                          False).getObject()
                    ]
                }
        for image in gSymbolImages:
            if imageMetadata.has_key(3):
                imageMetadata[3]['images'].append(
                    imageMetadataAPI.getImageMetadata(image,
                                                      False).getObject())
            else:
                imageMetadata[3] = {
                    'images': [
                        imageMetadataAPI.getImageMetadata(image,
                                                          False).getObject()
                    ]
                }
        for image in gIDImages:
            if imageMetadata.has_key(4):
                imageMetadata[4]['images'].append(
                    imageMetadataAPI.getImageMetadata(image,
                                                      False).getObject())
            else:
                imageMetadata[4] = {
                    'images': [
                        imageMetadataAPI.getImageMetadata(image,
                                                          False).getObject()
                    ]
                }

        metadata.setObject(LimitDict(self.fields, imageMetadata))

        return metadata