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


Python EBISubmission.from_templates_and_per_sample_fastqs方法代码示例

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


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

示例1: submit_EBI_from_files

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import from_templates_and_per_sample_fastqs [as 别名]
def submit_EBI_from_files(study_id, sample_template, prep_template,
                          fastq_dir_fp, output_dir_fp, investigation_type,
                          action, send):
    """EBI submission from files

    Parameters
    ----------
    study_id : int
        The study id
    sample_template : File
        The file handler of the sample template file
    prep_template : File
        The file handler of the prep template file
    fastq_dir_fp : str
        The fastq filepath
    output_dir_fp : str
        The output directory
    investigation_type : str
        The investigation type string
    action : str
        The action to perform with this data, valid options are: %s
    send : bool
        True to actually send the files
    """

    study = Study(study_id)
    study_id_str = str(study_id)

    # Get study-specific output directory and set filepaths
    get_output_fp = partial(join, output_dir_fp)
    study_fp = get_output_fp('study.xml')
    sample_fp = get_output_fp('sample.xml')
    experiment_fp = get_output_fp('experiment.xml')
    run_fp = get_output_fp('run.xml')
    submission_fp = get_output_fp('submission.xml')

    if not isdir(output_dir_fp):
        makedirs(output_dir_fp)
    else:
        raise ValueError('The output folder already exists: %s' %
                         output_dir_fp)

    submission = EBISubmission.from_templates_and_per_sample_fastqs(
        study_id_str, study.title, study.info['study_abstract'],
        investigation_type, sample_template, prep_template,
        fastq_dir_fp)

    submission.write_all_xml_files(study_fp, sample_fp, experiment_fp, run_fp,
                                   submission_fp, action)

    if send:
        submission.send_sequences()
        submission.send_xml()
开发者ID:Jorge-C,项目名称:qiita,代码行数:55,代码来源:commands.py

示例2: test_generate_curl_command

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import from_templates_and_per_sample_fastqs [as 别名]
    def test_generate_curl_command(self):
        sample_template = StringIO(EXP_SAMPLE_TEMPLATE)
        prep_template = StringIO(EXP_PREP_TEMPLATE)
        submission = EBISubmission.from_templates_and_per_sample_fastqs(
            '001', 'test study', 'abstract',
            'type',  sample_template, prep_template, self.path)

        # Set these artificially since the function depends only on these fps
        submission.submission_xml_fp = 'submission.xml'
        submission.experiment_xml_fp = 'experiment.xml'
        submission.study_xml_fp = 'study.xml'
        submission.sample_xml_fp = 'sample.xml'
        # this should fail since we have not yet set the run.xml fp
        with self.assertRaises(NoXMLError):
            submission.generate_curl_command('1', '2', '3', '4')
        submission.run_xml_fp = 'run.xml'

        test_ebi_seq_xfer_user = 'ebi_seq_xfer_user'
        test_ebi_access_key = 'ebi_access_key'
        test_ebi_dropbox_url = 'ebi_dropbox_url'

        # Without curl certificate authentication
        test_ebi_skip_curl_cert = True
        obs = submission.generate_curl_command(test_ebi_seq_xfer_user,
                                               test_ebi_access_key,
                                               test_ebi_skip_curl_cert,
                                               test_ebi_dropbox_url)
        exp_skip_cert = ('curl -k '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '"ebi_dropbox_url/?auth=ERA%20ebi_seq_xfer_user'
                         '%20ebi_access_key%3D"')
        self.assertEqual(obs, exp_skip_cert)

        # With curl certificate authentication
        test_ebi_skip_curl_cert = False
        obs = submission.generate_curl_command(test_ebi_seq_xfer_user,
                                               test_ebi_access_key,
                                               test_ebi_skip_curl_cert,
                                               test_ebi_dropbox_url)
        exp_with_cert = ('curl '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '-F "[email protected]" '
                         '"ebi_dropbox_url/?auth=ERA%20ebi_seq_xfer_user'
                         '%20ebi_access_key%3D"')
        self.assertEqual(obs, exp_with_cert)
开发者ID:Jorge-C,项目名称:qiita,代码行数:54,代码来源:test_ebi.py

示例3: test_from_templates_and_per_sample_fastqs

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import from_templates_and_per_sample_fastqs [as 别名]
 def test_from_templates_and_per_sample_fastqs(self):
     sample_template = StringIO(EXP_SAMPLE_TEMPLATE)
     prep_template = StringIO(EXP_PREP_TEMPLATE)
     submission = EBISubmission.from_templates_and_per_sample_fastqs(
         '001', 'test study', 'abstract',
         'type',  sample_template, prep_template, self.path)
     self.assertEqual(submission.samples['sample2']['preps'][0]['platform'],
                      'ILLUMINA')
     self.assertEqual(
         submission.samples['sample2']['preps'][0]['file_path'],
         self.path + '/sample2.fastq.gz')
     with self.assertRaises(KeyError):
         submission.samples['nothere']
开发者ID:Jorge-C,项目名称:qiita,代码行数:15,代码来源:test_ebi.py

示例4: submit_EBI

# 需要导入模块: from qiita_ware.ebi import EBISubmission [as 别名]
# 或者: from qiita_ware.ebi.EBISubmission import from_templates_and_per_sample_fastqs [as 别名]

#.........这里部分代码省略.........
        # If we intend actually to send the files, then change the status in
        # the database
        preprocessed_data.update_insdc_status("submitting")

    # we need to figure out whether the investigation type is a known one
    # or if we have to submit a "new_investigation_type" to EBI
    current_type = prep_template.investigation_type
    ena_ontology = Ontology(convert_to_id("ENA", "ontology"))
    if current_type in ena_ontology.terms:
        investigation_type = current_type
    elif current_type in ena_ontology.user_defined_terms:
        investigation_type = "Other"
        new_investigation_type = current_type
    else:
        # This should never happen
        raise ValueError(
            "Unrecognized investigation type: '%s'. This term "
            "is neither one of the official terms nor one of the "
            "user-defined terms in the ENA ontology"
        )

    if fastq_dir_fp is not None:
        # If the user specifies a FASTQ directory, use it

        # Set demux_samples to None so that MetadataTemplate.to_file will put
        # all samples in the template files
        demux_samples = None
    else:
        # If the user does not specify a FASTQ directory, create one and
        # re-serialize the per-sample FASTQs from the demux file
        fastq_dir_fp = mkdtemp(prefix=qiita_config.working_dir)
        demux = [path for _, path, ftype in preprocessed_data.get_filepaths() if ftype == "preprocessed_demux"][0]

        # Keep track of which files were actually in the demux file so that we
        # can write those rows to the prep and samples templates
        demux_samples = set()

        with open_file(demux) as demux_fh:
            for samp, iterator in to_per_sample_ascii(demux_fh, list(sample_template)):
                demux_samples.add(samp)
                sample_fp = join(fastq_dir_fp, "%s.fastq.gz" % samp)
                wrote_sequences = False
                with gzopen(sample_fp, "w") as fh:
                    for record in iterator:
                        fh.write(record)
                        wrote_sequences = True

                if not wrote_sequences:
                    remove(sample_fp)

    output_dir = fastq_dir_fp + "_submission"

    samp_fp = join(fastq_dir_fp, "sample_metadata.txt")
    prep_fp = join(fastq_dir_fp, "prep_metadata.txt")

    sample_template.to_file(samp_fp, demux_samples)
    prep_template.to_file(prep_fp, demux_samples)

    # Get specific output directory and set filepaths
    get_output_fp = partial(join, output_dir)
    study_fp = get_output_fp("study.xml")
    sample_fp = get_output_fp("sample.xml")
    experiment_fp = get_output_fp("experiment.xml")
    run_fp = get_output_fp("run.xml")
    submission_fp = get_output_fp("submission.xml")

    if not isdir(output_dir):
        makedirs(output_dir)
    else:
        raise IOError("The output folder already exists: %s" % output_dir)

    with open(samp_fp, "U") as st, open(prep_fp, "U") as pt:
        submission = EBISubmission.from_templates_and_per_sample_fastqs(
            preprocessed_data_id_str,
            study.title,
            study.info["study_abstract"],
            investigation_type,
            st,
            pt,
            fastq_dir_fp,
            new_investigation_type=new_investigation_type,
            pmids=study.pmids,
        )

    submission.write_all_xml_files(study_fp, sample_fp, experiment_fp, run_fp, submission_fp, action)

    if send:
        submission.send_sequences()
        study_accession, submission_accession = submission.send_xml()

        if study_accession is None or submission_accession is None:
            preprocessed_data.update_insdc_status("failed")

            raise ComputeError("EBI Submission failed!")
        else:
            preprocessed_data.update_insdc_status("success", study_accession, submission_accession)
    else:
        study_accession, submission_accession = None, None

    return study_accession, submission_accession
开发者ID:MarkBruns,项目名称:qiita,代码行数:104,代码来源:commands.py


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