def get(self, arguments): study_id = int(self.get_argument('study_id')) # this block is tricky because you can either pass the sample or the # prep template and if none is passed then we will let an exception # be raised because template will not be declared for the logic below if self.get_argument('prep_template', None): template = PrepTemplate(int(self.get_argument('prep_template'))) if self.get_argument('sample_template', None): template = None tid = int(self.get_argument('sample_template')) try: template = SampleTemplate(tid) except QiitaDBUnknownIDError: raise HTTPError(404, "SampleTemplate %d does not exist" % tid) study = Study(template.study_id) # check whether or not the user has access to the requested information if not study.has_access(User(self.current_user)): raise HTTPError(403, "You do not have access to access this " "information.") df = dataframe_from_template(template) stats = stats_from_df(df) self.render('metadata_summary.html', user=self.current_user, study_title=study.title, stats=stats, study_id=study_id)
def get(self, arguments): study_id = int(self.get_argument('study_id')) # Get the arguments prep_template = self.get_argument('prep_template', None) sample_template = self.get_argument('sample_template', None) if prep_template and sample_template: raise HTTPError( 500, "You should provide either a sample template " "or a prep template, but not both") elif prep_template: # The prep template has been provided template = self._get_template(PrepTemplate, prep_template) back_button_path = ( "/study/description/%s?top_tab=raw_data_tab&sub_tab=%s" "&prep_tab=%s" % (study_id, template.raw_data, template.id)) elif sample_template: # The sample template has been provided template = self._get_template(SampleTemplate, sample_template) back_button_path = ("/study/description/%s" % study_id) else: # Neither a sample template or a prep template has been provided # Fail nicely raise HTTPError( 500, "You should provide either a sample template " "or a prep template") study = Study(template.study_id) # check whether or not the user has access to the requested information if not study.has_access(self.current_user): raise HTTPError( 403, "You do not have access to access this " "information.") df = dataframe_from_template(template) num_samples = df.shape[0] stats = stats_from_df(df) self.render('metadata_summary.html', study_title=study.title, stats=stats, num_samples=num_samples, back_button_path=back_button_path)
def get(self, arguments): study_id = int(self.get_argument('study_id')) # Get the arguments prep_template = self.get_argument('prep_template', None) sample_template = self.get_argument('sample_template', None) if prep_template and sample_template: raise HTTPError(500, "You should provide either a sample template " "or a prep template, but not both") elif prep_template: # The prep template has been provided template = self._get_template(PrepTemplate, prep_template) back_button_path = ( "/study/description/%s?top_tab=prep_template_tab&sub_tab=%s" % (study_id, template.id)) elif sample_template: # The sample template has been provided template = self._get_template(SampleTemplate, sample_template) back_button_path = ( "/study/description/%s" % study_id) else: # Neither a sample template or a prep template has been provided # Fail nicely raise HTTPError(500, "You should provide either a sample template " "or a prep template") study = Study(template.study_id) # check whether or not the user has access to the requested information if not study.has_access(self.current_user): raise HTTPError(403, "You do not have access to access this " "information.") df = template.to_dataframe() num_samples = df.shape[0] stats = stats_from_df(df) self.render('metadata_summary.html', study_title=study.title, stats=stats, num_samples=num_samples, back_button_path=back_button_path)
def test_stats_from_df(self): obs = stats_from_df(SampleTemplate(1).to_dataframe()) for k in obs: self.assertItemsEqual(obs[k], SUMMARY_STATS[k])
def test_stats_from_df(self): obs = stats_from_df(dataframe_from_template(SampleTemplate(1))) for k in obs: self.assertEqual(obs[k], SUMMARY_STATS[k])