def next(self): """Returns the data from the call to the GenomicsAPI Raises: StopIteration: The data has been exhausted. """ # If it's your first time or you have a token then make the call. if self._firstTime or self._nextPageToken: api = GenomicsAPI() # Get the results try: content = api.read_search(self._readsetId, self._sequenceName, self._sequenceStart, self._sequenceEnd, self._nextPageToken) self._firstTime = False except ApiException as exception: logging.warning("API exception: %s" % exception.message) raise StopIteration() self._nextPageToken = content[ "nextPageToken"] if 'nextPageToken' in content else None return content, self._sequenceStart, self._sequenceEnd else: raise StopIteration()
def next(self): """Returns the data from the call to the GenomicsAPI Raises: StopIteration: The list of files has been exhausted. """ # If it's your first time or you have a token then make the call. if self._firstTime or self._nextPageToken: api = GenomicsAPI() # Get the results content = None try: content = api.read_search(self._readsetId, self._sequenceName, self._sequenceStart, self._sequenceEnd, self._nextPageToken) self._firstTime = False except ApiException as exception: errorMessage = exception.message raise StopIteration() self._nextPageToken = content["nextPageToken"] if 'nextPageToken' in content else None return (content, self._sequenceStart, self._sequenceEnd) else: # All Done #logging.debug("GenomicsAPIInputReader next() is Done start: %d end: %d.", # self._sequenceStart, self._sequenceEnd) raise StopIteration()
def next(self): """Returns the data from the call to the GenomicsAPI Raises: StopIteration: The data has been exhausted. """ # If it's your first time or you have a token then make the call. if self._firstTime or self._nextPageToken: api = GenomicsAPI() # Get the results try: content = api.read_search(self._readsetId, self._sequenceName, self._sequenceStart, self._sequenceEnd, self._nextPageToken) self._firstTime = False except ApiException as exception: logging.warning("API exception: %s" % exception.message) raise StopIteration() self._nextPageToken = content["nextPageToken"] if 'nextPageToken' in content else None return content, self._sequenceStart, self._sequenceEnd else: raise StopIteration()
def post(self): # Collect inputs. readsetId = self.request.get("readsetId") sequenceName = self.request.get('sequenceName') sequenceStart = int(self.request.get('sequenceStart')) sequenceEnd = int(self.request.get('sequenceEnd')) useMockData = self.request.get('useMockData') # TODO: Validate inputs such as sequence start and end to make # sure they are in bounds based on TARGETS. content = None coverage = None errorMessage = None if self.request.get("submitRead"): # Use the API to get the requested data. # If you are running the real pipeline map reduce then hit it. if self.request.get('runPipeline'): logging.debug("Running pipeline") pipeline = CoveragePipeline(readsetId, sequenceName, sequenceStart, sequenceEnd, useMockData) pipeline.start() self.redirect(pipeline.base_path + "/status?root=" + pipeline.pipeline_id) return if useMockData: # Use the mock to get coverage information. mock = MockGenomicsAPI() content = mock.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd) else: # Make the API call here to process directly. try: api = GenomicsAPI() content = api.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd) except ApiException as exception: errorMessage = exception.message elif self.request.get("submitReadSample"): # Read in local sample data which is based off of default settings. body = MainHandler.DEFAULT_SETTINGS path = os.path.join( os.path.split(__file__)[0], 'static/listRead_SampleData.json') file = open(path, 'r') content = file.read() file.close() content = json.loads(content) # If you have content then compute and store the results. if content is not None: if 'reads' in content: # Calculate results coverage = compute_coverage(content, sequenceStart, sequenceEnd) # TODO make a setting to turn this on/off? #store_coverage(readsetId, sequenceName, coverage) else: errorMessage = "There API did not return any reads to process." else: errorMessage = "No content was returned to process." # Render template with results or error. username = users.User().nickname() template = JINJA_ENVIRONMENT.get_template('index.html') self.response.out.write( template.render({ "username": username, "targets": MainHandler.TARGETS, "settings": { 'readsetId': readsetId, 'sequenceName': sequenceName, 'sequenceStart': sequenceStart, 'sequenceEnd': sequenceEnd, 'useMockData': useMockData, }, "errorMessage": errorMessage, "results": coverage, }))
def post(self): # Collect inputs. readsetId = self.request.get("readsetId") sequenceName = self.request.get('sequenceName') sequenceStart = int(self.request.get('sequenceStart')) sequenceEnd = int(self.request.get('sequenceEnd')) useMockData = self.request.get('useMockData') # TODO: Validate inputs such as sequence start and end to make # sure they are in bounds based on TARGETS. reads = [] coverage = None errorMessage = None if self.request.get("submitRead"): # Use the API to get the requested data. # If you are running the real pipeline map reduce then hit it. if self.request.get('runPipeline'): logging.debug("Running pipeline") pipeline = PipelineGenerateCoverage(readsetId, sequenceName, sequenceStart, sequenceEnd, useMockData) pipeline.start() self.redirect(pipeline.base_path + "/status?root=" + pipeline.pipeline_id) return # Make the API calls directly from the web ui. api = GenomicsAPI() # Use the Mock API if requested. if useMockData: api = MockGenomicsAPI() # Make the call. try: pageToken = None firstTime = True while firstTime or pageToken is not None: content = api.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd, pageToken) firstTime = False if 'reads' in content: reads += content['reads'] pageToken = content['nextPageToken'] if 'nextPageToken' in content\ else None except ApiException as exception: errorMessage = exception.message elif self.request.get("submitReadSample"): # Read in local sample data which is based off of default settings. readsetId = MainHandler.DEFAULT_SETTINGS['readsetId'] sequenceName = MainHandler.DEFAULT_SETTINGS['sequenceName'] sequenceStart = MainHandler.DEFAULT_SETTINGS['sequenceStart'] sequenceEnd = MainHandler.DEFAULT_SETTINGS['sequenceEnd'] path = os.path.join( os.path.split(__file__)[0], 'static/listRead_SampleData.json') file = open(path, 'r') content = file.read() file.close() content = json.loads(content) reads = content['reads'] # If you have content then compute and store the results. if reads is not None and len(reads) > 0: # Calculate results coverage = GenomicsAPI.compute_coverage(reads, sequenceStart, sequenceEnd) # TODO make a setting to turn this on/off? #GenomicsCoverageStatistics.store_coverage(readsetId, sequenceName, # coverage) else: errorMessage = "There API did not return any reads to process." # Render template with results or error. username = users.User().nickname() version = os.environ['CURRENT_VERSION_ID'] template = JINJA_ENVIRONMENT.get_template('index.html') self.response.out.write( template.render({ "username": username, "version": version, "targets": GenomicsAPI.TARGETS, "settings": { 'readsetId': readsetId, 'sequenceName': sequenceName, 'sequenceStart': sequenceStart, 'sequenceEnd': sequenceEnd, 'useMockData': useMockData, }, "errorMessage": errorMessage, "results": coverage, }))
def post(self): # Collect inputs. readsetId = self.request.get("readsetId") sequenceName = self.request.get('sequenceName') sequenceStart = int(self.request.get('sequenceStart')) sequenceEnd = int(self.request.get('sequenceEnd')) useMockData = self.request.get('useMockData') # TODO: Validate inputs such as sequence start and end to make # sure they are in bounds based on TARGETS. reads = [] coverage = None errorMessage = None if self.request.get("submitRead"): # Use the API to get the requested data. # If you are running the real pipeline map reduce then hit it. if self.request.get('runPipeline'): pipeline = PipelineGenerateCoverage(readsetId, sequenceName, sequenceStart, sequenceEnd, useMockData) pipeline.start() self.redirect(pipeline.base_path + "/status?root=" + pipeline.pipeline_id) return # Make the API calls directly from the web ui. api = GenomicsAPI() # Use the Mock API if requested. if useMockData: api = MockGenomicsAPI() # Make the call. try: pageToken = None firstTime = True while firstTime or pageToken is not None: content = api.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd, pageToken) firstTime = False if 'reads' in content: reads += content['reads'] pageToken = content['nextPageToken'] if 'nextPageToken' in content\ else None except ApiException as exception: errorMessage = exception.message elif self.request.get("submitReadSample"): # Read in local sample data which is based off of default settings. readsetId = MainHandler.DEFAULT_SETTINGS['readsetId'] sequenceName = MainHandler.DEFAULT_SETTINGS['sequenceName'] sequenceStart = MainHandler.DEFAULT_SETTINGS['sequenceStart'] sequenceEnd = MainHandler.DEFAULT_SETTINGS['sequenceEnd'] path = os.path.join(os.path.split(__file__)[0], 'static/reads-search_sample_data.json') file = open(path, 'r') content = file.read() file.close() content = json.loads(content) reads = content['reads'] # Calculate results coverage = GenomicsAPI.compute_coverage(reads, sequenceStart, sequenceEnd) # TODO make a setting to turn this on/off? #GenomicsCoverageStatistics.store_coverage(readsetId, sequenceName, # coverage) # Render template with results or error. username = users.User().nickname() template = JINJA_ENVIRONMENT.get_template('index.html') self.response.out.write(template.render({ "username": username, "version": self._get_version(), "targets": GenomicsAPI.TARGETS, "settings": { 'readsetId': readsetId, 'sequenceName': sequenceName, 'sequenceStart': sequenceStart, 'sequenceEnd': sequenceEnd, 'useMockData': useMockData, }, "errorMessage": errorMessage, "results": coverage, }))
def post(self): # Collect inputs. readsetId = self.request.get("readsetId") sequenceName = self.request.get('sequenceName') sequenceStart = int(self.request.get('sequenceStart')) sequenceEnd = int(self.request.get('sequenceEnd')) useMockData = self.request.get('useMockData') # TODO: Validate inputs such as sequence start and end to make # sure they are in bounds based on TARGETS. content = None coverage = None errorMessage = None if self.request.get("submitRead"): # Use the API to get the requested data. # If you are running the real pipeline map reduce then hit it. if self.request.get('runPipeline'): logging.debug("Running pipeline") pipeline = CoveragePipeline(readsetId, sequenceName, sequenceStart, sequenceEnd, useMockData) pipeline.start() self.redirect(pipeline.base_path + "/status?root=" + pipeline.pipeline_id) return if useMockData: # Use the mock to get coverage information. mock = MockGenomicsAPI() content = mock.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd) else: # Make the API call here to process directly. try: api = GenomicsAPI() content = api.read_search(readsetId, sequenceName, sequenceStart, sequenceEnd) except ApiException as exception: errorMessage = exception.message elif self.request.get("submitReadSample"): # Read in local sample data which is based off of default settings. body = MainHandler.DEFAULT_SETTINGS path = os.path.join(os.path.split(__file__)[0], 'static/listRead_SampleData.json') file = open(path, 'r') content = file.read() file.close() content = json.loads(content) # If you have content then compute and store the results. if content is not None: if 'reads' in content: # Calculate results coverage = compute_coverage(content, sequenceStart, sequenceEnd) # TODO make a setting to turn this on/off? #store_coverage(readsetId, sequenceName, coverage) else: errorMessage = "There API did not return any reads to process." else: errorMessage = "No content was returned to process." # Render template with results or error. username = users.User().nickname() template = JINJA_ENVIRONMENT.get_template('index.html') self.response.out.write(template.render({ "username": username, "targets": MainHandler.TARGETS, "settings": { 'readsetId': readsetId, 'sequenceName': sequenceName, 'sequenceStart': sequenceStart, 'sequenceEnd': sequenceEnd, 'useMockData': useMockData, }, "errorMessage": errorMessage, "results": coverage, }))