Esempio n. 1
0
def test_get_cds_codons_file(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with
    FASTA file (:py:const:`TEST_FASTA_CODONS_FILE`) and GFF file
    (:py:const:`TEST_GFF_CODONS_FILE`) and validate the TSV file output.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    get_cds_codons.get_cds_codons_file(TEST_FASTA_CODONS_FILE,
                                       TEST_GFF_CODONS_FILE, tmp_file)
    check_feature_codons_csv(TEST_CDS_CODONS, tmp_file)
Esempio n. 2
0
def test_get_cds_codons_file_empty_gff_file(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with
    FASTA file (:py:const:`TEST_FASTA_CODONS_FILE`) and an
    empty GFF file raises an exception.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    with pytest.raises(ValueError):
        get_cds_codons.get_cds_codons_file(TEST_FASTA_CODONS_FILE, tmp_file,
                                           tmp_file)
Esempio n. 3
0
def test_get_cds_codons_file_empty_fasta_file(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with an empty
    FASTA file and GFF file (:py:const:`TEST_GFF_CODONS_FILE`) raises
    an exception.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    with pytest.raises(FastaIndexingError):
        get_cds_codons.get_cds_codons_file(tmp_file, TEST_GFF_CODONS_FILE,
                                           tmp_file)
Esempio n. 4
0
def test_get_cds_codons_file_no_such_fasta_file(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with a
    non-existent FASTA file and GFF file
    (:py:const:`TEST_GFF_CODONS_FILE`) raises an exception.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    with pytest.raises(FileNotFoundError):
        get_cds_codons.get_cds_codons_file("nosuch.fasta",
                                           TEST_GFF_CODONS_FILE, tmp_file)
Esempio n. 5
0
def test_get_cds_codons_file_exclude_stop_codons(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with
    FASTA file (:py:const:`TEST_FASTA_CODONS_FILE`) and GFF file
    (:py:const:`TEST_GFF_CODONS_FILE`), where stop codons are to be
    be excluded from the codons returned, and validate the TSV file
    output.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    get_cds_codons.get_cds_codons_file(TEST_FASTA_CODONS_FILE,
                                       TEST_GFF_CODONS_FILE,
                                       tmp_file,
                                       exclude_stop_codons=True)
    cds_codons_minus_stops = {
        name: codons[:-1]
        for name, codons in TEST_CDS_CODONS.items()
    }
    check_feature_codons_csv(cds_codons_minus_stops, tmp_file)
Esempio n. 6
0
def test_get_cds_codons_file_use_feature_name_true(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with
    FASTA file (:py:const:`TEST_FASTA_CODONS_FILE`) and GFF file
    (:py:const:`TEST_GFF_CODONS_FILE`) and ``use_feature_name=True``
    and validate the TSV file output.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    get_cds_codons.get_cds_codons_file(TEST_FASTA_CODONS_FILE,
                                       TEST_GFF_CODONS_FILE,
                                       tmp_file,
                                       use_feature_name=True)
    # Update TEST_CDS_CODONS with the expected result when
    # use_feature_name=True.
    test_cds_codons = TEST_CDS_CODONS.copy()
    codons = test_cds_codons[TEST_ID_NAME_ATTR_ID]
    del test_cds_codons[TEST_ID_NAME_ATTR_ID]
    test_cds_codons[TEST_ID_NAME_ATTR_NAME] = codons
    check_feature_codons_csv(test_cds_codons, tmp_file)
Esempio n. 7
0
def test_get_cds_codons_file_cds_format(tmp_file):
    """
    Test :py:func:`riboviz.get_cds_codons.get_cds_codons_file` with
    FASTA file (:py:const:`TEST_FASTA_CODONS_FILE`) and GFF file
    (:py:const:`TEST_GFF_CODONS_FILE`) and custom
    ``cds_feature_format`` and validate the TSV file output.

    :param tmp_file: Temporary file
    :type tmp_file: str or unicode
    """
    cds_feature_format = "{}-Custom"
    get_cds_codons.get_cds_codons_file(TEST_FASTA_CODONS_FILE,
                                       TEST_GFF_CODONS_FILE,
                                       tmp_file,
                                       cds_feature_format=cds_feature_format)
    # Create expected results for custom cds_feature_format.
    test_cds_codons = TEST_CDS_CODONS.copy()
    codons = test_cds_codons[TEST_NO_ID_NAME_ATTR]
    del test_cds_codons[TEST_NO_ID_NAME_ATTR]
    test_cds_codons[cds_feature_format.format(
        TEST_NO_ID_NAME_ATTR_PREFIX)] = codons
    check_feature_codons_csv(test_cds_codons, tmp_file)
Esempio n. 8
0
def invoke_get_cds_codons():
    """
    Parse command-line options then invoke
    :py:func:`riboviz.get_cds_codons.get_cds_codons_file`.
    """
    print(provenance.write_provenance_to_str(__file__))
    options = parse_command_line_options()
    fasta = options.fasta
    gff = options.gff
    cds_codons = options.cds_codons
    exclude_stop_codons = options.exclude_stop_codons
    cds_feature_format = options.cds_feature_format
    use_feature_name = options.use_feature_name
    try:
        get_cds_codons.get_cds_codons_file(fasta, gff, cds_codons,
                                           exclude_stop_codons,
                                           cds_feature_format,
                                           use_feature_name)
    except FastaIndexingError as e:
        print("{}: {}".format(type(e).__name__, e))
    except FileNotFoundError as e:
        print("{}: {}".format(type(e).__name__, e))
    except ValueError as e:
        print("{}: {}".format(type(e).__name__, e))