Exemplo n.º 1
0
def test_get_issues_no_such_gff_file():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and
    a non-existent GFF file raises an exception.
    """
    with pytest.raises(FileNotFoundError):
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE, "nosuch.gff")
Exemplo n.º 2
0
def test_get_issues_no_such_fasta_file():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with an empty FASTA file and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) raises an exception.
    """
    with pytest.raises(FileNotFoundError):
        check_fasta_gff.get_issues("nosuch.fasta", TEST_GFF_CHECK_FILE)
Exemplo n.º 3
0
def test_get_issues_empty_gff_file(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and
    an empty GFF file raises an exception.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    # Cast to str to avoid "'LocalPath' object is not subscriptable"
    # error from gff library.
    gff_file = str(tmpdir.join("gff.gff"))
    open(gff_file, 'a').close()
    with pytest.raises(ValueError):
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE, gff_file)
Exemplo n.º 4
0
def test_get_issues_empty_fasta_file(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with an empty FASTA file and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) raises an exception.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    # Cast to str to avoid "'LocalPath' object is not subscriptable"
    # error from gff library.
    fasta_file = str(tmpdir.join("fasta.fasta"))
    open(fasta_file, 'a').close()
    with pytest.raises(FastaIndexingError):
        check_fasta_gff.get_issues(fasta_file, TEST_GFF_CHECK_FILE)
Exemplo n.º 5
0
def test_get_issues_feature_format():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and custom
    ``cds_feature_format``.
    """
    cds_feature_format = "{}-Custom"
    num_sequences, num_features, num_cds_features, issues = \
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE,
                                   TEST_GFF_CHECK_FILE,
                                   feature_format=cds_feature_format)
    assert num_sequences == TEST_NUM_SEQUENCES, \
        "Unexpected number of sequences"
    assert num_features == TEST_NUM_FEATURES, \
        "Unexpected number of features"
    assert num_cds_features == TEST_NUM_CDS_FEATURES, \
        "Unexpected number of CDS features"
    # Create expected results for custom cds_feature_format.
    test_check_issues = TEST_CHECK_ISSUES.copy()
    test_check_issues.remove(TEST_NO_ID_NAME_ATTR_ISSUE)
    test_check_issues.append(
        (TEST_NO_ID_NAME_ATTR_ISSUE[0],
         cds_feature_format.format(TEST_NO_ID_NAME_ATTR_PREFIX),
         TEST_NO_ID_NAME_ATTR_ISSUE[2], TEST_NO_ID_NAME_ATTR_ISSUE[3]))
    for issue in issues:
        assert issue in test_check_issues
Exemplo n.º 6
0
def test_get_issues_use_feature_name_true():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and ``use_feature_name=True``.
    """
    num_sequences, num_features, num_cds_features, issues = \
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE,
                                   TEST_GFF_CHECK_FILE,
                                   use_feature_name=True)
    assert num_sequences == TEST_NUM_SEQUENCES, \
        "Unexpected number of sequences"
    assert num_features == TEST_NUM_FEATURES, \
        "Unexpected number of features"
    assert num_cds_features == TEST_NUM_CDS_FEATURES, \
        "Unexpected number of CDS features"
    # Create expected results when use_feature_name=True.
    test_check_issues = TEST_CHECK_ISSUES.copy()
    test_check_issues.remove(TEST_NO_ATG_START_ID_NAME_ATTR_ISSUE)
    test_check_issues.append((TEST_NO_ATG_START_ID_NAME_ATTR_ISSUE[0],
                              TEST_NO_ATG_START_ID_NAME_ATTR_NAME,
                              TEST_NO_ATG_START_ID_NAME_ATTR_ISSUE[2],
                              TEST_NO_ATG_START_ID_NAME_ATTR_ISSUE[3]))
    for issue in issues:
        assert issue in test_check_issues
Exemplo n.º 7
0
def test_get_issues():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and check all issues match
    expected issues in :py:const:`TEST_CHECK_ISSUES`).
    """
    num_sequences, num_features, num_cds_features, issues = \
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE,
                                   TEST_GFF_CHECK_FILE)
    assert num_sequences == TEST_NUM_SEQUENCES, \
        "Unexpected number of sequences"
    assert num_features == TEST_NUM_FEATURES, \
        "Unexpected number of features"
    assert num_cds_features == TEST_NUM_CDS_FEATURES, \
        "Unexpected number of CDS features"
    for issue in issues:
        assert issue in TEST_CHECK_ISSUES
Exemplo n.º 8
0
def test_get_issues_start_codons():
    """
    Test :py:func:`riboviz.check_fasta_gff.get_issues`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and custom ``start_codons``.
    """
    num_sequences, num_features, num_cds_features, issues = \
        check_fasta_gff.get_issues(TEST_FASTA_CHECK_FILE,
                                   TEST_GFF_CHECK_FILE,
                                   start_codons=TEST_START_CODONS)
    assert num_sequences == TEST_NUM_SEQUENCES, \
        "Unexpected number of sequences"
    assert num_features == TEST_NUM_FEATURES, \
        "Unexpected number of features"
    assert num_cds_features == TEST_NUM_CDS_FEATURES, \
        "Unexpected number of CDS features"
    # TEST_START_CODONS includes all start codons in test data so
    # expect no NO_START_CODON issues in results.
    test_check_issues = [(s, f, i, d) for (s, f, i, d) in TEST_CHECK_ISSUES
                         if i != check_fasta_gff.NO_START_CODON]
    for issue in issues:
        assert issue in test_check_issues