def get(self): study_id = self.get_argument('study_id') study = to_int(study_id) res = study_get_req(study, self.current_user.id) study_info = res['study_info'] pdoi = [doi_linkifier([p]) for p in study_info['publication_doi']] ppid = [pubmed_linkifier([p]) for p in study_info['publication_pid']] email = '<a href="mailto:{email}">{name} ({affiliation})</a>' pi = email.format(**study_info['principal_investigator']) if study_info['lab_person']: contact = email.format(**study_info['lab_person']) else: contact = None share_access = (self.current_user.id in study_info['shared_with'] or self.current_user.id == study_info['owner']) ebi_info = study_info['ebi_submission_status'] ebi_study_accession = study_info['ebi_study_accession'] if ebi_study_accession: links = ''.join([ EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',') ]) ebi_info = '%s (%s)' % (links, study_info['ebi_submission_status']) self.render('study_ajax/base_info.html', study_info=study_info, publications=', '.join(pdoi + ppid), pi=pi, contact=contact, editable=res['editable'], share_access=share_access, ebi_info=ebi_info)
def get(self): study_id = self.get_argument('study_id') study = to_int(study_id) res = study_get_req(study, self.current_user.id) study_info = res['study_info'] pdoi = [doi_linkifier([p]) for p in study_info['publication_doi']] ppid = [pubmed_linkifier([p]) for p in study_info['publication_pid']] email = '<a href="mailto:{email}">{name} ({affiliation})</a>' pi = email.format(**study_info['principal_investigator']) if study_info['lab_person']: contact = email.format(**study_info['lab_person']) else: contact = None share_access = (self.current_user.id in study_info['shared_with'] or self.current_user.id == study_info['owner']) ebi_info = study_info['ebi_submission_status'] ebi_study_accession = study_info['ebi_study_accession'] if ebi_study_accession: links = ''.join([EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',')]) ebi_info = '%s (%s)' % (links, study_info['ebi_submission_status']) self.render('study_ajax/base_info.html', study_info=study_info, publications=', '.join(pdoi + ppid), pi=pi, contact=contact, editable=res['editable'], share_access=share_access, ebi_info=ebi_info)
def render(self, study): study_info = study.info id = study.id abstract = study_info['study_abstract'] description = study_info['study_description'] pmids = ", ".join([pubmed_linkifier([pmid]) for pmid in study.pmids]) princ_inv = StudyPerson(study_info['principal_investigator_id']) pi_link = study_person_linkifier((princ_inv.email, princ_inv.name)) number_samples_promised = study_info['number_samples_promised'] number_samples_collected = study_info['number_samples_collected'] metadata_complete = study_info['metadata_complete'] data_types = sorted(viewitems(get_data_types()), key=itemgetter(1)) # Retrieve the files from the uploads folder, so the user can choose # the sample template of the study. Filter them to only include the # ones that ends with 'txt' or 'tsv'. files = [f for _, f in get_files_from_uploads_folders(str(study.id)) if f.endswith(('txt', 'tsv'))] # If the sample template exists, retrieve all its filepaths if SampleTemplate.exists(study.id): sample_templates = SampleTemplate(study.id).get_filepaths() else: # If the sample template does not exist, just pass an empty list sample_templates = [] # Check if the request came from a local source is_local_request = is_localhost(self.request.headers['host']) # The user can choose the sample template only if the study is # sandboxed or the current user is an admin show_select_sample = ( study.status == 'sandbox' or self.current_user.level == 'admin') # Ebi information ebi_status = study.ebi_submission_status ebi_accession = study.ebi_study_accession if ebi_accession: ebi_accession = (EBI_LINKIFIER.format(ebi_accession)) return self.render_string( "study_description_templates/study_information_tab.html", abstract=abstract, description=description, id=id, pmids=pmids, principal_investigator=pi_link, number_samples_promised=number_samples_promised, number_samples_collected=number_samples_collected, metadata_complete=metadata_complete, show_select_sample=show_select_sample, files=files, study_id=study.id, sample_templates=sample_templates, is_local_request=is_local_request, data_types=data_types, ebi_status=ebi_status, ebi_accession=ebi_accession)
def get(self, ignore): user = self.get_argument('user') visibility = self.get_argument('visibility') echo = int(self.get_argument('sEcho')) if user != self.current_user.id: raise HTTPError(403, reason='Unauthorized search!') if visibility not in ['user', 'public']: raise HTTPError(400, reason='Not a valid visibility') info = generate_study_list(self.current_user, visibility) # linkifying data len_info = len(info) for i in range(len_info): info[i]['shared'] = ", ".join([ study_person_linkifier(element) for element in info[i]['shared'] ]) ppid = [pubmed_linkifier([p]) for p in info[i]['publication_pid']] pdoi = [doi_linkifier([p]) for p in info[i]['publication_doi']] del info[i]['publication_pid'] del info[i]['publication_doi'] info[i]['pubs'] = ', '.join(ppid + pdoi) info[i]['pi'] = study_person_linkifier(info[i]['pi']) info[i]['ebi_info'] = info[i]['ebi_submission_status'] ebi_study_accession = info[i]['ebi_study_accession'] if ebi_study_accession: info[i]['ebi_info'] = '%s (%s)' % (''.join([ EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',') ]), info[i]['ebi_submission_status']) # build the table json results = { "sEcho": echo, "iTotalRecords": len_info, "iTotalDisplayRecords": len_info, "aaData": info } # return the json in compact form to save transmit size self.write(dumps(results, separators=(',', ':')))
def get(self, ignore): user = self.get_argument('user') visibility = self.get_argument('visibility') echo = int(self.get_argument('sEcho')) if user != self.current_user.id: raise HTTPError(403, reason='Unauthorized search!') if visibility not in ['user', 'public']: raise HTTPError(400, reason='Not a valid visibility') info = generate_study_list(self.current_user, visibility) # linkifying data len_info = len(info) for i in range(len_info): info[i]['shared'] = ", ".join([study_person_linkifier(element) for element in info[i]['shared']]) ppid = [pubmed_linkifier([p]) for p in info[i]['publication_pid']] pdoi = [doi_linkifier([p]) for p in info[i]['publication_doi']] del info[i]['publication_pid'] del info[i]['publication_doi'] info[i]['pubs'] = ', '.join(ppid + pdoi) info[i]['pi'] = study_person_linkifier(info[i]['pi']) info[i]['ebi_info'] = info[i]['ebi_submission_status'] ebi_study_accession = info[i]['ebi_study_accession'] if ebi_study_accession: info[i]['ebi_info'] = '%s (%s)' % ( ''.join([EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',')]), info[i]['ebi_submission_status']) # build the table json results = { "sEcho": echo, "iTotalRecords": len_info, "iTotalDisplayRecords": len_info, "aaData": info } # return the json in compact form to save transmit size self.write(dumps(results, separators=(',', ':')))
def get(self, ignore): user = self.get_argument('user') query = self.get_argument('query') search_type = self.get_argument('search_type') echo = int(self.get_argument('sEcho')) if user != self.current_user.id: raise HTTPError(403, 'Unauthorized search!') if search_type not in ['user', 'public']: raise HTTPError(400, 'Not a valid search type') if query: # Search for samples matching the query search = QiitaStudySearch() try: search(query, self.current_user) study_proc, proc_samples, _ = search.filter_by_processed_data() except ParseException: self.clear() self.set_status(400) self.write('Malformed search query. Please read "search help" ' 'and try again.') return except QiitaDBIncompatibleDatatypeError as e: self.clear() self.set_status(400) searchmsg = ''.join(e) self.write(searchmsg) return except Exception as e: # catch any other error as generic server error self.clear() self.set_status(500) self.write("Server error during search. Please try again " "later") LogEntry.create('Runtime', str(e), info={'User': self.current_user.id, 'query': query}) return else: study_proc = proc_samples = None info = _build_study_info(self.current_user, search_type, study_proc, proc_samples) # linkifying data len_info = len(info) for i in range(len_info): info[i]['shared'] = ", ".join([study_person_linkifier(element) for element in info[i]['shared']]) ppid = [pubmed_linkifier([p]) for p in info[i]['publication_pid']] pdoi = [doi_linkifier([p]) for p in info[i]['publication_doi']] del info[i]['publication_pid'] del info[i]['publication_doi'] info[i]['pubs'] = ', '.join(ppid + pdoi) info[i]['pi'] = study_person_linkifier(info[i]['pi']) info[i]['ebi_info'] = info[i]['ebi_submission_status'] ebi_study_accession = info[i]['ebi_study_accession'] if ebi_study_accession: info[i]['ebi_info'] = '%s (%s)' % ( ''.join([EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',')]), info[i]['ebi_submission_status']) # build the table json results = { "sEcho": echo, "iTotalRecords": len_info, "iTotalDisplayRecords": len_info, "aaData": info } # return the json in compact form to save transmit size self.write(dumps(results, separators=(',', ':')))
def render(self, study): study_info = study.info id = study.id abstract = study_info['study_abstract'] description = study_info['study_description'] publications = [] for doi, pmid in study.publications: if doi is not None: publications.append(doi_linkifier([doi])) if pmid is not None: publications.append(pubmed_linkifier([pmid])) publications = ", ".join(publications) princ_inv = StudyPerson(study_info['principal_investigator_id']) pi_link = study_person_linkifier((princ_inv.email, princ_inv.name)) number_samples_promised = study_info['number_samples_promised'] number_samples_collected = study_info['number_samples_collected'] metadata_complete = study_info['metadata_complete'] data_types = sorted(viewitems(get_data_types()), key=itemgetter(1)) # Retrieve the files from the uploads folder, so the user can choose # the sample template of the study. Filter them to only include the # ones that ends with 'txt' or 'tsv'. files = [ f for _, f in get_files_from_uploads_folders(str(study.id)) if f.endswith(('txt', 'tsv')) ] # If the sample template exists, retrieve all its filepaths if SampleTemplate.exists(study.id): sample_templates = SampleTemplate(study.id).get_filepaths() else: # If the sample template does not exist, just pass an empty list sample_templates = [] # Check if the request came from a local source is_local_request = is_localhost(self.request.headers['host']) # The user can choose the sample template only if the study is # sandboxed or the current user is an admin show_select_sample = (study.status == 'sandbox' or self.current_user.level == 'admin') # EBI information ebi_status = study.ebi_submission_status ebi_accession = study.ebi_study_accession if ebi_accession: ebi_accession = (EBI_LINKIFIER.format(ebi_accession)) return self.render_string( "study_description_templates/study_information_tab.html", abstract=abstract, description=description, id=id, publications=publications, principal_investigator=pi_link, number_samples_promised=number_samples_promised, number_samples_collected=number_samples_collected, metadata_complete=metadata_complete, show_select_sample=show_select_sample, files=files, study_id=study.id, sample_templates=sample_templates, is_local_request=is_local_request, data_types=data_types, ebi_status=ebi_status, ebi_accession=ebi_accession)
def get(self, ignore): user = self.get_argument('user') query = self.get_argument('query') search_type = self.get_argument('search_type') echo = int(self.get_argument('sEcho')) if user != self.current_user.id: raise HTTPError(403, 'Unauthorized search!') if search_type not in ['user', 'public']: raise HTTPError(400, 'Not a valid search type') if query: # Search for samples matching the query search = QiitaStudySearch() try: search(query, self.current_user) study_proc, proc_samples, _ = search.filter_by_processed_data() except ParseException: self.clear() self.set_status(400) self.write('Malformed search query. Please read "search help" ' 'and try again.') return except QiitaDBIncompatibleDatatypeError as e: self.clear() self.set_status(400) searchmsg = ''.join(e) self.write(searchmsg) return except Exception as e: # catch any other error as generic server error self.clear() self.set_status(500) self.write("Server error during search. Please try again " "later") LogEntry.create('Runtime', str(e), info={ 'User': self.current_user.id, 'query': query }) return else: study_proc = proc_samples = None info = _build_study_info(self.current_user, search_type, study_proc, proc_samples) # linkifying data len_info = len(info) for i in range(len_info): info[i]['shared'] = ", ".join([ study_person_linkifier(element) for element in info[i]['shared'] ]) ppid = [pubmed_linkifier([p]) for p in info[i]['publication_pid']] pdoi = [doi_linkifier([p]) for p in info[i]['publication_doi']] del info[i]['publication_pid'] del info[i]['publication_doi'] info[i]['pubs'] = ', '.join(ppid + pdoi) info[i]['pi'] = study_person_linkifier(info[i]['pi']) info[i]['ebi_info'] = info[i]['ebi_submission_status'] ebi_study_accession = info[i]['ebi_study_accession'] if ebi_study_accession: info[i]['ebi_info'] = '%s (%s)' % (''.join([ EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',') ]), info[i]['ebi_submission_status']) # build the table json results = { "sEcho": echo, "iTotalRecords": len_info, "iTotalDisplayRecords": len_info, "aaData": info } # return the json in compact form to save transmit size self.write(dumps(results, separators=(',', ':')))
info[i]['shared'] = ", ".join([study_person_linkifier(element) for element in info[i]['shared']]) ppid = [pubmed_linkifier([p]) for p in info[i]['publication_pid']] pdoi = [doi_linkifier([p]) for p in info[i]['publication_doi']] del info[i]['publication_pid'] del info[i]['publication_doi'] info[i]['pubs'] = ', '.join(ppid + pdoi) info[i]['pi'] = study_person_linkifier(info[i]['pi']) info[i]['ebi_info'] = info[i]['ebi_submission_status'] ebi_study_accession = info[i]['ebi_study_accession'] if ebi_study_accession: info[i]['ebi_info'] = '%s (%s)' % ( ''.join([EBI_LINKIFIER.format(a) for a in ebi_study_accession.split(',')]), info[i]['ebi_submission_status']) >>>>>>> 405cbef0c9f71c620da95a0c1ba6c7d3d588b3ed # build the table json results = { "sEcho": echo, "iTotalRecords": len(info), "iTotalDisplayRecords": len(info), "aaData": info } # return the json in compact form to save transmit size self.write(dumps(results, separators=(',', ':')))
def render(self, study_id, preprocessed_data): user = self.current_user ppd_id = preprocessed_data.id vamps_status = preprocessed_data.is_submitted_to_vamps filepaths = preprocessed_data.filepaths is_local_request = is_localhost(self.request.headers['host']) show_ebi_btn = user.level == "admin" processing_status, processing_status_msg = \ get_artifact_processing_status(preprocessed_data) processed_data = sorted([pd.id for pd in preprocessed_data.children]) # Get all the ENA terms for the investigation type ontology = Ontology(convert_to_id('ENA', 'ontology')) # make "Other" show at the bottom of the drop down menu ena_terms = [] for v in sorted(ontology.terms): if v != 'Other': ena_terms.append('<option value="%s">%s</option>' % (v, v)) ena_terms.append('<option value="Other">Other</option>') # New Type is for users to add a new user-defined investigation type user_defined_terms = ontology.user_defined_terms + ['New Type'] # ppd can only have 1 prep template prep_template = preprocessed_data.prep_templates[0] # this block might seem wrong but is here due to a possible # pathological case that we used to have in the system: preprocessed # data without valid prep_templates prep_templates = preprocessed_data.prep_templates if len(prep_templates) == 1: prep_template_id = prep_template.id raw_data_id = prep_template.artifact.id inv_type = prep_template.investigation_type or "None selected" else: prep_template_id = None raw_data_id = None inv_type = "None Selected" process_params = { param.id: (generate_param_str(param), param.name) for param in Command(3).default_parameter_sets } # We just need to provide an ID for the default parameters, # so we can initialize the interface default_params = min(process_params.keys()) ebi_link = None if preprocessed_data.is_submitted_to_ebi: ebi_link = EBI_LINKIFIER.format( Study(study_id).ebi_study_accession) return self.render_string( "study_description_templates/preprocessed_data_info_tab.html", ppd_id=ppd_id, show_ebi_btn=show_ebi_btn, filepaths=filepaths, is_local_request=is_local_request, prep_template_id=prep_template_id, raw_data_id=raw_data_id, inv_type=inv_type, ena_terms=ena_terms, vamps_status=vamps_status, user_defined_terms=user_defined_terms, process_params=process_params, default_params=default_params, study_id=preprocessed_data.study.id, processing_status=processing_status, processing_status_msg=processing_status_msg, processed_data=processed_data, ebi_link=ebi_link)
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 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", 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, ebi_link=ebi_link)
def get(self): study_id = self.get_argument("study_id", None) artifact_id = self.get_argument("artifact_id", None) if study_id is None and artifact_id is None: raise HTTPError( 422, reason='You need to specify study_id or artifact_id') self.finish() elif study_id is not None: try: study = Study(int(study_id)) except QiitaDBUnknownIDError: raise HTTPError(422, reason="Study %s doesn't exist" % study_id) self.finish() artifact_ids = [ a.id for a in study.artifacts() if a.visibility == 'public' ] else: try: artifact = Artifact(int(artifact_id)) except QiitaDBUnknownIDError: raise HTTPError(422, reason="Artifact %s doesn't exist" % artifact_id) self.finish() if artifact.visibility != 'public': raise HTTPError(422, reason="Artifact %s is not public" % artifact_id) self.finish() study = artifact.study if study is None: raise HTTPError(422, reason="Artifact %s doesn't belong to " "a study" % artifact_id) self.finish() artifact_ids = [artifact.id] if study.status != 'public': raise HTTPError(422, reason='Not a public study') self.finish() study_info = study.info study_info['study_id'] = study.id study_info['study_title'] = study.title study_info['shared_with'] = [s.id for s in study.shared_with] study_info['status'] = study.status study_info['ebi_study_accession'] = study.ebi_study_accession study_info['ebi_submission_status'] = study.ebi_submission_status # Clean up StudyPerson objects to string for display email = '<a href="mailto:{email}">{name} ({affiliation})</a>' pi = study.info['principal_investigator'] study_info['principal_investigator'] = email.format( **{ 'name': pi.name, 'email': pi.email, 'affiliation': pi.affiliation }) study_info['owner'] = study.owner.id # Add needed info that is not part of the initial info pull study_info['publications'] = [] for pub, is_doi in study.publications: if is_doi: study_info['publications'].append(pubmed_linkifier([pub])) else: study_info['publications'].append(doi_linkifier([pub])) study_info['publications'] = ', '.join(study_info['publications']) if study_info['ebi_study_accession']: links = ''.join([ EBI_LINKIFIER.format(a) for a in study_info['ebi_study_accession'].split(',') ]) study_info['ebi_study_accession'] = '%s (%s)' % ( links, study_info['ebi_submission_status']) self.render("public.html", study_info=study_info, artifacts_info=get_artifacts_information( artifact_ids, False))
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)
def render(self, study_id, preprocessed_data): user = self.current_user ppd_id = preprocessed_data.id vamps_status = preprocessed_data.is_submitted_to_vamps filepaths = preprocessed_data.filepaths is_local_request = is_localhost(self.request.headers['host']) show_ebi_btn = user.level == "admin" processing_status, processing_status_msg = \ get_artifact_processing_status(preprocessed_data) processed_data = sorted([pd.id for pd in preprocessed_data.children]) # Get all the ENA terms for the investigation type ontology = Ontology(convert_to_id('ENA', 'ontology')) # make "Other" show at the bottom of the drop down menu ena_terms = [] for v in sorted(ontology.terms): if v != 'Other': ena_terms.append('<option value="%s">%s</option>' % (v, v)) ena_terms.append('<option value="Other">Other</option>') # New Type is for users to add a new user-defined investigation type user_defined_terms = ontology.user_defined_terms + ['New Type'] # ppd can only have 1 prep template prep_template = preprocessed_data.prep_templates[0] # this block might seem wrong but is here due to a possible # pathological case that we used to have in the system: preprocessed # data without valid prep_templates prep_templates = preprocessed_data.prep_templates if len(prep_templates) == 1: prep_template_id = prep_template.id raw_data_id = prep_template.artifact.id inv_type = prep_template.investigation_type or "None selected" else: prep_template_id = None raw_data_id = None inv_type = "None Selected" process_params = {param.id: (generate_param_str(param), param.name) for param in Command(3).default_parameter_sets} # We just need to provide an ID for the default parameters, # so we can initialize the interface default_params = min(process_params.keys()) ebi_link = None if preprocessed_data.is_submitted_to_ebi: ebi_link = EBI_LINKIFIER.format( Study(study_id).ebi_study_accession) return self.render_string( "study_description_templates/preprocessed_data_info_tab.html", ppd_id=ppd_id, show_ebi_btn=show_ebi_btn, filepaths=filepaths, is_local_request=is_local_request, prep_template_id=prep_template_id, raw_data_id=raw_data_id, inv_type=inv_type, ena_terms=ena_terms, vamps_status=vamps_status, user_defined_terms=user_defined_terms, process_params=process_params, default_params=default_params, study_id=preprocessed_data.study.id, processing_status=processing_status, processing_status_msg=processing_status_msg, processed_data=processed_data, ebi_link=ebi_link)
def render(self, study_id, preprocessed_data): user = self.current_user ppd_id = preprocessed_data.id vamps_status = preprocessed_data.submitted_to_vamps_status() filepaths = preprocessed_data.get_filepaths() is_local_request = is_localhost(self.request.headers['host']) show_ebi_btn = user.level == "admin" processing_status = convert_text_html( preprocessed_data.processing_status) processed_data = sorted(preprocessed_data.processed_data) # Get all the ENA terms for the investigation type ontology = Ontology(convert_to_id('ENA', 'ontology')) # make "Other" show at the bottom of the drop down menu ena_terms = [] for v in sorted(ontology.terms): if v != 'Other': ena_terms.append('<option value="%s">%s</option>' % (v, v)) ena_terms.append('<option value="Other">Other</option>') # New Type is for users to add a new user-defined investigation type user_defined_terms = ontology.user_defined_terms + ['New Type'] if PrepTemplate.exists(preprocessed_data.prep_template): prep_template_id = preprocessed_data.prep_template prep_template = PrepTemplate(prep_template_id) raw_data_id = prep_template.raw_data inv_type = prep_template.investigation_type or "None Selected" else: prep_template_id = None raw_data_id = None inv_type = "None Selected" process_params = {param.id: (generate_param_str(param), param.name) for param in ProcessedSortmernaParams.iter()} # We just need to provide an ID for the default parameters, # so we can initialize the interface default_params = 1 ebi_link = None if preprocessed_data.is_submitted_to_ebi: ebi_link = EBI_LINKIFIER.format( Study(study_id).ebi_study_accession) return self.render_string( "study_description_templates/preprocessed_data_info_tab.html", ppd_id=ppd_id, show_ebi_btn=show_ebi_btn, filepaths=filepaths, is_local_request=is_local_request, prep_template_id=prep_template_id, raw_data_id=raw_data_id, inv_type=inv_type, ena_terms=ena_terms, vamps_status=vamps_status, user_defined_terms=user_defined_terms, process_params=process_params, default_params=default_params, study_id=preprocessed_data.study, processing_status=processing_status, processed_data=processed_data, ebi_link=ebi_link)