当前位置: 首页>>代码示例>>Python>>正文


Python Study.processed_data方法代码示例

本文整理汇总了Python中qiita_db.study.Study.processed_data方法的典型用法代码示例。如果您正苦于以下问题:Python Study.processed_data方法的具体用法?Python Study.processed_data怎么用?Python Study.processed_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qiita_db.study.Study的用法示例。


在下文中一共展示了Study.processed_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filter_by_processed_data

# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import processed_data [as 别名]
    def filter_by_processed_data(self, datatypes=None):
        """Filters results to what is available in each processed data

        Parameters
        ----------
        datatypes : list of str, optional
            Datatypes to selectively return. Default all datatypes available

        Returns
        -------
        study_proc_ids : dict of dicts of lists
            Processed data ids with samples for each study, in the format
            {study_id: {datatype: [proc_id, proc_id, ...], ...}, ...}
        proc_data_samples : dict of lists
            Samples available in each processed data id, in the format
            {proc_data_id: [samp_id1, samp_id2, ...], ...}
        samples_meta : dict of pandas DataFrames
            metadata for the found samples, keyed by study. Pandas indexed on
            sample_id, column headers are the metadata categories searched
            over
        """
        with TRN:
            if datatypes is not None:
                # convert to set for easy lookups
                datatypes = set(datatypes)
            study_proc_ids = {}
            proc_data_samples = {}
            samples_meta = {}
            headers = {c: val for c, val in enumerate(self.meta_headers)}
            for study_id, study_meta in viewitems(self.results):
                # add metadata to dataframe and dict
                # use from_dict because pandas doesn't like cursor objects
                samples_meta[study_id] = pd.DataFrame.from_dict(
                    {s[0]: s[1:] for s in study_meta}, orient='index')
                samples_meta[study_id].rename(columns=headers, inplace=True)
                # set up study-based data needed
                study = Study(study_id)
                study_sample_ids = {s[0] for s in study_meta}
                study_proc_ids[study_id] = defaultdict(list)
                for proc_data_id in study.processed_data():
                    proc_data = ProcessedData(proc_data_id)
                    datatype = proc_data.data_type()
                    # skip processed data if it doesn't fit the given datatypes
                    if datatypes is not None and datatype not in datatypes:
                        continue
                    filter_samps = proc_data.samples.intersection(
                        study_sample_ids)
                    if filter_samps:
                        proc_data_samples[proc_data_id] = sorted(filter_samps)
                        study_proc_ids[study_id][datatype].append(proc_data_id)

            return study_proc_ids, proc_data_samples, samples_meta
开发者ID:adamrp,项目名称:qiita,代码行数:54,代码来源:search.py

示例2: _build_study_info

# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import processed_data [as 别名]
def _build_study_info(user, study_proc=None, proc_samples=None):
    """Builds list of dicts for studies table, with all HTML formatted

    Parameters
    ----------
    user : User object
        logged in user
    study_proc : dict of lists, optional
        Dictionary keyed on study_id that lists all processed data associated
        with that study. Required if proc_samples given.
    proc_samples : dict of lists, optional
        Dictionary keyed on proc_data_id that lists all samples associated with
        that processed data. Required if study_proc given.

    Returns
    -------
    infolist: list of dict of lists and dicts
        study and processed data info for JSON serialiation for datatables
        Each dict in the list is a single study, and contains the text

    Notes
    -----
    Both study_proc and proc_samples must be passed, or neither passed.
    """
    build_samples = False
    # Logic check to make sure both needed parts passed
    if study_proc is not None and proc_samples is None:
        raise IncompetentQiitaDeveloperError(
            'Must pass proc_samples when study_proc given')
    elif proc_samples is not None and study_proc is None:
        raise IncompetentQiitaDeveloperError(
            'Must pass study_proc when proc_samples given')
    elif study_proc is None:
        build_samples = True

    # get list of studies for table
    study_set = user.user_studies.union(
        Study.get_by_status('public')).union(user.shared_studies)
    if study_proc is not None:
        study_set = study_set.intersection(study_proc)
    if not study_set:
        # 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_set, cols)

    infolist = []
    for info in study_info:
        # Convert DictCursor to proper dict
        info = dict(info)
        study = Study(info['study_id'])
        # Build the processed data info for the study if none passed
        if build_samples:
            proc_data_list = study.processed_data()
            proc_samples = {}
            study_proc = {study.id: defaultdict(list)}
            for pid in proc_data_list:
                proc_data = ProcessedData(pid)
                study_proc[study.id][proc_data.data_type()].append(pid)
                proc_samples[pid] = proc_data.samples

        study_info = _build_single_study_info(study, info, study_proc,
                                              proc_samples)
        infolist.append(study_info)
    return infolist
开发者ID:DarcyMyers,项目名称:qiita,代码行数:71,代码来源:listing_handlers.py

示例3: TestStudy

# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import processed_data [as 别名]
class TestStudy(TestCase):
    def setUp(self):
        self.study = Study(1)
        self.portal = qiita_config.portal

        self.info = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": StudyPerson(2),
            "principal_investigator_id": StudyPerson(3),
            "lab_person_id": StudyPerson(1)
        }

        self.infoexp = {
            "timeseries_type_id": 1,
            "metadata_complete": True,
            "mixs_compliant": True,
            "number_samples_collected": 25,
            "number_samples_promised": 28,
            "study_alias": "FCM",
            "study_description": "Microbiome of people who eat nothing but "
                                 "fried chicken",
            "study_abstract": "Exploring how a high fat diet changes the "
                              "gut microbiome",
            "emp_person_id": 2,
            "principal_investigator_id": 3,
            "lab_person_id": 1
        }

        self.existingexp = {
            'mixs_compliant': True,
            'metadata_complete': True,
            'reprocess': False,
            'number_samples_promised': 27,
            'emp_person_id': StudyPerson(2),
            'funding': None,
            'vamps_id': None,
            'first_contact': datetime(2014, 5, 19, 16, 10),
            'principal_investigator_id': StudyPerson(3),
            'timeseries_type_id': 1,
            'study_abstract':
                "This is a preliminary study to examine the "
                "microbiota associated with the Cannabis plant. Soils samples "
                "from the bulk soil, soil associated with the roots, and the "
                "rhizosphere were extracted and the DNA sequenced. Roots "
                "from three independent plants of different strains were "
                "examined. These roots were obtained November 11, 2011 from "
                "plants that had been harvested in the summer. Future "
                "studies will attempt to analyze the soils and rhizospheres "
                "from the same location at different time points in the plant "
                "lifecycle.",
            'spatial_series': False,
            'study_description': 'Analysis of the Cannabis Plant Microbiome',
            'study_alias': 'Cannabis Soils',
            'most_recent_contact': '2014-05-19 16:11',
            'most_recent_contact': datetime(2014, 5, 19, 16, 11),
            'lab_person_id': StudyPerson(1),
            'number_samples_collected': 27}

    def tearDown(self):
        qiita_config.portal = self.portal

    def _change_processed_data_status(self, new_status):
        # Change the status of the studies by changing the status of their
        # processed data
        id_status = convert_to_id(new_status, 'processed_data_status')
        self.conn_handler.execute(
            "UPDATE qiita.processed_data SET processed_data_status_id = %s",
            (id_status,))

    def test_get_info(self):
        # Test get all info for single study
        qiita_config.portal = 'QIITA'
        obs = Study.get_info([1])
        self.assertEqual(len(obs), 1)
        obs = dict(obs[0])
        exp = {
            'mixs_compliant': True, 'metadata_complete': True,
            'reprocess': False, 'timeseries_type': 'None',
            'number_samples_promised': 27, 'emp_person_id': 2,
            'funding': None, 'vamps_id': None,
            'first_contact': datetime(2014, 5, 19, 16, 10),
            'principal_investigator_id': 3, 'timeseries_type_id': 1,
            'pmid': ['123456', '7891011'], 'study_alias': 'Cannabis Soils',
            'spatial_series': False,
            'study_abstract': 'This is a preliminary study to examine the '
            'microbiota associated with the Cannabis plant. Soils samples from'
            ' the bulk soil, soil associated with the roots, and the '
            'rhizosphere were extracted and the DNA sequenced. Roots from '
            'three independent plants of different strains were examined. '
            'These roots were obtained November 11, 2011 from plants that had '
            'been harvested in the summer. Future studies will attempt to '
#.........这里部分代码省略.........
开发者ID:MarkBruns,项目名称:qiita,代码行数:103,代码来源:test_study.py

示例4: TestStudy

# 需要导入模块: from qiita_db.study import Study [as 别名]
# 或者: from qiita_db.study.Study import processed_data [as 别名]

#.........这里部分代码省略.........
        }
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.infoexp.update(newinfo)
        new.info = newinfo
        # add missing table cols
        self.infoexp["funding"] = None
        self.infoexp["spatial_series"] = None
        self.infoexp["most_recent_contact"] = None
        self.infoexp["reprocess"] = False
        self.infoexp["lab_person_id"] = 2
        self.assertEqual(new.info, self.infoexp)

    def test_set_info_public(self):
        """Tests for fail if editing info of a public study"""
        with self.assertRaises(QiitaDBStatusError):
            self.study.info = {"vamps_id": "12321312"}

    def test_set_info_disallowed_keys(self):
        """Tests for fail if sending non-info keys in info dict"""
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        with self.assertRaises(QiitaDBColumnError):
            new.info = {"email": "[email protected]"}

    def test_info_empty(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        with self.assertRaises(IncompetentQiitaDeveloperError):
            new.info = {}

    def test_retrieve_status(self):
        self.assertEqual(self.study.status, "public")

    def test_set_status(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        new.status = "private"
        self.assertEqual(new.status, "private")

    def test_retrieve_shared_with(self):
        self.assertEqual(self.study.shared_with, ['[email protected]',
                         '[email protected]'])

    def test_retrieve_pmids(self):
        exp = ['123456', '7891011']
        self.assertEqual(self.study.pmids, exp)

    def test_retrieve_pmids_empty(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.pmids, [])

    def test_retrieve_investigation(self):
        self.assertEqual(self.study.investigation, 1)

    def test_retrieve_investigation_empty(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.investigation, None)

    def test_retrieve_sample_template(self):
        self.assertEqual(self.study.sample_template, 1)

    def test_retrieve_data_types(self):
        self.assertEqual(self.study.data_types, ['18S'])

    def test_retrieve_data_types_none(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.data_types, [])

    def test_retrieve_raw_data(self):
        self.assertEqual(self.study.raw_data(), [1, 2])

    def test_retrieve_raw_data_none(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.raw_data(), [])

    def test_retrieve_preprocessed_data(self):
        self.assertEqual(self.study.preprocessed_data(), [1, 2])

    def test_retrieve_preprocessed_data_none(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.preprocessed_data(), [])

    def test_retrieve_processed_data(self):
        self.assertEqual(self.study.processed_data(), [1])

    def test_retrieve_processed_data_none(self):
        new = Study.create(User('[email protected]'), 'NOT Identification of the '
                           'Microbiomes for Cannabis Soils', [1], self.info)
        self.assertEqual(new.processed_data(), [])

    def test_add_pmid(self):
        self.study.add_pmid('4544444')
        exp = ['123456', '7891011', '4544444']
        self.assertEqual(self.study.pmids, exp)
开发者ID:Jorge-C,项目名称:qiita,代码行数:104,代码来源:test_study.py


注:本文中的qiita_db.study.Study.processed_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。