Ejemplo n.º 1
0
 def getVariants(self, referenceName, startPosition, endPosition,
                 variantName=None, callSetIds=None):
     """
     Returns an iterator over the specified variants. The parameters
     correspond to the attributes of a GASearchVariantsRequest object.
     """
     if variantName is not None:
         raise exceptions.NotImplementedException(
             "Searching by variantName is not supported")
     # For v0.5.1, callSetIds=[] actually means return all callSets.
     # In v0.6+, callSetIds=[] means return no call sets, and
     # callSetIds=None means return all call sets. For forward
     # compatibility, we use the 0.6 interface for this function but
     # we translate back to the 0.5 interface while we support this.
     # TODO Remove this comment and workaround once we transition to
     # protocol version 0.6
     if callSetIds is None:
         callSetIds = []
     else:
         for callSetId in callSetIds:
             if callSetId not in self._callSetIds:
                 raise exceptions.CallSetNotInVariantSetException(
                     callSetId, self.getId())
     if len(callSetIds) == 0:
         callSetIds = self._callSetIds
     if referenceName in self._chromFileMap:
         varFileName = self._chromFileMap[referenceName]
         referenceName, startPosition, endPosition = \
             self.sanitizeVariantFileFetch(
                 referenceName, startPosition, endPosition)
         cursor = self.getFileHandle(varFileName).fetch(
             referenceName, startPosition, endPosition)
         for record in cursor:
             yield self.convertVariant(record, callSetIds)
Ejemplo n.º 2
0
 def _getDatasetFromReadsRequest(self, request):
     if len(request.readGroupIds) != 1:
         raise exceptions.NotImplementedException(
             "Exactly one read group id must be specified")
     compoundId = request.readGroupIds[0]
     dataset = self._getDatasetFromCompoundId(compoundId)
     return dataset
Ejemplo n.º 3
0
 def testNotImplementedException(self):
     message = "A string unlikely to occur at random."
     exception = exceptions.NotImplementedException(message)
     response = frontend.handleException(exception)
     self.assertEquals(response.status_code, 501)
     gaException = self.getGa4ghException(response.data)
     self.assertEquals(gaException.message, message)
Ejemplo n.º 4
0
 def _getDatasetFromVariantsRequest(self, request):
     variantSetIds = request.variantSetIds
     if len(variantSetIds) != 1:
         raise exceptions.NotImplementedException(
             "Exactly one variant set id must be specified")
     compoundId = request.variantSetIds[0]
     dataset = self._getDatasetFromCompoundId(compoundId)
     return dataset
Ejemplo n.º 5
0
def oidcCallback():
    """
    Once the authorization provider has cleared the user, the browser
    is returned here with a code. This function takes that code and
    checks it with the authorization provider to prove that it is valid,
    and get a bit more information about the user (which we don't use).

    A token is generated and given to the user, and the authorization info
    retrieved above is stored against this token. Later, when a client
    connects with this token, it is assumed to be a valid user.

    :return: A display of the authentication token to use in the client. If
    OIDC is not configured, raises a NotImplementedException.
    """
    if app.oidcClient is None:
        raise exceptions.NotImplementedException()
    response = dict(flask.request.args.iteritems(multi=True))
    aresp = app.oidcClient.parse_response(
        message.AuthorizationResponse,
        info=response,
        sformat='dict')
    sessState = flask.session.get('state')
    respState = aresp['state']
    if (not isinstance(aresp, message.AuthorizationResponse) or
            respState != sessState):
        raise exceptions.NotAuthenticatedException()

    args = {
        "code": aresp['code'],
        "redirect_uri": app.oidcClient.redirect_uris[0],
        "client_id": app.oidcClient.client_id,
        "client_secret": app.oidcClient.client_secret
    }
    atr = app.oidcClient.do_access_token_request(
        scope="openid",
        state=respState,
        request_args=args)

    if not isinstance(atr, message.AccessTokenResponse):
        raise exceptions.NotAuthenticatedException()

    atrDict = atr.to_dict()
    if flask.session.get('nonce') != atrDict['id_token']['nonce']:
        raise exceptions.NotAuthenticatedException()
    key = oic.oauth2.rndstr(SECRET_KEY_LENGTH)
    flask.session['key'] = key
    app.tokenMap[key] = aresp["code"], respState, atrDict
    # flask.url_for is broken. It relies on SERVER_NAME for both name
    # and port, and defaults to 'localhost' if not found. Therefore
    # we need to fix the returned url
    indexUrl = flask.url_for('index', _external=True)
    indexParts = list(urlparse.urlparse(indexUrl))
    if ':' not in indexParts[1]:
        indexParts[1] = '{}:{}'.format(socket.gethostname(), app.myPort)
        indexUrl = urlparse.urlunparse(indexParts)
    response = flask.redirect(indexUrl)
    return response
Ejemplo n.º 6
0
 def _getContainer(self):
     if len(self._request.readGroupIds) != 1:
         if len(self._request.readGroupIds) == 0:
             msg = "Read search requires a readGroup to be specified"
         else:
             msg = "Read search over multiple readGroups not supported"
         raise exceptions.NotImplementedException(msg)
     readGroupId = self._request.readGroupIds[0]
     readGroup = _safeMapQuery(self._containerIdMap, readGroupId,
                               exceptions.ReadGroupNotFoundException)
     return readGroup
Ejemplo n.º 7
0
 def _getPrefix(self, url):
     """
     Given a url return namespace prefix.
     Leverages prefixes already in graph namespace
     Ex.  "http://www.drugbank.ca/drugs/" -> "Drugbank"
     """
     for prefix, namespace in self._rdfGraph.namespaces():
         if namespace.toPython() == url or namespace == url:
             return prefix
     raise exceptions.NotImplementedException(
         "No namespace found for url {}".format(url))
Ejemplo n.º 8
0
 def callSetsGenerator(self, request):
     """
     Returns a generator over the (callSet, nextPageToken) pairs defined
     by the specified request.
     """
     if request.name is not None:
         raise exceptions.NotImplementedException(
             "Searching over names is not supported")
     variantSet = _getVariantSet(request, self._variantSetIdMap)
     return self._topLevelObjectGenerator(
         request, variantSet.getCallSetIdMap(),
         variantSet.getCallSetIds())
Ejemplo n.º 9
0
 def _toNamespaceURL(self, term):
     """
     Given an ontologyterm.term return namespace identifier.
     Leverages prefixes already in graph namespace
     Ex.  "DrugBank:DB01268" -> "http://www.drugbank.ca/drugs/DB01268"
     """
     termPrefix, termId = term.split(':')
     for prefix, namespace in self._rdfGraph.namespaces():
         if prefix == termPrefix:
             return "".join([namespace, termId])
     raise exceptions.NotImplementedException(
         "Term has a prefix not found in this instance. {}".format(term))
Ejemplo n.º 10
0
 def _getContainer(self):
     if len(self._request.readGroupIds) != 1:
         if len(self._request.readGroupIds) == 0:
             msg = "Read search requires a readGroup to be specified"
         else:
             msg = "Read search over multiple readGroups not supported"
         raise exceptions.NotImplementedException(msg)
     readGroupId = self._request.readGroupIds[0]
     try:
         readGroup = self._containerIdMap[self._request.readGroupIds[0]]
     except KeyError:
         raise exceptions.ReadGroupNotFoundException(readGroupId)
     return readGroup
Ejemplo n.º 11
0
def _getVariantSet(request, variantSetIdMap):
    if len(request.variantSetIds) != 1:
        if len(request.variantSetIds) == 0:
            msg = "Variant search requires specifying a variantSet"
        else:
            msg = ("Variant search over multiple variantSets "
                   "not supported")
        raise exceptions.NotImplementedException(msg)
    variantSetId = request.variantSetIds[0]
    try:
        variantSet = variantSetIdMap[variantSetId]
    except KeyError:
        raise exceptions.VariantSetNotFoundException(variantSetId)
    return variantSet
Ejemplo n.º 12
0
 def callSetsGenerator(self, request):
     """
     Returns a generator over the (callSet, nextPageToken) pairs defined
     by the specified request.
     """
     if request.name is not None:
         raise exceptions.NotImplementedException(
             "Searching over names is not supported")
     compoundId = datamodel.VariantSetCompoundId.parse(request.variantSetId)
     dataset = self.getDataset(compoundId.datasetId)
     variantSet = _getVariantSet(request, dataset.getVariantSetIdMap())
     return self._topLevelObjectGenerator(request,
                                          variantSet.getCallSetIdMap(),
                                          variantSet.getCallSetIds())
Ejemplo n.º 13
0
 def readsGenerator(self, request):
     """
     Returns a generator over the (read, nextPageToken) pairs defined
     by the specified request
     """
     if request.referenceId is None:
         raise exceptions.UnmappedReadsNotSupported()
     if len(request.readGroupIds) != 1:
         raise exceptions.NotImplementedException(
             "Exactly one read group id must be specified")
     compoundId = datamodel.ReadGroupCompoundId.parse(
         request.readGroupIds[0])
     dataset = self.getDataset(compoundId.datasetId)
     intervalIterator = ReadsIntervalIterator(request,
                                              dataset.getReadGroupIdMap())
     return intervalIterator
Ejemplo n.º 14
0
def getAllele(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 15
0
def getVariantSetSequence(version, vsid, sid):
    raise exceptions.NotImplementedException()
Ejemplo n.º 16
0
def getSequenceBases(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 17
0
def getMode(version, mode):
    raise exceptions.NotImplementedException()
Ejemplo n.º 18
0
def searchJoins(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 19
0
def getVariant(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 20
0
def searchSequences(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 21
0
def searchIndividualGroups(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 22
0
def searchExperiments(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 23
0
def searchGenotypePephenotype(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 24
0
def getReadGroup(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 25
0
def getDataset(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 26
0
def searchFeatures(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 27
0
def searchVariantSetSequences(version, id):
    raise exceptions.NotImplementedException()
Ejemplo n.º 28
0
def searchAlleles(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 29
0
def subgraphJoins(version):
    raise exceptions.NotImplementedException()
Ejemplo n.º 30
0
def getFeature(version, id):
    raise exceptions.NotImplementedException()