Esempio n. 1
0
 def readsGenerator(self, request):
     """
     Returns a generator over the (read, nextPageToken) pairs defined
     by the specified request
     """
     if not request.reference_id:
         raise exceptions.UnmappedReadsNotSupported()
     if len(request.read_group_ids) < 1:
         raise exceptions.BadRequestException(
             "At least one readGroupId must be specified")
     elif len(request.read_group_ids) == 1:
         return self._readsGeneratorSingle(request)
     else:
         return self._readsGeneratorMultiple(request)
Esempio n. 2
0
 def _readsGeneratorMultiple(self, request):
     compoundId = datamodel.ReadGroupCompoundId.parse(
         request.read_group_ids[0])
     dataset = self.getDataRepository().getDataset(compoundId.dataset_id)
     readGroupSet = dataset.getReadGroupSet(compoundId.read_group_set_id)
     referenceSet = readGroupSet.getReferenceSet()
     if referenceSet is None:
         raise exceptions.ReadGroupSetNotMappedToReferenceSetException(
                 readGroupSet.getId())
     reference = referenceSet.getReference(request.reference_id)
     readGroupIds = readGroupSet.getReadGroupIds()
     if set(readGroupIds) != set(request.read_group_ids):
         raise exceptions.BadRequestException(
             "If multiple readGroupIds are specified, "
             "they must be all of the readGroupIds in a ReadGroupSet")
     intervalIterator = paging.ReadsIntervalIterator(
         request, readGroupSet, reference)
     return intervalIterator
Esempio n. 3
0
    def runAddAnnouncement(self, flaskrequest):
        """
        Takes a flask request from the frontend and attempts to parse
        into an AnnouncePeerRequest. If successful, it will log the
        announcement to the `announcement` table with some other metadata
        gathered from the request.
        """
        announcement = {}
        # We want to parse the request ourselves to collect a little more
        # data about it.
        try:
            requestData = protocol.fromJson(
                flaskrequest.get_data(), protocol.AnnouncePeerRequest)
            announcement['hostname'] = flaskrequest.host_url
            announcement['remote_addr'] = flaskrequest.remote_addr
            announcement['user_agent'] = flaskrequest.headers.get('User-Agent')
        except AttributeError:
            # Sometimes in testing we will send protocol requests instead
            # of flask requests and so the hostname and user agent won't
            # be present.
            try:
                requestData = protocol.fromJson(
                    flaskrequest, protocol.AnnouncePeerRequest)
            except Exception as e:
                raise exceptions.InvalidJsonException(e)
        except Exception as e:
            raise exceptions.InvalidJsonException(e)

        # Validate the url before accepting the announcement
        peer = datamodel.peers.Peer(requestData.peer.url)
        peer.setAttributesJson(protocol.toJson(
                requestData.peer.attributes))
        announcement['url'] = peer.getUrl()
        announcement['attributes'] = peer.getAttributes()
        try:
            self.getDataRepository().insertAnnouncement(announcement)
        except:
            raise exceptions.BadRequestException(announcement['url'])
        return protocol.toJson(
            protocol.AnnouncePeerResponse(success=True))
Esempio n. 4
0
 def rnaQuantificationsGenerator(self, request):
     """
     Returns a generator over the (rnaQuantification, nextPageToken) pairs
     defined by the specified request.
     """
     if len(request.rna_quantification_set_id) < 1:
         raise exceptions.BadRequestException(
             "Rna Quantification Set Id must be specified")
     else:
         compoundId = datamodel.RnaQuantificationSetCompoundId.parse(
             request.rna_quantification_set_id)
         dataset = self.getDataRepository().getDataset(
             compoundId.dataset_id)
         rnaQuantSet = dataset.getRnaQuantificationSet(
             compoundId.rna_quantification_set_id)
     results = []
     for obj in rnaQuantSet.getRnaQuantifications():
         include = True
         if request.biosample_id:
             if request.biosample_id != obj.getBiosampleId():
                 include = False
         if include:
             results.append(obj)
     return self._objectListGenerator(request, results)