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)
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
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)
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
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
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
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))
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())
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))
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
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
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())
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
def getAllele(version, id): raise exceptions.NotImplementedException()
def getVariantSetSequence(version, vsid, sid): raise exceptions.NotImplementedException()
def getSequenceBases(version, id): raise exceptions.NotImplementedException()
def getMode(version, mode): raise exceptions.NotImplementedException()
def searchJoins(version): raise exceptions.NotImplementedException()
def getVariant(version, id): raise exceptions.NotImplementedException()
def searchSequences(version): raise exceptions.NotImplementedException()
def searchIndividualGroups(version): raise exceptions.NotImplementedException()
def searchExperiments(version): raise exceptions.NotImplementedException()
def searchGenotypePephenotype(version): raise exceptions.NotImplementedException()
def getReadGroup(version, id): raise exceptions.NotImplementedException()
def getDataset(version, id): raise exceptions.NotImplementedException()
def searchFeatures(version): raise exceptions.NotImplementedException()
def searchVariantSetSequences(version, id): raise exceptions.NotImplementedException()
def searchAlleles(version): raise exceptions.NotImplementedException()
def subgraphJoins(version): raise exceptions.NotImplementedException()
def getFeature(version, id): raise exceptions.NotImplementedException()