def get(self, *args, **kwargs): barcode = self.get_argument('barcode', None) filetype = self.get_argument('filetype', None) if barcode is None or filetype is None: raise HTTPError(400, "Incorrectly formed GET request") # Check access to file has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return if filetype not in FILETYPES: raise HTTPError(400, "Unrecognized filetype") filetype_path, filetype_suffix = FILETYPES[filetype] fname = barcode + filetype_suffix fullpath = join(filetype_path, fname) if not exists(join(AMGUT_CONFIG.base_data_dir, fullpath)): raise HTTPError(400, "File %s is not available" % fullpath) self.set_header('Content-Description', 'File Transfer') self.set_header('Content-Type', 'application/octet-stream') self.set_header('Content-Transfer-Encoding', 'binary') self.set_header('Expires', '0') self.set_header('Cache-Control', 'no-cache') self.set_header('X-Accel-Redirect', '/protected/' + fullpath) self.set_header('Content-Disposition', 'attachment; filename=%s' % fname) self.finish()
def get(self, barcode): # nothing else to do barcode = barcode.strip("/") # for nginx rewrites if barcode is None: tl = text_locale["handlers"] self.render("taxa_summary.html", skid=self.current_user, loginerror=tl["BARCODE_ERROR"]) return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return # we need this path to access the filesystem taxa_summary_fp = join(AMGUT_CONFIG.base_data_dir, "taxa-summaries", barcode + ".txt") # and we need this path for users to access the file taxa_summary_url = join(media_locale["SITEBASE"], "results", "taxa-summaries", barcode + ".txt") # read lines from taxa summary table, omit comment lines with open(taxa_summary_fp, "U") as fp: lines = [x.replace(";", "\t").strip() for x in fp if not x.startswith("#")] # remove the greengenes prefixes. If hierarchy is delimitd by # semicolon- space, the GG prefix may be preceded by a space lines = [sub(" *?[kpcofg]__", "", x) for x in lines] # we must operate on the genus and percent abundance columns # individually, so it must be split into individual cells lines = [x.split("\t") for x in lines] for i in range(len(lines)): for j in range(len(lines[i])): if lines[i][j] == "": lines[i][j] = "---" # format the last column to be a 2.2 number, and center it relative_abundance = float(lines[i][-1]) relative_abundance *= 100 lines[i][-1] = "%2.2f" % relative_abundance # generate headers headers = ["Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Relative Abundance (%)"] self.render( "taxa_summary.html", headers=headers, data=lines, barcode=barcode, file_path=taxa_summary_url, loginerror="", skid=self.current_user, )
def get(self, barcode): # nothing else to do barcode = barcode.strip('/') # for nginx rewrites if barcode is None: tl = text_locale['handlers'] self.render('taxa_summary.html', skid=self.current_user, loginerror=tl["BARCODE_ERROR"]) return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return # we need this path to access the filesystem taxa_summary_fp = join(AMGUT_CONFIG.base_data_dir, 'taxa-summaries', barcode+'.txt') # and we need this path for users to access the file taxa_summary_url = join(media_locale['SITEBASE'], 'results', 'taxa-summaries', barcode+'.txt') # read lines from taxa summary table, omit comment lines lines = [x.replace(';', '\t').strip() for x in open(taxa_summary_fp, 'U').readlines() if not x.startswith('#')] # remove the greengenes prefixes. If hierarchy is delimitd by # semicolon- space, the GG prefix may be preceded by a space lines = [sub(' *?[kpcofg]__', '', x) for x in lines] # we must operate on the genus and percent abundance columns # individually, so it must be split into individual cells lines = [x.split('\t') for x in lines] for i in range(len(lines)): for j in range(len(lines[i])): if lines[i][j] == '': lines[i][j] = '---' # format the last column to be a 2.2 number, and center it relative_abundance = float(lines[i][-1]) relative_abundance *= 100 lines[i][-1] = '%2.2f' % relative_abundance # generate headers headers = ['Kingdom', 'Phylum', 'Class', 'Order', 'Family', 'Genus', 'Relative Abundance (%)'] self.render('taxa_summary.html', headers=headers, data=lines, barcode=barcode, file_path=taxa_summary_url, loginerror="", skid=self.current_user)
def get(self, barcode): if barcode is None: self.redirect(media_locale['SITEBASE'] + '/authed/portal/') return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return self.render('interactive_report.html', skid=self.current_user, barcode=barcode)
def _sample_overview_renderer(self): barcode = self.get_argument('barcode', None) if barcode is None: self.redirect(media_locale['SITEBASE'] + '/authed/portal/') return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return sample_data = ag_data.getAGBarcodeDetails(barcode) if not sample_data: self.set_status(404) self.render("404.html", skid=self.current_user) return web_barcode_pdf, web_barcode_txt = _get_data_path(barcode) unidentified_results = _get_per_sample_results(barcode) per_sample_data = _get_per_sample_data(barcode) sample_time = sample_data['sample_time'] sample_date = sample_data['sample_date'] status = sample_data['status'] if status is None: bgcolor = '#FFF' status = 'Submitted' elif status == 'Received': bgcolor = '#AFA' else: bgcolor = '#FFF' sample_origin = sample_data['site_sampled'] if sample_origin is None: sample_origin = sample_data['environment_sampled'] notes = sample_data['notes'] if notes is None: notes = '' self.render('sample_overview.html', skid=self.current_user, barcode_pdf=web_barcode_pdf, barcode_txt=web_barcode_txt, bgcolor=bgcolor, status=status, barcode=barcode, sample_origin=sample_origin, sample_date=sample_date, sample_time=sample_time, notes=notes, unidentified_results=unidentified_results, per_sample_data=per_sample_data)
def _sample_overview_renderer(self): barcode = self.get_argument('barcode', None) if barcode is None: self.redirect(media_locale['SITEBASE'] + '/authed/portal/') return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return sample_data = ag_data.getAGBarcodeDetails(barcode) if not sample_data: self.set_status(404) self.render("404.html", skid=self.current_user) return web_barcode_pdf, web_barcode_txt = _get_data_path(barcode) sequence_url = None biomv1_url = None classic_url = None sequence_url = None api_base = 'http://api.microbio.me/americangut/1/' req = requests.get(api_base + 'sample/%s' % barcode) if req.status_code == 200 and req.content != "(null)": bc_with_suf = json.loads(req.content)[0] biomv1_url = api_base + 'otu/%s/json' % bc_with_suf classic_url = api_base + 'otu/%s/txt' % bc_with_suf seq_req = requests.get(api_base + 'sequence/%s' % bc_with_suf) if seq_req.status_code == 200: sequence_url = json.loads(seq_req.content)[0]['fastq_url'] sample_time = sample_data['sample_time'] sample_date = sample_data['sample_date'] status = sample_data['status'] if status is None: bgcolor = '#FFF' status = 'Submitted' elif status == 'Received': bgcolor = '#AFA' else: bgcolor = '#FFF' sample_origin = sample_data['site_sampled'] if sample_origin is None: sample_origin = sample_data['environment_sampled'] notes = sample_data['notes'] if notes is None: notes = '' self.render('sample_overview.html', skid=self.current_user, barcode_pdf=web_barcode_pdf, barcode_txt=web_barcode_txt, bgcolor=bgcolor, status=status, barcode=barcode, sample_origin=sample_origin, sample_date=sample_date, sample_time=sample_time, notes=notes, sequence_url=sequence_url, biomv1_url=biomv1_url, classic_url=classic_url)
def get(self, barcode): # nothing else to do barcode = barcode.strip('/') # for nginx rewrites if barcode is None: tl = text_locale['handlers'] self.render('taxa_summary.html', skid=self.current_user, loginerror=tl["BARCODE_ERROR"]) return has_access = ag_data.check_access(self.current_user, barcode) if not has_access: self.set_status(403) self.render("403.html", skid=self.current_user) return # we need this path to access the filesystem taxa_summary_fp = join(AMGUT_CONFIG.base_data_dir, 'taxa-summaries', barcode + '.txt') # and we need this path for users to access the file taxa_summary_url = join(media_locale['SITEBASE'], 'results', 'taxa-summaries', barcode + '.txt') # read lines from taxa summary table, omit comment lines with open(taxa_summary_fp, 'U') as fp: lines = [ x.replace(';', '\t').strip() for x in fp if not x.startswith('#') ] # remove the greengenes prefixes. If hierarchy is delimitd by # semicolon- space, the GG prefix may be preceded by a space lines = [sub(' *?[kpcofg]__', '', x) for x in lines] # we must operate on the genus and percent abundance columns # individually, so it must be split into individual cells lines = [x.split('\t') for x in lines] for i in range(len(lines)): for j in range(len(lines[i])): if lines[i][j] == '': lines[i][j] = '---' # format the last column to be a 2.2 number, and center it relative_abundance = float(lines[i][-1]) relative_abundance *= 100 lines[i][-1] = '%2.2f' % relative_abundance # generate headers headers = [ 'Kingdom', 'Phylum', 'Class', 'Order', 'Family', 'Genus', 'Relative Abundance (%)' ] self.render('taxa_summary.html', headers=headers, data=lines, barcode=barcode, file_path=taxa_summary_url, loginerror="", skid=self.current_user)