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


Python EBISubmission.generate_sample_xml方法代码示例

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


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

示例1: test_generate_sample_xml

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import generate_sample_xml [as 别名]
 def test_generate_sample_xml(self):
     submission = EBISubmission('001', 'teststudy', 'test asbstract',
                                'metagenome')
     submission.add_sample('test1')
     submission.add_sample('test2')
     xmlelement = submission.generate_sample_xml()
     xml = minidom.parseString(ET.tostring(xmlelement))
     xmlstring = xml.toprettyxml(indent='  ', encoding='UTF-8')
     obs_stripped = ''.join([l.strip() for l in xmlstring.splitlines()])
     exp_stripped = ''.join([l.strip() for l in SAMPLEXML.splitlines()])
     self.assertEqual(obs_stripped, exp_stripped)
开发者ID:Jorge-C,项目名称:qiita,代码行数:13,代码来源:test_ebi.py

示例2: submit_EBI

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import generate_sample_xml [as 别名]
def submit_EBI(artifact_id, action, send, test=False, test_size=False):
    """Submit an artifact to EBI

    Parameters
    ----------
    artifact_id : int
        The artifact id
    action : %s
        The action to perform with this data
    send : bool
        True to actually send the files
    test : bool
        If True some restrictions will be ignored, only used in parse_EBI_reply
    test_size : bool
        If True the EBI-ENA restriction size will be changed to 6000
    """
    # step 1: init and validate
    ebi_submission = EBISubmission(artifact_id, action)

    # step 2: generate demux fastq files
    try:
        ebi_submission.generate_demultiplexed_fastq()
    except Exception:
        error_msg = format_exc()
        if isdir(ebi_submission.full_ebi_dir):
            rmtree(ebi_submission.full_ebi_dir)
        LogEntry.create('Runtime', error_msg,
                        info={'ebi_submission': artifact_id})
        raise

    # step 3: generate and write xml files
    ebi_submission.generate_xml_files()

    # before we continue let's check the size of the submission
    to_review = [ebi_submission.study_xml_fp,
                 ebi_submission.sample_xml_fp,
                 ebi_submission.experiment_xml_fp,
                 ebi_submission.run_xml_fp,
                 ebi_submission.submission_xml_fp]
    total_size = sum([stat(tr).st_size for tr in to_review if tr is not None])
    # note that the max for EBI is 10M but let's play it safe
    max_size = 8.5e+6 if not test_size else 6000
    if total_size > max_size:
        LogEntry.create(
            'Runtime', 'The submission: %d is larger than allowed (%d), will '
            'try to fix: %d' % (artifact_id, max_size, total_size))
        # transform current metadata to dataframe for easier curation
        rows = {k: dict(v) for k, v in viewitems(ebi_submission.samples)}
        df = pd.DataFrame.from_dict(rows, orient='index')
        # remove unique columns and same value in all columns
        nunique = df.apply(pd.Series.nunique)
        nsamples = len(df.index)
        cols_to_drop = set(
            nunique[(nunique == 1) | (nunique == nsamples)].index)
        # maximize deletion by removing also columns that are almost all the
        # same or almost all unique
        cols_to_drop = set(
            nunique[(nunique <= int(nsamples * .01)) |
                    (nunique >= int(nsamples * .5))].index)
        cols_to_drop = cols_to_drop - {'taxon_id', 'scientific_name',
                                       'description'}
        all_samples = ebi_submission.sample_template.ebi_sample_accessions
        samples = {k: all_samples[k] for k in ebi_submission.samples}
        ebi_submission.write_xml_file(
            ebi_submission.generate_sample_xml(samples, cols_to_drop),
            ebi_submission.sample_xml_fp)

        # now let's recalculate the size to make sure it's fine
        new_total_size = sum([stat(tr).st_size
                              for tr in to_review if tr is not None])
        LogEntry.create(
            'Runtime', 'The submission: %d after cleaning is %d and was %d' % (
                artifact_id, total_size, new_total_size))
        if new_total_size > max_size:
            raise ComputeError(
                'Even after cleaning the submission: %d is too large. Before '
                'cleaning: %d, after: %d' % (
                    artifact_id, total_size, new_total_size))

    if send:
        # getting aspera's password
        old_ascp_pass = environ.get('ASPERA_SCP_PASS', '')
        if old_ascp_pass == '':
            environ['ASPERA_SCP_PASS'] = qiita_config.ebi_seq_xfer_pass
        ascp_passwd = environ['ASPERA_SCP_PASS']
        LogEntry.create('Runtime',
                        ('Submission of sequences of pre_processed_id: '
                         '%d completed successfully' % artifact_id))

        # step 4: sending sequences
        if action != 'MODIFY':
            LogEntry.create('Runtime',
                            ("Submitting sequences for pre_processed_id: "
                             "%d" % artifact_id))
            for cmd in ebi_submission.generate_send_sequences_cmd():
                stdout, stderr, rv = system_call(cmd)
                if rv != 0:
                    error_msg = ("ASCP Error:\nStd output:%s\nStd error:%s" % (
                        stdout, stderr))
                    environ['ASPERA_SCP_PASS'] = old_ascp_pass
#.........这里部分代码省略.........
开发者ID:tkosciol,项目名称:qiita,代码行数:103,代码来源:commands.py


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