def sendReferenceBasesList(self, id_=None): if id_ is None: id_ = self.referenceId path = "/references/{}/bases".format(id_) request = protocol.ListReferenceBasesRequest() response = self.sendListRequest(path, request) return response
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 post(self, url, params=None, data=None): self.checkSessionParameters() assert url.startswith(self._urlPrefix) suffix = url[len(self._urlPrefix):] searchSuffix = "/search" if suffix.endswith(searchSuffix): datatype = suffix[1:-len(searchSuffix)] assert datatype in self._searchMethodMap method = self._searchMethodMap[datatype] result = method(data) else: # ListReferenceBases is an oddball and needs to be treated # separately. data = json.loads(data) args = protocol.ListReferenceBasesRequest() args.reference_id = data.get('referenceId', "") args.start = int(data.get('start', 0)) args.end = int(data.get('end', 0)) args.page_token = data.get('pageToken', "") result = self._backend.runListReferenceBases(protocol.toJson(args)) return DummyResponse(result)
def list_reference_bases(self, id_, start=0, end=None): """ Returns an iterator over the bases from the server in the form of consecutive strings. This command does not conform to the patterns of the other search and get requests, and is implemented differently. """ request = protocol.ListReferenceBasesRequest() request.start = pb.int(start) request.end = pb.int(end) request.reference_id = id_ not_done = True # TODO We should probably use a StringIO here to make string buffering # a bit more efficient. bases_list = [] while not_done: response = self._run_list_reference_bases_page_request(request) bases_list.append(response.sequence) not_done = bool(response.next_page_token) request.page_token = response.next_page_token return "".join(bases_list)