def render(self, study, prep_template, full_access, ena_terms, user_defined_terms): user = self.current_user is_local_request = is_localhost(self.request.headers['host']) template_fps = [] qiime_fps = [] # Unfortunately, both the prep template and the qiime mapping files # have the sample type. The way to differentiate them is if we have # the substring 'qiime' in the basename for id_, fp in prep_template.get_filepaths(): if 'qiime' in basename(fp): qiime_fps.append( download_link_or_path( is_local_request, fp, id_, 'Qiime mapping')) else: template_fps.append( download_link_or_path( is_local_request, fp, id_, 'Prep template')) # Since get_filepaths returns the paths sorted from newest to oldest, # the first in both list is the latest one current_template_fp = template_fps[0] current_qiime_fp = qiime_fps[0] if len(template_fps) > 1: show_old_templates = True old_templates = template_fps[1:] else: show_old_templates = False old_templates = None if len(qiime_fps) > 1: show_old_qiime_fps = True old_qiime_fps = qiime_fps[1:] else: show_old_qiime_fps = False old_qiime_fps = None filetypes = sorted( ((ft, ft_id, fp_type_by_ft[ft]) for ft, ft_id in viewitems(get_filetypes())), key=itemgetter(1)) files = [f for _, f in get_files_from_uploads_folders(str(study.id))] other_studies_rd = sorted(viewitems( _get_accessible_raw_data(user))) # A prep template can be modified if its status is sandbox is_editable = prep_template.status == 'sandbox' raw_data_id = prep_template.raw_data preprocess_options = [] preprocessed_data = None show_preprocess_btn = True no_preprocess_msg = None if raw_data_id: rd = RawData(raw_data_id) rd_ft = rd.filetype # If the prep template has a raw data associated, it can be # preprocessed. Retrieve the pre-processing parameters if rd_ft in ('SFF', 'FASTA'): param_iter = Preprocessed454Params.iter() elif rd_ft == 'FASTQ': param_iter = [pip for pip in PreprocessedIlluminaParams.iter() if pip.values['barcode_type'] != 'not-barcoded'] elif rd_ft == 'per_sample_FASTQ': param_iter = [pip for pip in PreprocessedIlluminaParams.iter() if pip.values['barcode_type'] == 'not-barcoded'] else: raise NotImplementedError( "Pre-processing of %s files currently not supported." % rd_ft) preprocess_options = [] for param in param_iter: text = ("<b>%s:</b> %s" % (k, v) for k, v in viewitems(param.values)) preprocess_options.append((param.id, param.name, '<br>'.join(text))) preprocessed_data = prep_template.preprocessed_data # Check if the template have all the required columns for # preprocessing raw_data_files = rd.get_filepaths() if len(raw_data_files) == 0: show_preprocess_btn = False no_preprocess_msg = ( "Preprocessing disabled because there are no files " "linked with the Raw Data") else: if prep_template.data_type() in TARGET_GENE_DATA_TYPES: raw_forward_fps = [fp for _, fp, ftype in raw_data_files if ftype == 'raw_forward_seqs'] key = ('demultiplex_multiple' if len(raw_forward_fps) > 1 else 'demultiplex') missing_cols = prep_template.check_restrictions( [PREP_TEMPLATE_COLUMNS_TARGET_GENE[key]]) if rd_ft == 'per_sample_FASTQ': show_preprocess_btn = 'run_prefix' not in missing_cols else: show_preprocess_btn = len(missing_cols) == 0 no_preprocess_msg = None if not show_preprocess_btn: no_preprocess_msg = ( "Preprocessing disabled due to missing columns in " "the prep template: %s" % ', '.join(missing_cols)) preprocessing_status = prep_template.preprocessing_status return self.render_string( "study_description_templates/prep_template_info_tab.html", pt_id=prep_template.id, study_id=study.id, raw_data=raw_data_id, current_template_fp=current_template_fp, current_qiime_fp=current_qiime_fp, show_old_templates=show_old_templates, old_templates=old_templates, show_old_qiime_fps=show_old_qiime_fps, old_qiime_fps=old_qiime_fps, filetypes=filetypes, files=files, other_studies_rd=other_studies_rd, prep_template=prep_template, study=study, ena_terms=ena_terms, user_defined_terms=user_defined_terms, investigation_type=prep_template.investigation_type, is_editable=is_editable, preprocess_options=preprocess_options, preprocessed_data=preprocessed_data, preprocessing_status=preprocessing_status, show_preprocess_btn=show_preprocess_btn, no_preprocess_msg=no_preprocess_msg)
def render(self, study, prep_template, full_access, ena_terms, user_defined_terms): user = self.current_user is_local_request = is_localhost(self.request.headers['host']) template_fps = [] qiime_fps = [] # Unfortunately, both the prep template and the qiime mapping files # have the sample type. The way to differentiate them is if we have # the substring 'qiime' in the basename for id_, fp in prep_template.get_filepaths(): if 'qiime' in basename(fp): qiime_fps.append( download_link_or_path(is_local_request, fp, id_, 'Qiime mapping')) else: template_fps.append( download_link_or_path(is_local_request, fp, id_, 'Prep template')) # Since get_filepaths returns the paths sorted from newest to oldest, # the first in both list is the latest one current_template_fp = template_fps[0] current_qiime_fp = qiime_fps[0] if len(template_fps) > 1: show_old_templates = True old_templates = template_fps[1:] else: show_old_templates = False old_templates = None if len(qiime_fps) > 1: show_old_qiime_fps = True old_qiime_fps = qiime_fps[1:] else: show_old_qiime_fps = False old_qiime_fps = None filetypes = sorted(((ft, ft_id, fp_type_by_ft[ft]) for ft, ft_id in viewitems(get_artifact_types())), key=itemgetter(1)) files = [f for _, f in get_files_from_uploads_folders(str(study.id))] other_studies_rd = sorted(viewitems(_get_accessible_raw_data(user))) # A prep template can be modified if its status is sandbox is_editable = prep_template.status == 'sandbox' raw_data = prep_template.artifact preprocess_options = [] preprocessed_data = None show_preprocess_btn = True no_preprocess_msg = None preprocessing_status = 'Not processed' preprocessing_status_msg = "" if raw_data: raw_data_ft = raw_data.artifact_type # If the prep template has a raw data associated, it can be # preprocessed. Retrieve the pre-processing parameters # Hardcoding the command ids until the interface is refactored if raw_data_ft in ('SFF', 'FASTA'): param_iter = Command(2).default_parameter_sets elif raw_data_ft == 'FASTQ': param_iter = [ p for p in Command(1).default_parameter_sets if p.values['barcode_type'] != 'not-barcoded' ] elif raw_data_ft == 'per_sample_FASTQ': param_iter = [ p for p in Command(1).default_parameter_sets if p.values['barcode_type'] == 'not-barcoded' ] else: raise NotImplementedError( "Pre-processing of %s files currently not supported." % raw_data_ft) preprocess_options = [] for param in param_iter: text = ("<b>%s:</b> %s" % (k, v) for k, v in viewitems(param.values)) preprocess_options.append( (param.id, param.name, '<br>'.join(text))) preprocessed_data = raw_data.children # Check if the template have all the required columns for # preprocessing raw_data_files = raw_data.filepaths if len(raw_data_files) == 0: show_preprocess_btn = False no_preprocess_msg = ( "Preprocessing disabled because there are no files " "linked with the Raw Data") else: if prep_template.data_type() in TARGET_GENE_DATA_TYPES: raw_forward_fps = [ fp for _, fp, ftype in raw_data_files if ftype == 'raw_forward_seqs' ] key = ('demultiplex_multiple' if len(raw_forward_fps) > 1 else 'demultiplex') missing_cols = prep_template.check_restrictions( [PREP_TEMPLATE_COLUMNS_TARGET_GENE[key]]) if raw_data_ft == 'per_sample_FASTQ': show_preprocess_btn = 'run_prefix' not in missing_cols else: show_preprocess_btn = len(missing_cols) == 0 no_preprocess_msg = None if not show_preprocess_btn: no_preprocess_msg = ( "Preprocessing disabled due to missing columns in " "the prep template: %s" % ', '.join(missing_cols)) # Check the processing status preprocessing_status, preprocessing_status_msg = \ get_artifact_processing_status(raw_data) ebi_link = None if prep_template.is_submitted_to_ebi: ebi_link = EBI_LINKIFIER.format(study.ebi_study_accession) return self.render_string( "study_description_templates/prep_template_info_tab.html", raw_data=raw_data, current_template_fp=current_template_fp, current_qiime_fp=current_qiime_fp, show_old_templates=show_old_templates, old_templates=old_templates, show_old_qiime_fps=show_old_qiime_fps, old_qiime_fps=old_qiime_fps, filetypes=filetypes, files=files, other_studies_rd=other_studies_rd, prep_template=prep_template, study=study, ena_terms=ena_terms, user_defined_terms=user_defined_terms, investigation_type=prep_template.investigation_type, is_editable=is_editable, preprocess_options=preprocess_options, preprocessed_data=preprocessed_data, preprocessing_status=preprocessing_status, preprocessing_status_message=preprocessing_status_msg, show_preprocess_btn=show_preprocess_btn, no_preprocess_msg=no_preprocess_msg, ebi_link=ebi_link)