def study_get_req(study_id, user_id): """Returns information available for the given study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User requesting the info Returns ------- dict Data types information in the form {'status': status, 'message': message, 'info': dict of objects status can be success, warning, or error depending on result message has the warnings or errors info contains study information seperated by data type, in the form {col_name: value, ...} with value being a string, int, or list of strings or ints """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(study_id) study_info = study.info # Add needed info that is not part of the initial info pull study_info['publications'] = study.publications 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 pi = study_info['principal_investigator'] study_info['principal_investigator'] = { 'name': pi.name, 'email': pi.email, 'affiliation': pi.affiliation} lab_person = study_info['lab_person'] if lab_person: study_info['lab_person'] = { 'name': lab_person.name, 'email': lab_person.email, 'affiliation': lab_person.affiliation} samples = study.sample_template study_info['num_samples'] = 0 if samples is None else len(list(samples)) study_info['owner'] = study.owner.id return {'status': 'success', 'message': '', 'study_info': study_info, 'editable': study.can_edit(User(user_id))}
def study_prep_get_req(study_id, user_id): """Gives a summary of each prep template attached to the study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User id requesting the prep templates Returns ------- dict of list of dict prep template information seperated by data type, in the form {data_type: [{prep 1 info dict}, ....], ...} """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(int(study_id)) prep_info = defaultdict(list) editable = study.can_edit(User(user_id)) for dtype in study.data_types: for prep in study.prep_templates(dtype): if prep.status != 'public' and not editable: continue start_artifact = prep.artifact info = { 'name': 'PREP %d NAME' % prep.id, 'id': prep.id, 'status': prep.status, } if start_artifact is not None: youngest_artifact = prep.artifact.youngest_artifact info['start_artifact'] = start_artifact.artifact_type info['start_artifact_id'] = start_artifact.id info['youngest_artifact'] = '%s - %s' % ( youngest_artifact.name, youngest_artifact.artifact_type) info['ebi_experiment'] = bool( [v for _, v in viewitems(prep.ebi_experiment_accessions) if v is not None]) else: info['start_artifact'] = None info['start_artifact_id'] = None info['youngest_artifact'] = None info['ebi_experiment'] = False prep_info[dtype].append(info) return {'status': 'success', 'message': '', 'info': prep_info}
def study_get_req(study_id, user_id): """Returns information available for the given study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User requesting the info Returns ------- dict Data types information in the form {'status': status, 'message': message, 'info': dict of objects status can be success, warning, or error depending on result message has the warnings or errors info contains study information seperated by data type, in the form {col_name: value, ...} with value being a string, int, or list of strings or ints """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(study_id) study_info = study.info # Add needed info that is not part of the initial info pull study_info['publication_doi'] = [] study_info['publication_pid'] = [] for pub, is_doi in study.publications: if is_doi: study_info['publication_doi'].append(pub) else: study_info['publication_pid'].append(pub) 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 study_info['public_raw_download'] = study.public_raw_download study_info['notes'] = study.notes # Clean up StudyPerson objects to string for display pi = study_info['principal_investigator'] study_info['principal_investigator'] = { 'name': pi.name, 'email': pi.email, 'affiliation': pi.affiliation } lab_person = study_info['lab_person'] if lab_person: study_info['lab_person'] = { 'name': lab_person.name, 'email': lab_person.email, 'affiliation': lab_person.affiliation } samples = study.sample_template study_info['num_samples'] = 0 if samples is None else len(list(samples)) study_info['owner'] = study.owner.id # Study.has_access no_public=True, will return True only if the user_id is # the owner of the study or if the study is shared with the user_id; this # with study.public_raw_download will define has_access_to_raw_data study_info['has_access_to_raw_data'] = study.has_access( User(user_id), True) or study.public_raw_download study_info['show_biom_download_button'] = 'BIOM' in [ a.artifact_type for a in study.artifacts() ] study_info['show_raw_download_button'] = any( [True for pt in study.prep_templates() if pt.artifact is not None]) # getting study processing status from redis processing = False study_info['level'] = '' study_info['message'] = '' job_info = r_client.get(STUDY_KEY_FORMAT % study_id) if job_info: job_info = defaultdict(lambda: '', loads(job_info)) job_id = job_info['job_id'] job = ProcessingJob(job_id) job_status = job.status processing = job_status not in ('success', 'error') if processing: study_info['level'] = 'info' study_info['message'] = 'This study is currently being processed' elif job_status == 'error': study_info['level'] = 'danger' study_info['message'] = job.log.msg.replace('\n', '</br>') else: study_info['level'] = job_info['alert_type'] study_info['message'] = job_info['alert_msg'].replace( '\n', '</br>') return { 'status': 'success', 'message': '', 'study_info': study_info, 'editable': study.can_edit(User(user_id)) }
def study_get_req(study_id, user_id): """Returns information available for the given study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User requesting the info Returns ------- dict Data types information in the form {'status': status, 'message': message, 'info': dict of objects status can be success, warning, or error depending on result message has the warnings or errors info contains study information seperated by data type, in the form {col_name: value, ...} with value being a string, int, or list of strings or ints """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(study_id) study_info = study.info # Add needed info that is not part of the initial info pull study_info['publication_doi'] = [] study_info['publication_pid'] = [] for pub, is_doi in study.publications: if is_doi: study_info['publication_doi'].append(pub) else: study_info['publication_pid'].append(pub) 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 pi = study_info['principal_investigator'] study_info['principal_investigator'] = { 'name': pi.name, 'email': pi.email, 'affiliation': pi.affiliation} lab_person = study_info['lab_person'] if lab_person: study_info['lab_person'] = { 'name': lab_person.name, 'email': lab_person.email, 'affiliation': lab_person.affiliation} samples = study.sample_template study_info['num_samples'] = 0 if samples is None else len(list(samples)) study_info['owner'] = study.owner.id # Study.has_access no_public=True, will return True only if the user_id is # the owner of the study or if the study is shared with the user_id study_info['has_access_to_raw_data'] = study.has_access( User(user_id), True) study_info['show_biom_download_button'] = 'BIOM' in [ a.artifact_type for a in study.artifacts()] study_info['show_raw_download_button'] = any([ True for pt in study.prep_templates() if pt.artifact is not None]) # getting study processing status from redis processing = False study_info['level'] = '' study_info['message'] = '' job_info = r_client.get(STUDY_KEY_FORMAT % study_id) if job_info: job_info = defaultdict(lambda: '', loads(job_info)) job_id = job_info['job_id'] job = ProcessingJob(job_id) job_status = job.status processing = job_status not in ('success', 'error') if processing: study_info['level'] = 'info' study_info['message'] = 'This study is currently being processed' elif job_status == 'error': study_info['level'] = 'danger' study_info['message'] = job.log.msg.replace('\n', '</br>') else: study_info['level'] = job_info['alert_type'] study_info['message'] = job_info['alert_msg'].replace( '\n', '</br>') return {'status': 'success', 'message': '', 'study_info': study_info, 'editable': study.can_edit(User(user_id))}
def study_get_req(study_id, user_id): """Returns information available for the given study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User requesting the info Returns ------- dict Data types information in the form {'status': status, 'message': message, 'info': dict of objects status can be success, warning, or error depending on result message has the warnings or errors info contains study information seperated by data type, in the form {col_name: value, ...} with value being a string, int, or list of strings or ints """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(study_id) study_info = study.info # Add needed info that is not part of the initial info pull study_info['publication_doi'] = [] study_info['publication_pid'] = [] for pub, is_doi in study.publications: if is_doi: study_info['publication_doi'].append(pub) else: study_info['publication_pid'].append(pub) 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 pi = study_info['principal_investigator'] study_info['principal_investigator'] = { 'name': pi.name, 'email': pi.email, 'affiliation': pi.affiliation} lab_person = study_info['lab_person'] if lab_person: study_info['lab_person'] = { 'name': lab_person.name, 'email': lab_person.email, 'affiliation': lab_person.affiliation} samples = study.sample_template study_info['num_samples'] = 0 if samples is None else len(list(samples)) study_info['owner'] = study.owner.id # Study.has_access no_public=True, will return True only if the user_id is # the owner of the study or if the study is shared with the user_id study_info['has_access_to_raw_data'] = study.has_access( User(user_id), True) study_info['show_biom_download_button'] = 'BIOM' in [ a.artifact_type for a in study.artifacts()] study_info['show_raw_download_button'] = any([ True for pt in study.prep_templates() if pt.artifact is not None]) return {'status': 'success', 'message': '', 'study_info': study_info, 'editable': study.can_edit(User(user_id))}
def study_prep_get_req(study_id, user_id): """Gives a summary of each prep template attached to the study Parameters ---------- study_id : int Study id to get prep template info for user_id : str User id requesting the prep templates Returns ------- dict of list of dict prep template information seperated by data type, in the form {data_type: [{prep 1 info dict}, ....], ...} """ access_error = check_access(study_id, user_id) if access_error: return access_error # Can only pass ids over API, so need to instantiate object study = Study(int(study_id)) prep_info = defaultdict(list) editable = study.can_edit(User(user_id)) for dtype in study.data_types: dtype_infos = list() for prep in study.prep_templates(dtype): if prep.status != 'public' and not editable: continue start_artifact = prep.artifact info = { 'name': prep.name, 'id': prep.id, 'status': prep.status, 'total_samples': len(prep), 'creation_timestamp': prep.creation_timestamp, 'modification_timestamp': prep.modification_timestamp } if start_artifact is not None: youngest_artifact = prep.artifact.youngest_artifact info['start_artifact'] = start_artifact.artifact_type info['start_artifact_id'] = start_artifact.id info['num_artifact_children'] = len(start_artifact.children) info['youngest_artifact_name'] = youngest_artifact.name info['youngest_artifact_type'] = \ youngest_artifact.artifact_type info['youngest_artifact'] = '%s - %s' % ( youngest_artifact.name, youngest_artifact.artifact_type) info['ebi_experiment'] = len([ v for _, v in prep.ebi_experiment_accessions.items() if v is not None ]) else: info['start_artifact'] = None info['start_artifact_id'] = None info['youngest_artifact'] = None info['num_artifact_children'] = 0 info['youngest_artifact_name'] = None info['youngest_artifact_type'] = None info['ebi_experiment'] = 0 dtype_infos.append(info) # default sort is in ascending order of creation timestamp sorted_info = sorted(dtype_infos, key=lambda k: k['creation_timestamp'], reverse=False) prep_info[dtype] = sorted_info return {'status': 'success', 'message': '', 'info': prep_info}