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


Python SampleTemplate.validate_restrictions方法代码示例

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


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

示例1: sample_template_overview_handler_get_request

# 需要导入模块: from qiita_db.metadata_template.sample_template import SampleTemplate [as 别名]
# 或者: from qiita_db.metadata_template.sample_template.SampleTemplate import validate_restrictions [as 别名]
def sample_template_overview_handler_get_request(study_id, user):
    # Check if the current user has access to the sample template
    sample_template_checks(study_id, user)

    # Check if the sample template exists
    exists = SampleTemplate.exists(study_id)

    # The following information should always be provided:
    # The files that have been uploaded to the system and can be a
    # sample template file
    files = [f for _, f, _ in get_files_from_uploads_folders(study_id)
             if f.endswith(('txt', 'tsv', 'xlsx'))]
    # If there is a job associated with the sample information, the job id
    job = None
    job_info = r_client.get(SAMPLE_TEMPLATE_KEY_FORMAT % study_id)
    if job_info:
        job = loads(job_info)['job_id']

    # Specific information if it exists or not:
    data_types = []
    st_fp_id = None
    old_files = []
    num_samples = 0
    num_cols = 0
    columns = []
    specimen_id_column = None
    sample_restrictions = ''
    if exists:
        # If it exists we need to provide:
        # The id of the sample template file so the user can download it and
        # the list of old filepaths
        st = SampleTemplate(study_id)
        all_st_files = st.get_filepaths()
        # The current sample template file is the first one in the list
        # (pop(0)) and we are interested only in the id ([0])
        st_fp_id = all_st_files.pop(0)[0]
        # For the old filepaths we are only interested in their basename
        old_files = [basename(fp) for _, fp in all_st_files]
        # The number of samples - this is a space efficient way of counting
        # the number of samples. Doing len(list(st.keys())) creates a list
        # that we are not using
        num_samples = sum(1 for _ in st.keys())
        columns = st.categories()
        # The number of columns
        num_cols = len(columns)
        specimen_id_column = Study(study_id).specimen_id_column
        _, sample_restrictions = st.validate_restrictions()
    else:
        # It doesn't exist, we also need to provide the data_types in case
        # the user uploads a QIIME mapping file
        data_types = sorted(data_types_get_req()['data_types'])

    return {'exists': exists,
            'uploaded_files': files,
            'data_types': data_types,
            'user_can_edit': Study(study_id).can_edit(user),
            'job': job,
            'download_id': st_fp_id,
            'old_files': old_files,
            'num_samples': num_samples,
            'num_columns': num_cols,
            'columns': columns,
            'sample_restrictions': sample_restrictions,
            'specimen_id_column': specimen_id_column}
开发者ID:antgonza,项目名称:qiita,代码行数:66,代码来源:sample_template.py


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