Пример #1
0
    def verifySearchRouting(self, path, getDefined=False):
        """
        Verifies that the specified path has the correct routing for a
        search command. If getDefined is False we check to see if it
        returns the correct status code.
        """
        response = self.app.post(path)
        protocol.fromJson(
            response.get_data(), protocol.GAException)
        self.assertEqual(415, response.status_code)
        if not getDefined:
            getResponse = self.app.get(path)
            protocol.fromJson(
                getResponse.get_data(), protocol.GAException)
            self.assertEqual(405, getResponse.status_code)

        # Malformed requests should return 400
        for badJson in ["", None, "JSON", "<xml/>", "{]"]:
            badResponse = self.app.post(
                path, data=badJson,
                headers={'Content-type': 'application/json'})
            self.assertEqual(400, badResponse.status_code)

        # OPTIONS should return success
        self.assertEqual(200, self.app.options(path).status_code)
Пример #2
0
 def test404sReturnJson(self):
     paths = [
         '/doesNotExist',
         '/reads/sea',
         '/variantsets/id/doesNotExist',
     ]
     for path in paths:
         response = self.app.get(path)
         protocol.fromJson(response.get_data(), protocol.GAException)
         self.assertEqual(404, response.status_code)
Пример #3
0
 def test404sReturnJson(self):
     paths = [
         '/doesNotExist',
         '/reads/sea',
         '/variantsets/id/doesNotExist',
     ]
     for path in paths:
         response = self.app.get(path)
         protocol.fromJson(
             response.get_data(), protocol.GAException)
         self.assertEqual(404, response.status_code)
Пример #4
0
 def testNextPageToken(self):
     responseClass = protocol.SearchVariantsResponse
     builder = protocol.SearchResponseBuilder(responseClass, 100, 2**32)
     # If not set, pageToken should be empty string
     self.assertIsNone(builder.getNextPageToken())
     instance = protocol.fromJson(builder.getSerializedResponse(),
                                  responseClass)
     self.assertEqual(instance.next_page_token, "")
     # page tokens can be any string.
     for nextPageToken in ["", "string"]:
         builder.setNextPageToken(nextPageToken)
         self.assertEqual(nextPageToken, builder.getNextPageToken())
         instance = protocol.fromJson(builder.getSerializedResponse(),
                                      responseClass)
         self.assertEqual(nextPageToken, instance.next_page_token)
Пример #5
0
 def populateFromRow(self, row):
     """
     Populates the instance variables of this ReadGroupSet from the
     specified database row.
     """
     self._dataUrl = row[b'dataUrl']
     self._indexFile = row[b'indexFile']
     self._programs = []
     for jsonDict in json.loads(row[b'programs']):
         program = protocol.fromJson(json.dumps(jsonDict),
                                     protocol.ReadGroup.Program)
         self._programs.append(program)
     stats = protocol.fromJson(row[b'stats'], protocol.ReadStats)
     self._numAlignedReads = stats.aligned_read_count
     self._numUnalignedReads = stats.unaligned_read_count
Пример #6
0
 def sendCallSetsSearch(self):
     response = self.sendVariantSetsSearch()
     variantSets = protocol.fromJson(
         response.data, protocol.SearchVariantSetsResponse).variant_sets
     request = protocol.SearchCallSetsRequest()
     request.variant_set_id = variantSets[0].id
     return self.sendPostRequest('/callsets/search', request)
Пример #7
0
 def runSearchRequest(self, requestStr, requestClass, responseClass,
                      objectGenerator):
     """
     Runs the specified request. The request is a string containing
     a JSON representation of an instance of the specified requestClass.
     We return a string representation of an instance of the specified
     responseClass in JSON format. Objects are filled into the page list
     using the specified object generator, which must return
     (object, nextPageToken) pairs, and be able to resume iteration from
     any point using the nextPageToken attribute of the request object.
     """
     self.startProfile()
     try:
         request = protocol.fromJson(requestStr, requestClass)
     except protocol.json_format.ParseError:
         raise exceptions.InvalidJsonException(requestStr)
     # TODO How do we detect when the page size is not set?
     if not request.page_size:
         request.page_size = self._defaultPageSize
     if request.page_size < 0:
         raise exceptions.BadPageSizeException(request.page_size)
     responseBuilder = protocol.SearchResponseBuilder(
         responseClass, request.page_size, self._maxResponseLength)
     nextPageToken = None
     for obj, nextPageToken in objectGenerator(request):
         responseBuilder.addValue(obj)
         if responseBuilder.isFull():
             break
     responseBuilder.setNextPageToken(nextPageToken)
     responseString = responseBuilder.getSerializedResponse()
     self.endProfile()
     return responseString
Пример #8
0
 def _deserialize_response(
         self, json_response_string, protocol_response_class):
     self._protocol_bytes_received += len(json_response_string)
     self._logger.debug("response:{}".format(json_response_string))
     if not json_response_string:
         raise exceptions.EmptyResponseException()
     return protocol.fromJson(json_response_string, protocol_response_class)
Пример #9
0
 def sendCallSetsSearch(self):
     response = self.sendVariantSetsSearch()
     variantSets = protocol.fromJson(
         response.data, protocol.SearchVariantSetsResponse).variant_sets
     request = protocol.SearchCallSetsRequest()
     request.variant_set_id = variantSets[0].id
     return self.sendPostRequest('/callsets/search', request)
Пример #10
0
 def testNextPageToken(self):
     responseClass = protocol.SearchVariantsResponse
     builder = protocol.SearchResponseBuilder(
         responseClass, 100, 2 ** 32)
     # If not set, pageToken should be empty string
     self.assertIsNone(builder.getNextPageToken())
     instance = protocol.fromJson(builder.getSerializedResponse(),
                                  responseClass)
     self.assertEqual(instance.next_page_token, "")
     # page tokens can be any string.
     for nextPageToken in ["", "string"]:
         builder.setNextPageToken(nextPageToken)
         self.assertEqual(nextPageToken, builder.getNextPageToken())
         instance = protocol.fromJson(builder.getSerializedResponse(),
                                      responseClass)
         self.assertEqual(nextPageToken, instance.next_page_token)
Пример #11
0
 def _deserialize_response(self, json_response_string,
                           protocol_response_class):
     self._protocol_bytes_received += len(json_response_string)
     self._logger.debug("response:{}".format(json_response_string))
     if not json_response_string:
         raise exceptions.EmptyResponseException()
     return protocol.fromJson(json_response_string, protocol_response_class)
Пример #12
0
    def testCompoundFeatureSearch(self):
        datasetName, featureSet = self.getCGDDataSetFeatureSet()
        featureId = \
            "http://cancer.sanger.ac.uk/cosmic/mutation/overview?id=736"
        obfuscated = self.getObfuscatedFeatureCompoundId(
            datasetName, featureSet.name, featureId)
        request = protocol.GetFeatureRequest
        request.feature_id = obfuscated
        response = self.sendGetRequest('/features/{}'.format(obfuscated))

        feature = protocol.fromJson(response.data, protocol.Feature)

        self.assertIsNotNone(feature)
        featureId = feature.id

        request = protocol.SearchGenotypePhenotypeRequest()
        request.phenotype_association_set_id = \
            self.getPhenotypeAssociationSetId()
        request.feature_ids.append(featureId)
        response = self.sendSearchRequest(
            '/featurephenotypeassociations/search',
            request,
            protocol.SearchGenotypePhenotypeResponse)
        self.assertEqual(1, len(response.associations))
        self.assertEqual(1, len(response.associations[0].feature_ids))
Пример #13
0
 def testRnaQuantificationSetsSearch(self):
     response = self.sendRnaQuantificationSetsSearch()
     responseData = protocol.fromJson(
         response.data, protocol.SearchRnaQuantificationSetsResponse)
     rnaQuantificationSets = list(responseData.rna_quantification_sets)
     self.assertEqual(self.rnaQuantificationSetId,
                      rnaQuantificationSets[0].id)
Пример #14
0
 def runSearchRequest(
         self, requestStr, requestClass, responseClass, objectGenerator):
     """
     Runs the specified request. The request is a string containing
     a JSON representation of an instance of the specified requestClass.
     We return a string representation of an instance of the specified
     responseClass in JSON format. Objects are filled into the page list
     using the specified object generator, which must return
     (object, nextPageToken) pairs, and be able to resume iteration from
     any point using the nextPageToken attribute of the request object.
     """
     self.startProfile()
     try:
         request = protocol.fromJson(requestStr, requestClass)
     except protocol.json_format.ParseError:
         raise exceptions.InvalidJsonException(requestStr)
     # TODO How do we detect when the page size is not set?
     if not request.page_size:
         request.page_size = self._defaultPageSize
     if request.page_size < 0:
         raise exceptions.BadPageSizeException(request.page_size)
     responseBuilder = protocol.SearchResponseBuilder(
         responseClass, request.page_size, self._maxResponseLength)
     nextPageToken = None
     for obj, nextPageToken in objectGenerator(request):
         responseBuilder.addValue(obj)
         if responseBuilder.isFull():
             break
     responseBuilder.setNextPageToken(nextPageToken)
     responseString = responseBuilder.getSerializedResponse()
     self.endProfile()
     return responseString
Пример #15
0
 def testRnaQuantificationSetsSearch(self):
     response = self.sendRnaQuantificationSetsSearch()
     responseData = protocol.fromJson(
         response.data, protocol.SearchRnaQuantificationSetsResponse)
     rnaQuantificationSets = list(responseData.rna_quantification_sets)
     self.assertEqual(
         self.rnaQuantificationSetId, rnaQuantificationSets[0].id)
Пример #16
0
 def testReadsSearch(self):
     response = self.sendReadsSearch(readGroupIds=[self.readGroupId],
                                     referenceId=self.referenceId)
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data,
                                      protocol.SearchReadsResponse)
     self.assertEqual(len(responseData.alignments), 2)
     self.assertEqual(responseData.alignments[0].id, self.readAlignmentId)
Пример #17
0
 def searchObjectTest(self, responseMethod, responseClass, attributeName,
                      objectId):
     response = responseMethod()
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data, responseClass)
     responseList = getattr(responseData, attributeName)
     objectList = list(responseList)
     self.assertEqual(objectId, objectList[0].id)
Пример #18
0
 def populateFromRow(self, row):
     """
     Populate the instance variables using the specified DB row.
     """
     self._sampleId = row[b'sampleId']
     self._description = row[b'description']
     self._predictedInsertSize = row[b'predictedInsertSize']
     stats = protocol.fromJson(row[b'stats'], protocol.ReadStats)
     self._numAlignedReads = stats.aligned_read_count
     self._numUnalignedReads = stats.unaligned_read_count
     experiment = protocol.fromJson(row[b'experiment'], protocol.Experiment)
     self._instrumentModel = experiment.instrument_model
     self._sequencingCenter = experiment.sequencing_center
     self._experimentDescription = experiment.description
     self._library = experiment.library
     self._platformUnit = experiment.platform_unit
     self._runTime = experiment.run_time
Пример #19
0
 def searchObjectTest(
         self, responseMethod, responseClass, attributeName, objectId):
     response = responseMethod()
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data, responseClass)
     responseList = getattr(responseData, attributeName)
     objectList = list(responseList)
     self.assertEqual(objectId, objectList[0].id)
Пример #20
0
 def assertObjectNotFound(self, response):
     """
     Checks that the specified response contains a search failure.
     """
     self.assertEqual(404, response.status_code)
     error = protocol.fromJson(response.data, protocol.GAException)
     self.assertTrue(protocol.validate(protocol.toJson(error), type(error)))
     self.assertGreater(error.error_code, 0)
     self.assertGreater(len(error.message), 0)
Пример #21
0
 def assertObjectNotSupported(self, response):
     """
     Checks that the specified response returns a not supported 501 status
     """
     self.assertEqual(501, response.status_code)
     error = protocol.fromJson(response.data, protocol.GAException)
     self.assertTrue(protocol.validate(protocol.toJson(error), type(error)))
     self.assertGreater(error.error_code, 0)
     self.assertGreater(len(error.message), 0)
Пример #22
0
 def populateFromRow(self, row):
     """
     Populate the instance variables using the specified DB row.
     """
     self._sampleName = row[b'sampleName']
     self._bioSampleId = row[b'bioSampleId']
     self._description = row[b'description']
     self._predictedInsertSize = row[b'predictedInsertSize']
     stats = protocol.fromJson(row[b'stats'], protocol.ReadStats)
     self._numAlignedReads = stats.aligned_read_count
     self._numUnalignedReads = stats.unaligned_read_count
     experiment = protocol.fromJson(row[b'experiment'], protocol.Experiment)
     self._instrumentModel = experiment.instrument_model
     self._sequencingCenter = experiment.sequencing_center
     self._experimentDescription = experiment.description
     self._library = experiment.library
     self._platformUnit = experiment.platform_unit
     self._runTime = experiment.run_time
Пример #23
0
 def sendGetObject(self, path, id_, responseClass):
     """
     Sends a get request and parses the value into an instance of the
     specified class.
     """
     response = self.sendObjectGetRequest(path, id_)
     self.assertEqual(200, response.status_code)
     obj = protocol.fromJson(response.data, responseClass)
     self.assertIsInstance(obj, responseClass)
     return obj
Пример #24
0
 def testPhenotypeAssociationSetsSearch(self):
     response = self.sendPhenotypeAssociationSetsSearch()
     responseData = protocol.fromJson(
         response.data, protocol.SearchPhenotypeAssociationSetsResponse)
     pasets = list(responseData.phenotype_association_sets)
     foundPASet = False
     for paset in pasets:
         if self.phenotypeAssociationSetId == paset.id:
             foundPASet = True
     self.assertTrue(foundPASet)
Пример #25
0
 def sendVariantsSearch(self):
     response = self.sendVariantSetsSearch()
     variantSets = protocol.fromJson(
         response.data, protocol.SearchVariantSetsResponse).variant_sets
     request = protocol.SearchVariantsRequest()
     request.variant_set_id = variantSets[0].id
     request.reference_name = "1"
     request.start = 0
     request.end = 1
     return self.sendPostRequest('/variants/search', request)
Пример #26
0
 def sendVariantsSearch(self):
     response = self.sendVariantSetsSearch()
     variantSets = protocol.fromJson(
         response.data, protocol.SearchVariantSetsResponse).variant_sets
     request = protocol.SearchVariantsRequest()
     request.variant_set_id = variantSets[0].id
     request.reference_name = "1"
     request.start = 0
     request.end = 1
     return self.sendPostRequest('/variants/search', request)
Пример #27
0
 def testPhenotypeAssociationSetsSearch(self):
     response = self.sendPhenotypeAssociationSetsSearch()
     responseData = protocol.fromJson(
         response.data, protocol.SearchPhenotypeAssociationSetsResponse)
     pasets = list(responseData.phenotype_association_sets)
     foundPASet = False
     for paset in pasets:
         if self.phenotypeAssociationSetId == paset.id:
             foundPASet = True
     self.assertTrue(foundPASet)
Пример #28
0
 def testReadsSearch(self):
     response = self.sendReadsSearch(readGroupIds=[self.readGroupId],
                                     referenceId=self.referenceId)
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(
         response.data, protocol.SearchReadsResponse)
     self.assertEqual(len(responseData.alignments), 2)
     self.assertEqual(
         responseData.alignments[0].id,
         self.readAlignmentId)
Пример #29
0
 def sendSearchRequest(self, path, request, responseClass):
     """
     Sends the specified protocol request instance as JSON, and
     parses the result into an instance of the specified response.
     """
     response = self.sendJsonPostRequest(path, protocol.toJson(request))
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data, responseClass)
     self.assertTrue(
         protocol.validate(protocol.toJson(responseData), responseClass))
     return responseData
Пример #30
0
 def sendSearchRequest(self, path, request, responseClass):
     """
     Sends the specified protocol request instance as JSON, and
     parses the result into an instance of the specified response.
     """
     response = self.sendJsonPostRequest(path, protocol.toJson(request))
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data, responseClass)
     self.assertTrue(
         protocol.validate(protocol.toJson(responseData), responseClass))
     return responseData
Пример #31
0
 def testGetVariantSet(self):
     response = self.sendVariantSetsSearch()
     responseData = protocol.fromJson(
         response.data, protocol.SearchVariantSetsResponse)
     variantSetId = responseData.variant_sets[0].id
     response = self.sendGetVariantSet(variantSetId)
     self.assertEqual(200, response.status_code)
     invalidId = datamodel.VariantSetCompoundId.getInvalidIdString()
     obfuscated = datamodel.CompoundId.obfuscate(invalidId)
     compoundId = datamodel.VariantSetCompoundId.parse(obfuscated)
     response = self.sendGetVariantSet(str(compoundId))
     self.assertEqual(404, response.status_code)
Пример #32
0
 def testGetVariantSet(self):
     response = self.sendVariantSetsSearch()
     responseData = protocol.fromJson(response.data,
                                      protocol.SearchVariantSetsResponse)
     variantSetId = responseData.variant_sets[0].id
     response = self.sendGetVariantSet(variantSetId)
     self.assertEqual(200, response.status_code)
     invalidId = datamodel.VariantSetCompoundId.getInvalidIdString()
     obfuscated = datamodel.CompoundId.obfuscate(invalidId)
     compoundId = datamodel.VariantSetCompoundId.parse(obfuscated)
     response = self.sendGetVariantSet(str(compoundId))
     self.assertEqual(404, response.status_code)
Пример #33
0
 def toProtocolElement(self):
     species = None
     sex = None
     if self.getSpecies():
         species = protocol.fromJson(json.dumps(self.getSpecies()),
                                     protocol.OntologyTerm)
     if self.getSex():
         sex = protocol.fromJson(json.dumps(self.getSex()),
                                 protocol.OntologyTerm)
     gaIndividual = protocol.Individual(dataset_id=self._datasetId,
                                        created=self.getCreated(),
                                        updated=self.getUpdated(),
                                        description=self.getDescription(),
                                        id=self.getId(),
                                        name=self.getName(),
                                        species=species,
                                        sex=sex)
     for key in self.getInfo():
         for value in self.getInfo()[key]['values']:
             gaIndividual.info[key].values.add().string_value = value
     return gaIndividual
Пример #34
0
 def sendListReferenceBasesRequest(self, id_, request):
     """
     Sends a ListReferenceBasesRequest and parses the result into a
     ListReferenceBasesResponse.
     """
     path = '/references/{}/bases'.format(id_)
     response = self.app.get(
         path, query_string=protocol.toJsonDict(request))
     self.assertEqual(response.status_code, 200)
     obj = protocol.fromJson(
         response.data, protocol.ListReferenceBasesResponse)
     self.assertIsInstance(obj, protocol.ListReferenceBasesResponse)
     return obj
Пример #35
0
 def toProtocolElement(self):
     species = None
     sex = None
     if self.getSpecies():
         species = protocol.fromJson(
             json.dumps(self.getSpecies()), protocol.OntologyTerm)
     if self.getSex():
         sex = protocol.fromJson(
             json.dumps(self.getSex()), protocol.OntologyTerm)
     gaIndividual = protocol.Individual(
         dataset_id=self._datasetId,
         created=self.getCreated(),
         updated=self.getUpdated(),
         description=self.getDescription(),
         id=self.getId(),
         name=self.getName(),
         species=species,
         sex=sex)
     for key in self.getInfo():
         for value in self.getInfo()[key]['values']:
             gaIndividual.info[key].values.add().string_value = value
     return gaIndividual
Пример #36
0
 def testPageSizeExactFill(self):
     responseClass = protocol.SearchVariantsResponse
     valueClass = protocol.Variant
     for pageSize in range(1, 10):
         builder = protocol.SearchResponseBuilder(responseClass, pageSize,
                                                  2**32)
         self.assertEqual(builder.getPageSize(), pageSize)
         while not builder.isFull():
             builder.addValue(valueClass())
         instance = protocol.fromJson(builder.getSerializedResponse(),
                                      responseClass)
         valueList = getattr(instance, getValueListName(responseClass))
         self.assertEqual(len(valueList), pageSize)
Пример #37
0
 def assertRawRequestRaises(self, exceptionClass, url, requestString):
     """
     Verifies that the specified request string returns a protocol
     exception corresponding to the specified class when applied to
     all POST endpoints.
     """
     response = self.app.post(url,
                              headers={'Content-type': 'application/json'},
                              data=requestString)
     self.assertEqual(response.status_code, exceptionClass.httpStatus)
     error = protocol.fromJson(response.data, protocol.GAException)
     self.assertEqual(error.error_code, exceptionClass.getErrorCode())
     self.assertGreater(len(error.message), 0)
Пример #38
0
 def testPageSizeExactFill(self):
     responseClass = protocol.SearchVariantsResponse
     valueClass = protocol.Variant
     for pageSize in range(1, 10):
         builder = protocol.SearchResponseBuilder(
             responseClass, pageSize, 2 ** 32)
         self.assertEqual(builder.getPageSize(), pageSize)
         while not builder.isFull():
             builder.addValue(valueClass())
         instance = protocol.fromJson(builder.getSerializedResponse(),
                                      responseClass)
         valueList = getattr(instance, getValueListName(responseClass))
         self.assertEqual(len(valueList), pageSize)
Пример #39
0
 def assertRawRequestRaises(self, exceptionClass, url, requestString):
     """
     Verifies that the specified request string returns a protocol
     exception corresponding to the specified class when applied to
     all POST endpoints.
     """
     response = self.app.post(
         url, headers={'Content-type': 'application/json'},
         data=requestString)
     self.assertEqual(response.status_code, exceptionClass.httpStatus)
     error = protocol.fromJson(response.data, protocol.GAException)
     self.assertEqual(
         error.error_code, exceptionClass.getErrorCode())
     self.assertGreater(len(error.message), 0)
Пример #40
0
 def populateFromJson(self, jsonString):
     try:
         parsed = protocol.fromJson(jsonString, protocol.BioSample)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._disease = protocol.toJsonDict(parsed.disease)
     self._individualId = parsed.individual_id
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Пример #41
0
 def populateFromJson(self, jsonString):
     try:
         parsed = protocol.fromJson(jsonString, protocol.BioSample)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._disease = protocol.toJsonDict(parsed.disease)
     self._individualId = parsed.individual_id
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Пример #42
0
 def getPhenotypeAssociationSetId(self):
     """
     Gets the dataset phenotype association set ID
     """
     request = protocol.SearchDatasetsRequest()
     response = self.sendSearchRequest("datasets/search", request,
                                       protocol.SearchDatasetsResponse)
     datasetId = response.datasets[0].id
     request = protocol.SearchPhenotypeAssociationSetsRequest()
     request.dataset_id = datasetId
     response = self.sendPostRequest("phenotypeassociationsets/search",
                                     request)
     response = protocol.fromJson(
         response.data, protocol.SearchPhenotypeAssociationSetsResponse)
     return response.phenotype_association_sets[0].id
Пример #43
0
    def verifySearchRouting(self, path, getDefined=False):
        """
        Verifies that the specified path has the correct routing for a
        search command. If getDefined is False we check to see if it
        returns the correct status code.
        """
        response = self.app.post(path)
        protocol.fromJson(response.get_data(), protocol.GAException)
        self.assertEqual(415, response.status_code)
        if not getDefined:
            getResponse = self.app.get(path)
            protocol.fromJson(getResponse.get_data(), protocol.GAException)
            self.assertEqual(405, getResponse.status_code)

        # Malformed requests should return 400
        for badJson in ["", None, "JSON", "<xml/>", "{]"]:
            badResponse = self.app.post(
                path,
                data=badJson,
                headers={'Content-type': 'application/json'})
            self.assertEqual(400, badResponse.status_code)

        # OPTIONS should return success
        self.assertEqual(200, self.app.options(path).status_code)
Пример #44
0
    def testGetDataset(self):
        # Test OK: ID found
        response = self.sendDatasetsSearch()
        responseData = protocol.fromJson(
            response.data, protocol.SearchDatasetsResponse)
        datasetId = responseData.datasets[0].id
        response = self.sendGetDataset(datasetId)
        self.assertEqual(200, response.status_code)

        # Test Error: 404, ID not found
        invalidId = datamodel.DatasetCompoundId.getInvalidIdString()
        obfuscated = datamodel.CompoundId.obfuscate(invalidId)
        compoundId = datamodel.DatasetCompoundId.parse(obfuscated)
        response = self.sendGetDataset(str(compoundId))
        self.assertEqual(404, response.status_code)
Пример #45
0
 def populateFromJson(self, jsonString):
     # TODO validate
     try:
         parsed = protocol.fromJson(jsonString, protocol.Individual)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._species = protocol.toJsonDict(parsed.species)
     self._sex = protocol.toJsonDict(parsed.sex)
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Пример #46
0
    def testVariantAnnotationSetsSearch(self):
        self.assertIsNotNone(self.variantAnnotationSet)

        request = protocol.SearchVariantAnnotationSetsRequest()

        request.variant_set_id = "b4d=="
        path = '/variantannotationsets/search'
        response = self.sendJsonPostRequest(path, protocol.toJson(request))
        responseData = protocol.fromJson(response.data, protocol.GAException)
        self.assertTrue(protocol.validate(protocol.toJson(responseData),
                                          protocol.GAException))
        self.assertEqual(responseData.error_code, 758389611)
        self.assertEqual(responseData.message,
                         'No object of this type exists with id \'b4d==\'')

        request.variant_set_id = self.variantSet.getId()
        response = self.sendJsonPostRequest(path, protocol.toJson(request))
        responseData = protocol.fromJson(response.data, protocol.
                                         SearchVariantAnnotationSetsResponse)
        self.assertTrue(protocol.validate(
            protocol.toJson(responseData),
            protocol.SearchVariantAnnotationSetsResponse))
        self.assertGreater(len(responseData.variant_annotation_sets), 0,
                           "Expect some results for a known good ID")
Пример #47
0
    def testGetDataset(self):
        # Test OK: ID found
        response = self.sendDatasetsSearch()
        responseData = protocol.fromJson(response.data,
                                         protocol.SearchDatasetsResponse)
        datasetId = responseData.datasets[0].id
        response = self.sendGetDataset(datasetId)
        self.assertEqual(200, response.status_code)

        # Test Error: 404, ID not found
        invalidId = datamodel.DatasetCompoundId.getInvalidIdString()
        obfuscated = datamodel.CompoundId.obfuscate(invalidId)
        compoundId = datamodel.DatasetCompoundId.parse(obfuscated)
        response = self.sendGetDataset(str(compoundId))
        self.assertEqual(404, response.status_code)
Пример #48
0
 def populateFromJson(self, jsonString):
     # TODO validate
     try:
         parsed = protocol.fromJson(jsonString, protocol.Individual)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._species = protocol.toJsonDict(parsed.species)
     self._sex = protocol.toJsonDict(parsed.sex)
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Пример #49
0
 def testIntegrity(self):
     # Verifies that the values we put in are exactly what we get
     # back across all subclasses of SearchResponse
     for class_ in [responseClass for _, _, responseClass in
                    protocol.postMethods]:
         instance = class_()
         valueList = getattr(instance, getValueListName(class_))
         valueList.add()
         builder = protocol.SearchResponseBuilder(
             class_, len(valueList), 2 ** 32)
         for value in valueList:
             builder.addValue(value)
         builder.setNextPageToken(instance.next_page_token)
         otherInstance = protocol.fromJson(
             builder.getSerializedResponse(), class_)
         self.assertEqual(instance, otherInstance)
Пример #50
0
 def testIntegrity(self):
     # Verifies that the values we put in are exactly what we get
     # back across all subclasses of SearchResponse
     for class_ in [
             responseClass for _, _, responseClass in protocol.postMethods
     ]:
         instance = class_()
         valueList = getattr(instance, getValueListName(class_))
         valueList.add()
         builder = protocol.SearchResponseBuilder(class_, len(valueList),
                                                  2**32)
         for value in valueList:
             builder.addValue(value)
         builder.setNextPageToken(instance.next_page_token)
         otherInstance = protocol.fromJson(builder.getSerializedResponse(),
                                           class_)
         self.assertEqual(instance, otherInstance)
Пример #51
0
 def toProtocolElement(self):
     disease = None
     if self.getDisease():
         disease = protocol.fromJson(json.dumps(self.getDisease()),
                                     protocol.OntologyTerm)
     bioSample = protocol.BioSample(dataset_id=self._datasetId,
                                    created=self.getCreated(),
                                    updated=self.getUpdated(),
                                    description=self.getDescription(),
                                    id=self.getId(),
                                    individual_id=self.getIndividualId(),
                                    name=self.getName(),
                                    disease=disease)
     for key in self.getInfo():
         for value in self.getInfo()[key]['values']:
             bioSample.info[key].values.add().string_value = value
     return bioSample
Пример #52
0
 def getPhenotypeAssociationSetId(self):
     """
     Gets the dataset phenotype association set ID
     """
     request = protocol.SearchDatasetsRequest()
     response = self.sendSearchRequest(
         "datasets/search",
         request,
         protocol.SearchDatasetsResponse)
     datasetId = response.datasets[0].id
     request = protocol.SearchPhenotypeAssociationSetsRequest()
     request.dataset_id = datasetId
     response = self.sendPostRequest(
         "phenotypeassociationsets/search", request)
     response = protocol.fromJson(
         response.data, protocol.SearchPhenotypeAssociationSetsResponse)
     return response.phenotype_association_sets[0].id
Пример #53
0
 def toProtocolElement(self):
     disease = None
     if self.getDisease():
         disease = protocol.fromJson(
             json.dumps(self.getDisease()), protocol.OntologyTerm)
     bioSample = protocol.BioSample(
         dataset_id=self._datasetId,
         created=self.getCreated(),
         updated=self.getUpdated(),
         description=self.getDescription(),
         id=self.getId(),
         individual_id=self.getIndividualId(),
         name=self.getName(),
         disease=disease)
     for key in self.getInfo():
         for value in self.getInfo()[key]['values']:
             bioSample.info[key].values.add().string_value = value
     return bioSample
Пример #54
0
    def testFeaturesSearchById(self):
        datasetName, featureSet = self.getCGDDataSetFeatureSet()
        featureId = \
            "http://cancer.sanger.ac.uk/cosmic/mutation/overview?id=965"
        obfuscated = self.getObfuscatedFeatureCompoundId(
            datasetName, featureSet.name, featureId)
        request = protocol.GetFeatureRequest
        request.feature_id = obfuscated
        response = self.sendGetRequest('/features/{}'.format(obfuscated))

        feature = protocol.fromJson(response.data, protocol.Feature)
        self.assertIsNotNone(feature)
        self.assertEqual(request.feature_id, feature.id)
        self.assertIsNotNone(feature.feature_type)
        self.assertIsNotNone(feature.feature_type.id)
        self.assertEqual(feature.reference_name, "chr10")
        self.assertEqual(feature.start, 43617416)
        self.assertEqual(feature.end, 43617416)
Пример #55
0
 def testMaxBufferSizeOverridesPageSize(self):
     responseClass = protocol.SearchVariantsResponse
     typicalValue = protocol.Variant()
     # We have to put some values in here or it will have zero length.
     typicalValue.start = 1
     typicalValue.end = 2
     typicalValue.reference_bases = "AAAAAAAA"
     typicalValueLength = typicalValue.ByteSize()
     for numValues in range(1, 10):
         maxBufferSize = numValues * typicalValueLength
         builder = protocol.SearchResponseBuilder(responseClass, 1000,
                                                  maxBufferSize)
         self.assertEqual(maxBufferSize, builder.getMaxBufferSize())
         while not builder.isFull():
             builder.addValue(typicalValue)
         instance = protocol.fromJson(builder.getSerializedResponse(),
                                      responseClass)
         valueList = getattr(instance, getValueListName(responseClass))
         self.assertEqual(len(valueList), numValues)
Пример #56
0
    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)
Пример #57
0
    def testPageSizeOverflow(self):
        # Verifies that the page size behaviour is correct when we keep
        # filling after full is True.
        responseClass = protocol.SearchVariantsResponse
        valueClass = protocol.Variant
        for pageSize in range(1, 10):
            builder = protocol.SearchResponseBuilder(responseClass, pageSize,
                                                     2**32)
            self.assertEqual(builder.getPageSize(), pageSize)
            self.assertFalse(builder.isFull())
            for listLength in range(1, 2 * pageSize):
                builder.addValue(valueClass())
                instance = protocol.fromJson(builder.getSerializedResponse(),
                                             responseClass)

                valueList = getattr(instance, getValueListName(responseClass))
                self.assertEqual(len(valueList), listLength)
                if listLength < pageSize:
                    self.assertFalse(builder.isFull())
                else:
                    self.assertTrue(builder.isFull())
Пример #58
0
    def testCompoundFeatureSearch(self):
        datasetName, featureSet = self.getCGDDataSetFeatureSet()
        featureId = \
            "http://cancer.sanger.ac.uk/cosmic/mutation/overview?id=736"
        obfuscated = self.getObfuscatedFeatureCompoundId(
            datasetName, featureSet.name, featureId)
        request = protocol.GetFeatureRequest
        request.feature_id = obfuscated
        response = self.sendGetRequest('/features/{}'.format(obfuscated))

        feature = protocol.fromJson(response.data, protocol.Feature)

        self.assertIsNotNone(feature)
        featureId = feature.id

        request = protocol.SearchGenotypePhenotypeRequest()
        request.phenotype_association_set_id = \
            self.getPhenotypeAssociationSetId()
        request.feature_ids.append(featureId)
        response = self.sendSearchRequest(
            '/featurephenotypeassociations/search', request,
            protocol.SearchGenotypePhenotypeResponse)
        self.assertEqual(1, len(response.associations))
        self.assertEqual(1, len(response.associations[0].feature_ids))
Пример #59
0
 def getObjectTest(self, getMethod, protocolClass, objectId):
     response = getMethod()
     self.assertEqual(200, response.status_code)
     responseData = protocol.fromJson(response.data, protocolClass)
     self.assertEqual(responseData.id, objectId)