def _build_study_info(studytype, user=None): """builds list of namedtuples for study listings""" if studytype == "private": studylist = user.user_studies elif studytype == "shared": studylist = user.shared_studies elif studytype == "public": studylist = Study.get_by_status('public') else: raise IncompetentQiitaDeveloperError("Must use private, shared, " "or public!") StudyTuple = namedtuple( 'StudyInfo', 'id title meta_complete ' 'num_samples_collected shared num_raw_data pi ' 'pmids owner status') infolist = [] for s_id in studylist: study = Study(s_id) status = study.status # Just passing the email address as the name here, since # name is not a required field in qiita.qiita_user owner = study_person_linkifier((study.owner, study.owner)) info = study.info PI = StudyPerson(info['principal_investigator_id']) PI = study_person_linkifier((PI.email, PI.name)) pmids = ", ".join([pubmed_linkifier([pmid]) for pmid in study.pmids]) shared = _get_shared_links_for_study(study) infolist.append( StudyTuple(study.id, study.title, info["metadata_complete"], info["number_samples_collected"], shared, len(study.raw_data()), PI, pmids, owner, status)) return infolist
def _build_study_info(studytype, user=None): """builds list of namedtuples for study listings""" if studytype == "private": studylist = user.user_studies elif studytype == "shared": studylist = user.shared_studies elif studytype == "public": studylist = Study.get_by_status('public') else: raise IncompetentQiitaDeveloperError("Must use private, shared, " "or public!") StudyTuple = namedtuple('StudyInfo', 'id title meta_complete ' 'num_samples_collected shared num_raw_data pi ' 'pmids owner status') infolist = [] for s_id in studylist: study = Study(s_id) status = study.status # Just passing the email address as the name here, since # name is not a required field in qiita.qiita_user owner = study_person_linkifier((study.owner, study.owner)) info = study.info PI = StudyPerson(info['principal_investigator_id']) PI = study_person_linkifier((PI.email, PI.name)) pmids = ", ".join([pubmed_linkifier([pmid]) for pmid in study.pmids]) shared = _get_shared_links_for_study(study) infolist.append(StudyTuple(study.id, study.title, info["metadata_complete"], info["number_samples_collected"], shared, len(study.raw_data()), PI, pmids, owner, status)) return infolist
def _get_shared_links_for_study(study): shared = [] for person in study.shared_with: name = person.info['name'] email = person.email # Name is optional, so default to email if non existant if name: shared.append(study_person_linkifier((email, name))) else: shared.append(study_person_linkifier((email, email))) return ", ".join(shared)
def _get_shared_links_for_study(study): shared = [] for person in study.shared_with: name = person.info['name'] email = person.email # Name is optional, so default to email if non existant if name: shared.append(study_person_linkifier( (email, name))) else: shared.append(study_person_linkifier( (email, email))) return ", ".join(shared)
def _get_shared_links_for_study(study): shared = [] for person in study.shared_with: person = User(person) shared.append(study_person_linkifier( (person.email, person.info['name']))) return ", ".join(shared)
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 _build_single_study_info(study, info, study_proc, proc_samples): """Clean up and add to the study info for HTML purposes Parameters ---------- study : Study object The study to build information for info : dict Information from Study.get_info study_proc : dict of dict of lists Dictionary keyed on study_id that lists all processed data associated with that study. This list of processed data ids is keyed by data type proc_samples : dict of lists Dictionary keyed on proc_data_id that lists all samples associated with that processed data. Returns ------- dict info-information + extra information for the study, slightly HTML formatted """ PI = StudyPerson(info['principal_investigator_id']) status = study.status if info['publication_doi'] is not None: pmids = get_pubmed_ids_from_dois(info['publication_doi']).values() info['pmid'] = ", ".join([pubmed_linkifier([p]) for p in pmids]) info['publication_doi'] = ", ".join( [doi_linkifier([p]) for p in info['publication_doi']]) else: info['publication_doi'] = "" info['pmid'] = "" if info["number_samples_collected"] is None: info["number_samples_collected"] = 0 info["shared"] = _get_shared_links_for_study(study) # raw data is any artifact that is not Demultiplexed or BIOM info["num_raw_data"] = len([ a for a in study.artifacts() if a.artifact_type not in ['Demultiplexed', 'BIOM'] ]) info["status"] = status info["study_id"] = study.id info["pi"] = study_person_linkifier((PI.email, PI.name)) del info["principal_investigator_id"] del info["email"] # Build the proc data info list for the child row in datatable info["proc_data_info"] = [] for data_type, proc_datas in viewitems(study_proc[study.id]): info["proc_data_info"].extend([ _build_single_proc_data_info(pd_id, data_type, proc_samples[pd_id]) for pd_id in proc_datas ]) return info
def _build_single_study_info(study, info, study_proc, proc_samples): """Clean up and add to the study info for HTML purposes Parameters ---------- study : Study object The study to build information for info : dict Information from Study.get_info study_proc : dict of dict of lists Dictionary keyed on study_id that lists all processed data associated with that study. This list of processed data ids is keyed by data type proc_samples : dict of lists Dictionary keyed on proc_data_id that lists all samples associated with that processed data. Returns ------- dict info-information + extra information for the study, slightly HTML formatted """ PI = StudyPerson(info['principal_investigator_id']) status = study.status if info['publication_doi'] is not None: pmids = get_pubmed_ids_from_dois(info['publication_doi']).values() info['pmid'] = ", ".join([pubmed_linkifier([p]) for p in pmids]) info['publication_doi'] = ", ".join([doi_linkifier([p]) for p in info['publication_doi']]) else: info['publication_doi'] = "" info['pmid'] = "" if info["number_samples_collected"] is None: info["number_samples_collected"] = 0 info["shared"] = _get_shared_links_for_study(study) # raw data is any artifact that is not Demultiplexed or BIOM info["num_raw_data"] = len([a for a in study.artifacts() if a.artifact_type not in ['Demultiplexed', 'BIOM']]) info["status"] = status info["study_id"] = study.id info["pi"] = study_person_linkifier((PI.email, PI.name)) del info["principal_investigator_id"] del info["email"] # Build the proc data info list for the child row in datatable info["proc_data_info"] = [] for data_type, proc_datas in viewitems(study_proc[study.id]): info["proc_data_info"].extend([ _build_single_proc_data_info(pd_id, data_type, proc_samples[pd_id]) for pd_id in proc_datas]) return info
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 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=(',', ':')))
LogEntry.create('Runtime', str(e), info={'User': self.current_user.id, 'query': query}) return else: study_proc = proc_samples = None <<<<<<< HEAD info = _build_study_info(self.current_user, study_proc=study_proc, proc_samples=proc_samples) ======= 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)
def _build_study_info(user, results=None): """builds list of dicts for studies table, with all html formatted""" # get list of studies for table study_list = user.user_studies.union( Study.get_by_status('public')).union(user.shared_studies) if results is not None: study_list = study_list.intersection(results) if not study_list: # No studies left so no need to continue return [] # get info for the studies cols = ['study_id', 'email', 'principal_investigator_id', 'pmid', 'study_title', 'metadata_complete', 'number_samples_collected', 'study_abstract'] study_info = Study.get_info(study_list, cols) infolist = [] for row, info in enumerate(study_info): study = Study(info['study_id']) status = study.status # Just passing the email address as the name here, since # name is not a required field in qiita.qiita_user PI = StudyPerson(info['principal_investigator_id']) PI = study_person_linkifier((PI.email, PI.name)) if info['pmid'] is not None: pmids = ", ".join([pubmed_linkifier([p]) for p in info['pmid']]) else: pmids = "" if info["number_samples_collected"] is None: info["number_samples_collected"] = "0" shared = _get_shared_links_for_study(study) meta_complete_glyph = "ok" if info["metadata_complete"] else "remove" # build the HTML elements needed for table cell title = ("<a href='#' data-toggle='modal' " "data-target='#study-abstract-modal' " "onclick='fillAbstract(\"studies-table\", {0})'>" "<span class='glyphicon glyphicon-file' " "aria-hidden='true'></span></a> | " "<a href='/study/description/{1}' " "id='study{0}-title'>{2}</a>").format( str(row), str(study.id), info["study_title"]) meta_complete = "<span class='glyphicon glyphicon-%s'></span>" % \ meta_complete_glyph if status == 'public': shared = "Not Available" else: shared = ("<span id='shared_html_{0}'>{1}</span><br/>" "<a class='btn btn-primary btn-xs' data-toggle='modal' " "data-target='#share-study-modal-view' " "onclick='modify_sharing({0});'>Modify</a>".format( study.id, shared)) infolist.append({ "checkbox": "<input type='checkbox' value='%d' />" % study.id, "id": study.id, "title": title, "meta_complete": meta_complete, "num_samples": info["number_samples_collected"], "shared": shared, "num_raw_data": len(study.raw_data()), "pi": PI, "pmid": pmids, "status": status, "abstract": info["study_abstract"] }) return infolist