示例#1
0
    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)
示例#2
0
文件: base.py 项目: josenavas/QiiTa
    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)
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#7
0
    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=(',', ':')))
示例#8
0
    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=(',', ':')))
示例#9
0
    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=(',', ':')))
示例#10
0
    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=(',', ':')))
示例#11
0
                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)
                             for a in ebi_study_accession.split(',')]),
                    info[i]['ebi_submission_status'])
示例#12
0
文件: public.py 项目: mestaki/qiita
    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))
示例#13
0
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