Exemplo n.º 1
0
    def testReads(self):
        # search read group sets
        path = utils.applyVersion('/readgroupsets/search')
        request = protocol.SearchReadGroupSetsRequest()
        request.datasetId = 'simulatedDataset1'
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(response.status_code, 200)
        responseData = protocol.SearchReadGroupSetsResponse.fromJsonString(
            response.data)
        readGroupSets = responseData.readGroupSets
        self.assertEqual(len(readGroupSets), 1)

        # search reads
        path = utils.applyVersion('/reads/search')
        request = protocol.SearchReadsRequest()
        readGroupId = readGroupSets[0].readGroups[0].id
        request.readGroupIds = [readGroupId]
        request.referenceId = "chr1"
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(response.status_code, 200)
        responseData = protocol.SearchReadsResponse.fromJsonString(
            response.data)
        alignments = responseData.alignments
        self.assertEqual(len(alignments), self.numAlignmentsPerReadGroup)
        for alignment in alignments:
            self.assertEqual(alignment.readGroupId, readGroupId)
Exemplo n.º 2
0
    def testReferences(self):
        # search for reference sets
        path = utils.applyVersion('/referencesets/search')
        request = protocol.SearchReferenceSetsRequest()
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(response.status_code, 200)
        responseData = protocol.SearchReferenceSetsResponse.fromJsonString(
            response.data)
        referenceSets = responseData.referenceSets
        self.assertEqual(self.numReferenceSets, len(referenceSets))

        # search for references
        path = utils.applyVersion('/references/search')
        request = protocol.SearchReferencesRequest()
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(response.status_code, 200)
        responseData = protocol.SearchReferencesResponse.fromJsonString(
            response.data)
        references = responseData.references
        self.assertEqual(
            self.numReferenceSets * self.numReferencesPerReferenceSet,
            len(references))

        for referenceSet in referenceSets:
            # fetch the reference set
            path = utils.applyVersion('/referencesets/{}'.format(
                referenceSet.id))
            response = self.app.get(path)
            self.assertEqual(response.status_code, 200)
            fetchedReferenceSet = protocol.ReferenceSet.fromJsonString(
                response.data)
            self.assertEqual(fetchedReferenceSet, referenceSet)
            self.assertEqual(len(fetchedReferenceSet.referenceIds),
                             self.numReferencesPerReferenceSet)

            for referenceId in referenceSet.referenceIds:
                # fetch the reference
                path = utils.applyVersion('/references/{}'.format(referenceId))
                response = self.app.get(path)
                self.assertEqual(response.status_code, 200)
                fetchedReference = protocol.Reference.fromJsonString(
                    response.data)
                self.assertEqual(fetchedReference.id, referenceId)

                # fetch the bases
                path = utils.applyVersion(
                    '/references/{}/bases'.format(referenceId))
                args = protocol.ListReferenceBasesRequest().toJsonDict()
                response = self.app.get(path, data=args)
                self.assertEqual(response.status_code, 200)
                bases = protocol.ListReferenceBasesResponse.fromJsonString(
                    response.data)
                self.assertEqual(len(bases.sequence), 200)
                self.assertEqual(set(bases.sequence), set(['A', 'C', 'T',
                                                           'G']))
                calculatedDigest = hashlib.md5(bases.sequence).hexdigest()
                self.assertEqual(calculatedDigest,
                                 fetchedReference.md5checksum)
Exemplo n.º 3
0
 def testRouteReferences(self):
     paths = ['/references/1', 'references/1/bases', 'referencesets/1']
     for path in paths:
         versionedPath = utils.applyVersion(path)
         self.assertEqual(404, self.app.get(versionedPath).status_code)
     paths = ['/references/search']
     for path in paths:
         versionedPath = utils.applyVersion(path)
         self.assertEqual(404, self.app.get(versionedPath).status_code)
     self.verifySearchRouting('/referencesets/search', True)
Exemplo n.º 4
0
 def testRouteReferences(self):
     paths = ['/references/1', 'references/1/bases', 'referencesets/1']
     for path in paths:
         versionedPath = utils.applyVersion(path)
         self.assertEqual(404, self.app.get(versionedPath).status_code)
     paths = ['/references/search']
     for path in paths:
         versionedPath = utils.applyVersion(path)
         self.assertEqual(404, self.app.get(versionedPath).status_code)
     self.verifySearchRouting('/referencesets/search', True)
Exemplo n.º 5
0
 def test404sReturnJson(self):
     paths = [
         '/doesNotExist',
         utils.applyVersion('/doesNotExist'),
         utils.applyVersion('/reads/sea'),
         utils.applyVersion('/variantsets/id/doesNotExist'),
     ]
     for path in paths:
         response = self.app.get(path)
         protocol.GAException.fromJsonString(response.get_data())
         self.assertEqual(404, response.status_code)
Exemplo n.º 6
0
 def testRouteReferences(self):
     referenceId = "referenceSet0:srs0"
     paths = ['/references/{}', '/references/{}/bases']
     for path in paths:
         path = path.format(referenceId)
         versionedPath = utils.applyVersion(path)
         self.assertEqual(200, self.app.get(versionedPath).status_code)
     referenceSetId = "referenceSet0"
     paths = ['/referencesets/{}']
     for path in paths:
         path = path.format(referenceSetId)
         versionedPath = utils.applyVersion(path)
         self.assertEqual(200, self.app.get(versionedPath).status_code)
     self.verifySearchRouting('/referencesets/search', True)
     self.verifySearchRouting('/references/search', True)
Exemplo n.º 7
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.
        """
        versionedPath = utils.applyVersion(path)
        response = self.app.post(versionedPath)
        protocol.GAException.fromJsonString(response.get_data())
        self.assertEqual(415, response.status_code)
        if not getDefined:
            getResponse = self.app.get(versionedPath)
            protocol.GAException.fromJsonString(getResponse.get_data())
            self.assertEqual(405, getResponse.status_code)

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

        # OPTIONS should return success
        self.assertEqual(200, self.app.options(versionedPath).status_code)
Exemplo n.º 8
0
 def sendPostRequest(self, path, request):
     """
     Sends the specified GA request object and returns the response.
     """
     versionedPath = utils.applyVersion(path)
     headers = {"Content-type": "application/json", "Origin": self.exampleUrl}
     return self.app.post(versionedPath, headers=headers, data=request.toJsonString())
Exemplo n.º 9
0
 def sendListRequest(self, path, request):
     versionedPath = utils.applyVersion(path)
     headers = {
         'Origin': self.exampleUrl,
     }
     data = request.toJsonDict()
     response = self.app.get(versionedPath, data=data, headers=headers)
     return response
Exemplo n.º 10
0
 def sendGetRequest(self, path):
     """
     Sends a get request to the specified URL and returns the response.
     """
     versionedPath = utils.applyVersion(path)
     headers = {
         'Origin': self.exampleUrl,
     }
     return self.app.get(versionedPath, headers=headers)
Exemplo n.º 11
0
 def testGetVariantSet(self):
     path = utils.applyVersion("/variantsets")
     for variantSetId in self.variantSetIds:
         response = self.sendObjectGetRequest(path, variantSetId)
         self.assertEqual(200, response.status_code)
         responseObject = protocol.VariantSet.fromJsonString(response.data)
         self.assertEqual(responseObject.id, variantSetId)
     for badId in ["", "terribly bad ID value", "x" * 1000]:
         response = self.sendObjectGetRequest(path, badId)
         self.assertEqual(404, response.status_code)
Exemplo n.º 12
0
 def sendPostRequest(self, path, request):
     """
     Sends the specified GA request object and returns the response.
     """
     versionedPath = utils.applyVersion(path)
     headers = {
         'Content-type': 'application/json',
         'Origin': self.exampleUrl,
     }
     return self.app.post(versionedPath,
                          headers=headers,
                          data=request.toJsonString())
Exemplo n.º 13
0
    def testVariantsSearch(self):
        expectedIds = self.variantSetIds[:1]
        referenceName = '1'

        request = protocol.GASearchVariantsRequest()
        request.referenceName = referenceName
        request.start = 0
        request.end = 0
        request.variantSetIds = expectedIds

        # Request windows is too small, no results
        path = utils.applyVersion('/variants/search')
        response = self.sendJsonPostRequest(
            path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.GASearchVariantsResponse.fromJsonString(
            response.data)
        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual([], responseData.variants)

        # Larger request window, expect results
        request.end = 2 ** 16
        path = utils.applyVersion('/variants/search')
        response = self.sendJsonPostRequest(
            path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.GASearchVariantsResponse.fromJsonString(
            response.data)
        self.assertTrue(protocol.GASearchVariantsResponse.validate(
            responseData.toJsonDict()))
        self.assertGreater(len(responseData.variants), 0)

        # Verify all results are in the correct range, set and reference
        for variant in responseData.variants:
            self.assertGreaterEqual(variant.start, 0)
            self.assertLessEqual(variant.end, 2 ** 16)
            self.assertTrue(variant.variantSetId in expectedIds)
            self.assertEqual(variant.referenceName, referenceName)
Exemplo n.º 14
0
    def testVariantsSearch(self):
        expectedId = self.variantSetIds[0]
        referenceName = '1'

        request = protocol.SearchVariantsRequest()
        request.referenceName = referenceName
        request.start = 0
        request.end = 0
        request.variantSetId = expectedId

        # Request windows is too small, no results
        path = utils.applyVersion('/variants/search')
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.SearchVariantsResponse.fromJsonString(
            response.data)
        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual([], responseData.variants)

        # Larger request window, expect results
        request.end = 2**16
        path = utils.applyVersion('/variants/search')
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.SearchVariantsResponse.fromJsonString(
            response.data)
        self.assertTrue(
            protocol.SearchVariantsResponse.validate(
                responseData.toJsonDict()))
        self.assertGreater(len(responseData.variants), 0)

        # Verify all results are in the correct range, set and reference
        for variant in responseData.variants:
            self.assertGreaterEqual(variant.start, 0)
            self.assertLessEqual(variant.end, 2**16)
            self.assertEqual(variant.variantSetId, expectedId)
            self.assertEqual(variant.referenceName, referenceName)
Exemplo n.º 15
0
 def setUp(self):
     # TODO replace this with ALL post methods once the rest of the
     # end points have been implemented. This should also add an API
     # to protocol.py to simplify and document the process of getting
     # the correct API endpoints and classes. That is, we shouldn't
     # use protocol.postMethods directly, but instead call a function.
     supportedMethods = set([
         protocol.SearchCallSetsRequest,
         protocol.SearchVariantSetsRequest,
         protocol.SearchVariantsRequest,
     ])
     self.endPointMap = {}
     for endPoint, requestClass, responseClass in protocol.postMethods:
         if requestClass in supportedMethods:
             path = utils.applyVersion(endPoint)
             self.endPointMap[path] = requestClass
Exemplo n.º 16
0
 def setUp(self):
     self.app = _app
     # TODO replace this with ALL post methods once the rest of the
     # end points have been implemented. This should also add an API
     # to protocol.py to simplify and document the process of getting
     # the correct API endpoints and classes. That is, we shouldn't
     # use protocol.postMethods directly, but instead call a function.
     supportedMethods = set([
         protocol.GASearchCallSetsRequest,
         protocol.GASearchVariantSetsRequest,
         protocol.GASearchVariantsRequest,
     ])
     self.endPointMap = {}
     for endPoint, requestClass, responseClass in protocol.postMethods:
         if requestClass in supportedMethods:
             path = utils.applyVersion(endPoint)
             self.endPointMap[path] = requestClass
Exemplo n.º 17
0
    def testVariantSetsSearch(self):
        expectedIds = self.variantSetIds
        request = protocol.GASearchVariantSetsRequest()
        request.pageSize = len(expectedIds)
        path = utils.applyVersion('/variantsets/search')
        response = self.sendJsonPostRequest(
            path, request.toJsonString())

        self.assertEqual(200, response.status_code)

        responseData = protocol.GASearchVariantSetsResponse.fromJsonString(
            response.data)
        self.assertTrue(protocol.GASearchVariantSetsResponse.validate(
            responseData.toJsonDict()))

        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual(len(expectedIds), len(responseData.variantSets))
        for variantSet in responseData.variantSets:
            self.assertTrue(variantSet.id in expectedIds)
Exemplo n.º 18
0
    def testVariantSetsSearch(self):
        expectedIds = self.variantSetIds
        request = protocol.SearchVariantSetsRequest()
        request.pageSize = len(expectedIds)
        path = utils.applyVersion('/variantsets/search')
        response = self.sendJsonPostRequest(path, request.toJsonString())

        self.assertEqual(200, response.status_code)

        responseData = protocol.SearchVariantSetsResponse.fromJsonString(
            response.data)
        self.assertTrue(
            protocol.SearchVariantSetsResponse.validate(
                responseData.toJsonDict()))

        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual(len(expectedIds), len(responseData.variantSets))
        for variantSet in responseData.variantSets:
            self.assertTrue(variantSet.id in expectedIds)
Exemplo n.º 19
0
    def testCallSetsSearch(self):
        # TODO remove the @nottest decorator here once calls have been
        # properly implemented in the simulator.
        request = protocol.GASearchCallSetsRequest()
        request.name = None
        path = utils.applyVersion('/callsets/search')

        # when variantSetIds are wrong, no results
        request.variantSetIds = ["xxxx"]
        response = self.sendJsonPostRequest(
            path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.GASearchCallSetsResponse.fromJsonString(
            response.data)
        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual([], responseData.callSets)

        # if no callset name is given return all callsets
        request.variantSetIds = self.variantSetIds[:1]
        response = self.sendJsonPostRequest(
            path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.GASearchCallSetsResponse.fromJsonString(
            response.data)
        self.assertTrue(protocol.GASearchCallSetsResponse.validate(
            responseData.toJsonDict()))
        self.assertNotEqual([], responseData.callSets)
        # TODO test the length of responseData.callSets equal to all callsets

        # Verify all results are of the correct type and range
        for callSet in responseData.callSets:
            self.assertIs(type(callSet.info), dict)
            self.assertIs(type(callSet.variantSetIds), list)
            splits = callSet.id.split(".")
            variantSetId = '.'.join(splits[:2])
            callSetName = splits[-1]
            self.assertIn(variantSetId, callSet.variantSetIds)
            self.assertEqual(callSetName, callSet.name)
            self.assertEqual(callSetName, callSet.sampleId)
Exemplo n.º 20
0
    def testCallSetsSearch(self):
        # TODO remove the @skipIf decorator here once calls have been
        # properly implemented in the simulator.
        request = protocol.SearchCallSetsRequest()
        request.name = None
        path = utils.applyVersion('/callsets/search')

        # when variantSetIds are wrong, no results
        request.variantSetIds = ["xxxx"]
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.SearchCallSetsResponse.fromJsonString(
            response.data)
        self.assertIsNone(responseData.nextPageToken)
        self.assertEqual([], responseData.callSets)

        # if no callset name is given return all callsets
        request.variantSetIds = self.variantSetIds[:1]
        response = self.sendJsonPostRequest(path, request.toJsonString())
        self.assertEqual(200, response.status_code)
        responseData = protocol.SearchCallSetsResponse.fromJsonString(
            response.data)
        self.assertTrue(
            protocol.SearchCallSetsResponse.validate(
                responseData.toJsonDict()))
        self.assertNotEqual([], responseData.callSets)
        # TODO test the length of responseData.callSets equal to all callsets

        # Verify all results are of the correct type and range
        for callSet in responseData.callSets:
            self.assertIs(type(callSet.info), dict)
            self.assertIs(type(callSet.variantSetIds), list)
            splits = callSet.id.split(".")
            variantSetId = '.'.join(splits[:2])
            callSetName = splits[-1]
            self.assertIn(variantSetId, callSet.variantSetIds)
            self.assertEqual(callSetName, callSet.name)
            self.assertEqual(callSetName, callSet.sampleId)
Exemplo n.º 21
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.
        """
        versionedPath = utils.applyVersion(path)
        response = self.app.post(versionedPath)
        protocol.GAException.fromJsonString(response.get_data())
        self.assertEqual(415, response.status_code)
        if not getDefined:
            getResponse = self.app.get(versionedPath)
            protocol.GAException.fromJsonString(getResponse.get_data())
            self.assertEqual(405, getResponse.status_code)

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

        # OPTIONS should return success
        self.assertEqual(200, self.app.options(versionedPath).status_code)
Exemplo n.º 22
0
 def runRequest(method, path):
     requestPath = path.replace('<id>', 'someId')
     versionedPath = utils.applyVersion(requestPath)
     response = method(versionedPath)
     protocol.GAException.fromJsonString(response.get_data())
     self.assertEqual(response.status_code, 501)
Exemplo n.º 23
0
 def testRouteCallsets(self):
     path = utils.applyVersion('/callsets/search')
     self.assertEqual(415, self.app.post(path).status_code)
     self.assertEqual(200, self.app.options(path).status_code)
     self.assertEqual(405, self.app.get(path).status_code)
Exemplo n.º 24
0
 def test404sReturnJson(self):
     path = utils.applyVersion('/doesNotExist')
     response = self.app.get(path)
     protocol.GAException.fromJsonString(response.get_data())
     self.assertEqual(404, response.status_code)
Exemplo n.º 25
0
 def testRouteCallsets(self):
     path = utils.applyVersion('/callsets/search')
     self.assertEqual(415, self.app.post(path).status_code)
     self.assertEqual(200, self.app.options(path).status_code)
     self.assertEqual(405, self.app.get(path).status_code)
Exemplo n.º 26
0
 def test404sReturnJson(self):
     path = utils.applyVersion('/doesNotExist')
     response = self.app.get(path)
     protocol.GAException.fromJsonString(response.get_data())
     self.assertEqual(404, response.status_code)