Ejemplo n.º 1
0
 def getAggregateTagGroupsByImage(self, imageKey, isKey=True):
     metadata = WebServiceArray()
     
     try:
         if (isKey):
             image = Picture.objects.get(pk__exact=imageKey)
         else:
             image = imageKey
     except (ObjectDoesNotExist, ValueError):
         raise Errors.INVALID_IMAGE_KEY
             
     if not image.readPermissions(self.user):
         raise Errors.AUTHENTICATION
             
     # initialize tagging APIs
     tagGroupAPI = TagGroupAPI(self.limit, self.offset, self.user, self.fields, self.unlimited)
     tagAPI = TagAPI(user=self.user, unlimited=True)
     geneLinkAPI = GeneLinkAPI(user=self.user, 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
         
     metadata.setObject(tagGroups)
 
     return metadata
Ejemplo n.º 2
0
 def getOrganisms(self, organisms):
     metadata = WebServiceArray()
     candidates = []
     
     # search for each organism
     for organism in organisms:
         orgCandidates = Organism.objects.filter(common_name=organism)
         species = organism.split(None, 1)
         if len(species) > 1:
             species = species[1]
         else:
             species = species[0]
         orgCandidates = orgCandidates | Organism.objects.filter(species=species)
         if orgCandidates:
             candidates.extend(orgCandidates)
     
     closedSet = set()
     
     for candidate in candidates:
         if not candidate.pk in closedSet:
             metadata.put(LimitDict(self.fields, {
                 'id' : candidate.pk,
                 'commonName' : candidate.common_name,
                 'abbreviation' : candidate.abbreviation,
                 'genus' : candidate.genus,
                 'species' : candidate.species
             }))
             closedSet.add(candidate.pk)
                 
     return metadata
Ejemplo n.º 3
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.º 4
0
    def getTagGroupsByImage(self, imageKey, isKey=True):
        metadata = WebServiceArray()

        try:
            if (isKey):
                image = Picture.objects.get(pk__exact=imageKey)
            else:
                image = imageKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_IMAGE_KEY

        if not image.readPermissions(self.user):
            raise Errors.AUTHENTICATION

        # get all duplicate image instances with ImageName
        images = Picture.objects.filter(imageName__exact=image.imageName)

        for imageID in images:
            if self.unlimited:
                groups = TagGroup.objects.filter(
                    picture__exact=imageID)[self.offset:]
            else:
                groups = TagGroup.objects.filter(
                    picture__exact=imageID)[self.offset:self.offset +
                                            self.limit]

            for group in groups:
                if group.readPermissions(self.user):
                    metadata.put(
                        LimitDict(
                            self.fields, {
                                'id':
                                group.pk,
                                'user':
                                group.user.username,
                                'name':
                                group.name,
                                'dateCreated':
                                group.dateCreated.strftime(
                                    "%Y-%m-%d %H:%M:%S"),
                                'lastModified':
                                group.lastModified.strftime(
                                    "%Y-%m-%d %H:%M:%S"),
                                'imageId':
                                group.picture.pk,
                                'isPrivate':
                                group.isPrivate
                            }))

        return metadata
Ejemplo n.º 5
0
    def getGeneLinksByTag(self, tagKey, isKey=True):
        metadata = WebServiceArray()

        try:
            if isKey:
                tag = Tag.objects.get(pk__exact=tagKey)
            else:
                tag = tagKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_TAG_KEY

        if not tag.readPermissions(self.user):
            raise Errors.AUTHENTICATION

        if (self.unlimited):
            geneLinks = GeneLink.objects.filter(
                tag__exact=tag).order_by('pk')[self.offset:]
        else:
            geneLinks = GeneLink.objects.filter(
                tag__exact=tag).order_by('pk')[self.offset:self.offset +
                                               self.limit]

        for geneLink in geneLinks:
            if geneLink.readPermissions(self.user):
                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id':
                            geneLink.pk,
                            'user':
                            geneLink.user.username,
                            'tagId':
                            tag.pk,
                            'feature':
                            LimitDict(
                                self.fields, {
                                    'uniqueName':
                                    geneLink.feature.uniquename,
                                    'name':
                                    geneLink.feature.name,
                                    'allele':
                                    geneLink.allele,
                                    'organismId':
                                    geneLink.feature.organism.organism_id
                                })
                        }))

        return metadata
Ejemplo n.º 6
0
    def getTagsByImage(self, imageKey, isKey=True):
        metadata = WebServiceArray()

        try:
            if isKey:
                image = Picture.objects.get(pk__exact=imageKey)
            else:
                image = imageKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_IMAGE_KEY

        if not image.readPermissions(self.user):
            raise Errors.AUTHENTICATION

        tagGroups = TagGroup.objects.filter(picture__exact=image)

        if self.unlimited:
            tags = Tag.objects.filter(
                group__in=tagGroups).order_by('pk')[self.offset:]
        else:
            tags = Tag.objects.filter(
                group__in=tagGroups).order_by('pk')[self.offset:self.offset +
                                                    self.limit]

        for tag in tags:
            if tag.readPermissions(self.user):
                tagPoints = TagPoint.objects.filter(
                    tag__exact=tag).order_by('rank')
                points = []

                for tagPoint in tagPoints:
                    points.append([tagPoint.pointX, tagPoint.pointY])

                color = [tag.color.red, tag.color.green, tag.color.blue]

                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id': tag.pk,
                            'user': tag.user.username,
                            'color': color,
                            'points': points,
                            'name': tag.name
                        }))

        return metadata
Ejemplo n.º 7
0
    def getTags(self):
        metadata = WebServiceArray()

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

        else:
            images = Picture.objects.filter(isPrivate=False)

        tagGroups = TagGroup.objects.filter(picture__in=images)

        if (self.unlimited):
            tags = Tag.objects.filter(
                group__in=tagGroups).order_by('pk')[self.offset:]
        else:
            tags = Tag.objects.filter(
                group__in=tagGroups).order_by('pk')[self.offset:self.offset +
                                                    self.limit]

        for tag in tags:
            if tag.readPermissions(self.user):
                tagPoints = TagPoint.objects.filter(
                    tag__exact=tag).order_by('rank')
                points = []

                for tagPoint in tagPoints:
                    points.append([tagPoint.pointX, tagPoint.pointY])

                color = [tag.color.red, tag.color.green, tag.color.blue]

                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id': tag.pk,
                            'user': tag.user.username,
                            'color': color,
                            'points': points,
                            'name': tag.name
                        }))

        return metadata
Ejemplo n.º 8
0
 def getAggregateTagGroups(self):
     metadata = WebServiceArray()
             
     # initialize tagging APIs
     tagGroupAPI = TagGroupAPI(self.limit, self.offset, self.user, self.fields, self.unlimited)
     tagAPI = TagAPI(user=self.user, unlimited=True)
     geneLinkAPI = GeneLinkAPI(user=self.user, unlimited=True)
     
     tagGroups = tagGroupAPI.getTagGroups().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
         
     metadata.setObject(tagGroups)
 
     return metadata
Ejemplo n.º 9
0
    def getGeneLinksByImage(self, imageKey, isKey=True):
        metadata = WebServiceArray()

        try:
            if isKey:
                image = TagGroup.objects.get(pk__exact=imageKey)
            else:
                image = imageKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_IMAGE_KEY

        if not image.readPermissions(self.user):
            raise Errors.AUTHENTICATION

        tagGroups = TagGroup.objects.filter(picture__exact=image)

        tags = Tag.objects.filter(group__in=tagGroups)

        if (self.unlimited):
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:]
        else:
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:self.offset +
                                             self.limit]

        for geneLink in geneLinks:
            if geneLink.readPermissions(self.user):
                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id': geneLink.pk,
                            'user': geneLink.user.username,
                            'tagId': geneLink.tag.pk,
                            'uniquename': geneLink.feature.uniquename,
                            'name': geneLink.feature.name,
                            'allele': geneLink.allele,
                            'organismId': geneLink.feature.organism.organism_id
                        }))

        return metadata
Ejemplo n.º 10
0
    def getGeneLinksByTagGroup(self, tagGroupKey, isKey=True):
        metadata = WebServiceArray()

        try:
            if isKey:
                tagGroup = TagGroup.objects.get(pk__exact=tagGroupKey)
            else:
                tagGroup = tagGroupKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.NO_TAG_GROUP_KEY

        if not tagGroup.readPermissions(self.user):
            raise Errors.AUTHENTICATION

        tags = Tag.objects.filter(group__exact=tagGroup)

        if (self.unlimited):
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:]
        else:
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:self.offset +
                                             self.limit]

        for geneLink in geneLinks:
            if geneLink.readPermissions(self.user):
                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id': geneLink.pk,
                            'user': geneLink.user.username,
                            'tagId': geneLink.tag.pk,
                            'uniquename': geneLink.feature.uniquename,
                            'name': geneLink.feature.name,
                            'organismId':
                            geneLink.feature.organism.organism_id,
                        }))

        return metadata
Ejemplo n.º 11
0
    def getTagGroups(self):
        metadata = WebServiceArray()

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

        if self.unlimited:
            groups = TagGroup.objects.filter(picture__in=images)[self.offset:]
        else:
            groups = TagGroup.objects.filter(
                picture__in=images)[self.offset:self.offset + self.limit]

        for group in groups:
            if group.readPermissions(self.user):
                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id':
                            group.pk,
                            'user':
                            group.user.username,
                            'name':
                            group.name,
                            'dateCreated':
                            group.dateCreated.strftime("%Y-%m-%d %H:%M:%S"),
                            'lastModified':
                            group.lastModified.strftime("%Y-%m-%d %H:%M:%S"),
                            'imageId':
                            group.picture.pk,
                            'isPrivate':
                            group.isPrivate
                        }))

        return metadata
Ejemplo n.º 12
0
    def getGeneLinks(self):
        metadata = WebServiceArray()

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

        tagGroups = TagGroup.objects.filter(picture__in=images)

        tags = Tag.objects.filter(group__in=tagGroups)

        if self.unlimited:
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:]
        else:
            geneLinks = GeneLink.objects.filter(
                tag__in=tags).order_by('pk')[self.offset:self.offset +
                                             self.limit]

        for geneLink in geneLinks:
            if geneLink.readPermissions(self.user):
                metadata.put(
                    LimitDict(
                        self.fields, {
                            'id': geneLink.pk,
                            'user': geneLink.user.username,
                            'tagId': geneLink.tag.pk,
                            'uniquename': geneLink.feature.uniquename,
                            'name': geneLink.feature.name,
                            'allele': geneLink.allele,
                            'organismId': geneLink.feature.organism.organism_id
                        }))

        return metadata
Ejemplo n.º 13
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