def _readGroupSetsGenerator(self, request, numObjects, getByIndexMethod): """ Returns a generator over the results for the specified request, which is over a set of objects of the specified size. The objects are returned by call to the specified method, which must take a single integer as an argument. The returned generator yields a sequence of (object, nextPageToken) pairs, which allows this iteration to be picked up at any point. """ currentIndex = 0 if request.page_token: currentIndex, = paging._parsePageToken(request.page_token, 1) while currentIndex < numObjects: obj = getByIndexMethod(currentIndex) include = True rgsp = obj.toProtocolElement() if request.name and request.name != obj.getLocalId(): include = False if request.bio_sample_id and include: rgsp.ClearField("read_groups") for readGroup in obj.getReadGroups(): if request.bio_sample_id == readGroup.getBioSampleId(): rgsp.read_groups.extend( [readGroup.toProtocolElement()]) # If none of the biosamples match and the readgroupset # contains reagroups, don't include in the response if len(rgsp.read_groups) == 0 and \ len(obj.getReadGroups()) != 0: include = False currentIndex += 1 nextPageToken = None if currentIndex < numObjects: nextPageToken = str(currentIndex) if include: yield rgsp, nextPageToken
def _topLevelObjectGenerator(self, request, numObjects, getByIndexMethod): """ Returns a generator over the results for the specified request, which is over a set of objects of the specified size. The objects are returned by call to the specified method, which must take a single integer as an argument. The returned generator yields a sequence of (object, nextPageToken) pairs, which allows this iteration to be picked up at any point. """ currentIndex = 0 if request.page_token: currentIndex, = paging._parsePageToken(request.page_token, 1) while currentIndex < numObjects: object_ = getByIndexMethod(currentIndex) currentIndex += 1 nextPageToken = None if currentIndex < numObjects: nextPageToken = str(currentIndex) yield object_.toProtocolElement(), nextPageToken
def runListReferenceBases(self, requestJson): """ Runs a listReferenceBases request for the specified ID and request arguments. """ # In the case when an empty post request is made to the endpoint # we instantiate an empty ListReferenceBasesRequest. if not requestJson: request = protocol.ListReferenceBasesRequest() else: try: request = protocol.fromJson( requestJson, protocol.ListReferenceBasesRequest) except protocol.json_format.ParseError: raise exceptions.InvalidJsonException(requestJson) compoundId = datamodel.ReferenceCompoundId.parse(request.reference_id) referenceSet = self.getDataRepository().getReferenceSet( compoundId.reference_set_id) reference = referenceSet.getReference(request.reference_id) start = request.start end = request.end if end == 0: # assume meant "get all" end = reference.getLength() if request.page_token: pageTokenStr = request.page_token start = paging._parsePageToken(pageTokenStr, 1)[0] chunkSize = self._maxResponseLength nextPageToken = None if start + chunkSize < end: end = start + chunkSize nextPageToken = str(start + chunkSize) sequence = reference.getBases(start, end) # build response response = protocol.ListReferenceBasesResponse() response.offset = start response.sequence = sequence if nextPageToken: response.next_page_token = nextPageToken return protocol.toJson(response)
def _topLevelObjectGenerator(self, request, numObjects, getByIndexMethod): """ Returns a generator over the results for the specified request, which is over a set of objects of the specified size. The objects are returned by call to the specified method, which must take a single integer as an argument. The returned generator yields a sequence of (object, nextPageToken) pairs, which allows this iteration to be picked up at any point. """ currentIndex = 0 if request.page_token: currentIndex, = paging._parsePageToken( request.page_token, 1) while currentIndex < numObjects: object_ = getByIndexMethod(currentIndex) currentIndex += 1 nextPageToken = None if currentIndex < numObjects: nextPageToken = str(currentIndex) yield object_.toProtocolElement(), nextPageToken
def _readGroupSetsGenerator(self, request, numObjects, getByIndexMethod): """ Returns a generator over the results for the specified request, which is over a set of objects of the specified size. The objects are returned by call to the specified method, which must take a single integer as an argument. The returned generator yields a sequence of (object, nextPageToken) pairs, which allows this iteration to be picked up at any point. """ currentIndex = 0 if request.page_token: currentIndex, = paging._parsePageToken( request.page_token, 1) while currentIndex < numObjects: obj = getByIndexMethod(currentIndex) include = True rgsp = obj.toProtocolElement() if request.name and request.name != obj.getLocalId(): include = False if request.biosample_id and include: rgsp.ClearField("read_groups") for readGroup in obj.getReadGroups(): if request.biosample_id == readGroup.getBiosampleId(): rgsp.read_groups.extend( [readGroup.toProtocolElement()]) # If none of the biosamples match and the readgroupset # contains reagroups, don't include in the response if len(rgsp.read_groups) == 0 and \ len(obj.getReadGroups()) != 0: include = False currentIndex += 1 nextPageToken = None if currentIndex < numObjects: nextPageToken = str(currentIndex) if include: yield rgsp, nextPageToken
def testParsePageToken(self): goodPageToken = "12:34:567:8:9000" parsedToken = paging._parsePageToken(goodPageToken, 5) self.assertEqual(parsedToken[2], 567)