示例#1
0
def write_outputs(results: serialiser.AntismashResults,
                  options: ConfigType) -> None:
    """ Write output files (webpage, genbank files, etc) to the output directory

        Arguments:
            results: a serialiser.AntismashResults instance
            options: an antismash Config instance

        Returns:
            None
    """
    # don't use results for which the module no longer exists to regenerate/calculate
    module_results_per_record = []
    for record_results in results.results:
        record_result = {}
        for module_name, result in record_results.items():
            if isinstance(result, ModuleResults):
                record_result[module_name] = result
        module_results_per_record.append(record_result)

    logging.debug("Creating results page")
    html.write(results.records, module_results_per_record, options)

    logging.debug("Creating results SVGs")
    svg.write(options, module_results_per_record)

    # convert records to biopython
    bio_records = [record.to_biopython() for record in results.records]

    # add antismash meta-annotation to records
    add_antismash_comments(list(zip(results.records, bio_records)), options)

    logging.debug("Writing cluster-specific genbank files")
    for record, bio_record in zip(results.records, bio_records):
        for region in record.get_regions():
            region.write_to_genbank(directory=options.output_dir,
                                    record=bio_record)

    # write records to an aggregate output
    base_filename = os.path.splitext(
        os.path.join(options.output_dir, results.input_file))[0]
    combined_filename = base_filename + ".gbk"
    logging.debug("Writing final genbank file to '%s'", combined_filename)
    SeqIO.write(bio_records, combined_filename, "genbank")

    zipfile = base_filename + ".zip"
    if os.path.exists(zipfile):
        os.remove(zipfile)
    if not options.skip_zip_file:
        logging.debug("Zipping output to '%s'", zipfile)
        with tempfile.NamedTemporaryFile(prefix="as_zip_tmp",
                                         suffix=".zip") as temp:
            shutil.make_archive(temp.name.replace(".zip", ""),
                                "zip",
                                root_dir=options.output_dir)
            shutil.copy(temp.name, zipfile)
        assert os.path.exists(zipfile)
示例#2
0
def write_outputs(results, options) -> None:
    """ Write output files (webpage, genbank files, etc) to the output directory

        Arguments:
            results: a serialiser.AntismashResults instance
            options: an antismash Config instance

        Returns:
            None
    """
    logging.debug("Creating results page")
    html.write(results.records, results.results, options)

    logging.debug("Creating results SVGs")
    svg.write(options, results.results)

    # convert records to biopython
    bio_records = [record.to_biopython() for record in results.records]

    logging.debug("Writing cluster-specific genbank files")
    for record, bio_record in zip(results.records, bio_records):
        for cluster in record.get_clusters():
            cluster.write_to_genbank(directory=options.output_dir,
                                     record=bio_record)

    # write records to an aggregate output
    base_filename = os.path.splitext(
        os.path.join(options.output_dir, results.input_file))[0]
    combined_filename = base_filename + ".gbk"
    logging.debug("Writing final genbank file to '%s'", combined_filename)
    SeqIO.write(bio_records, combined_filename, "genbank")

    zipfile = base_filename + ".zip"
    logging.debug("Zipping output to '%s'", zipfile)
    if os.path.exists(zipfile):
        os.remove(zipfile)

    with tempfile.NamedTemporaryFile(prefix="as_zip_tmp",
                                     suffix=".zip") as temp:
        shutil.make_archive(temp.name.replace(".zip", ""),
                            "zip",
                            root_dir=options.output_dir)
        shutil.copy(temp.name, zipfile)
    assert os.path.exists(zipfile)