コード例 #1
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #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
コード例 #3
0
ファイル: delete.py プロジェクト: towardtruth/maizedig-1
    def deleteGeneLink(self, geneLinkKey, isKey=True):
        metadata = WebServiceObject()

        try:
            if (isKey):
                geneLink = GeneLink.objects.get(pk__exact=geneLinkKey)
            else:
                geneLink = geneLinkKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_GENE_LINK_KEY
        except Exception:
            raise Errors.INTERNAL_ERROR

        if not geneLink.writePermissions(self.user):
            raise Errors.AUTHENTICATION

        metadata.limitFields(self.fields)

        metadata.put('id', geneLink.pk)
        metadata.put('tagId', geneLink.tag.pk)
        metadata.put(
            'feature',
            LimitDict(
                self.fields, {
                    'uniqueName': geneLink.feature.uniquename,
                    'name': geneLink.feature.name,
                    'organismId': geneLink.feature.organism.organism_id
                }))

        try:
            geneLink.delete()
        except DatabaseError as e:
            transaction.rollback()
            raise Errors.INTEGRITY_ERROR.setCustom(str(e))
        return metadata
コード例 #4
0
ファイル: get.py プロジェクト: nguyennk/BioDIG
 def getGeneLink(self, geneLinkKey, isKey=True):
     metadata = WebServiceObject()
     
     try:            
         if isKey:
             geneLink = GeneLink.objects.get(pk__exact=geneLinkKey)
         else:
             geneLink = geneLinkKey
     except (ObjectDoesNotExist, ValueError):
         raise Errors.INVALID_GENE_LINK_KEY
     except Exception:
         raise Errors.INTERNAL_ERROR
     
     if not geneLink.readPermissions(self.user):
         raise Errors.AUTHENTICATION
     
     metadata.limitFields(self.fields)
         
     metadata.put('id', geneLink.pk)
     metadata.put('user', geneLink.user.username)
     metadata.put('tagId', geneLink.tag.pk)
     metadata.put('feature', 
         LimitDict(self.fields, {
             'uniqueName' : geneLink.feature.uniquename,
             'name': geneLink.feature.name,
             'organismId' : geneLink.feature.organism.organism_id
         })
     )
     return metadata
コード例 #5
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
コード例 #6
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #7
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #8
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #9
0
ファイル: get.py プロジェクト: nguyennk/BioDIG
    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
コード例 #10
0
ファイル: get.py プロジェクト: nguyennk/BioDIG
    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
コード例 #11
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #12
0
    def createGeneLink(self, tagKey, name=None,  allele=None, organismId=None, isKey=True):
        metadata = WebServiceObject()

        try:
            if isKey:
                tag = Tag.objects.get(pk__exact=tagKey)
            else:
                tag = tagKey
        except (ObjectDoesNotExist, ValueError):
            raise Errors.INVALID_TAG_GROUP_KEY
        
        if not tag.writePermissions(self.user):
            raise Errors.AUTHENTICATION

        try:
            feature = None
            if name and organismId:
                feature = Feature.objects.filter(name=name, organism=organismId)

            if not feature:
                error = "Could not find a feature with the parameters: "
                if name and organismId:
                    error += "name: " + name + ", organismId: " + organismId

                raise Errors.NO_MATCHING_FEATURE.setCustom(error)
            elif len(feature) > 1:
                error = "Multiple matches for parameters: "
                if name and organismId:
                    error += "name: " + name + ", organismId: " + organismId

                error += "\n\n Responses: \n\n"
                
                for f in feature:
                    error += "uniquename: " + f.uniquename + ", name: " + f.name + ", organism: " + f.organism.common_name + "\n\n"
                
                raise Errors.NO_MATCHING_FEATURE.setCustom(error)

            if allele:
                vID = None

                vID = Variation.objects.using('mgdb').filter(name__exact=allele)
                if not vID:
                    errorAllele = Errors.NO_MATCHING_ALLELE.setCustom(allele)
                    raise errorAllele

            geneLink = GeneLink(tag=tag, feature=feature[0], user=self.user, allele=allele)
            geneLink.save()
        except DatabaseError as e:
            transaction.rollback()
            raise Errors.INTEGRITY_ERROR.setCustom(str(e))
        
        # limit metadata return
        metadata.limitFields(self.fields)
            
        metadata.put('id', geneLink.pk)
        metadata.put('user', geneLink.user.username)
        metadata.put('tagId', geneLink.tag.pk)
        metadata.put('feature',
            LimitDict(self.fields, {
                'uniqueName' : geneLink.feature.uniquename,
                'name' : geneLink.feature.name,
                'allele': geneLink.allele,
                'organismId' : geneLink.feature.organism.organism_id
            })
        )
        
        return metadata
コード例 #13
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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
コード例 #14
0
ファイル: get.py プロジェクト: towardtruth/maizedig-1
    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