Exemplo n.º 1
0
def invoke_check_fasta_gff():
    """
    Parse command-line options then invoke
    :py:func:`riboviz.check_fasta_gff.check_fasta_gff`.
    """
    print(provenance.write_provenance_to_str(__file__))
    options = parse_command_line_options()
    fasta = options.fasta
    gff = options.gff
    check_fasta_gff.check_fasta_gff(fasta, gff)
Exemplo n.º 2
0
def test_check_fasta_gff_no_such_gff_file(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff`
    with FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and
    a non-existent GFF file raises an exception.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    issues_file = tmpdir.join("issues.tsv")
    with pytest.raises(FileNotFoundError):
        check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE, "nosuch.gff",
                                        issues_file)
Exemplo n.º 3
0
def test_check_fasta_gff(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff` with
    FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and validate the TSV file
    output.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    issues_file = tmpdir.join("issues.tsv")
    check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE, TEST_GFF_CHECK_FILE,
                                    issues_file)
    check_fasta_gff_issues_csv(TEST_CHECK_ISSUES, issues_file)
Exemplo n.º 4
0
def test_check_fasta_gff_empty_gff_file(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff`
    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()
    issues_file = tmpdir.join("issues.tsv")
    with pytest.raises(ValueError):
        check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE, gff_file,
                                        issues_file)
Exemplo n.º 5
0
def test_check_fasta_gff_start_codons(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff` with
    FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and custom
    ``start_codons`` and validate the TSV file output.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    issues_file = tmpdir.join("issues.tsv")
    check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE,
                                    TEST_GFF_CHECK_FILE,
                                    issues_file,
                                    start_codons=TEST_START_CODONS)
    # 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]
    check_fasta_gff_issues_csv(test_check_issues, issues_file)
Exemplo n.º 6
0
def test_check_fasta_gff_use_feature_name_true(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff` with
    FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and ``use_feature_name=True``
    and validate the TSV file output.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    issues_file = tmpdir.join("issues.tsv")
    check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE,
                                    TEST_GFF_CHECK_FILE,
                                    issues_file,
                                    use_feature_name=True)
    # 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]))
    check_fasta_gff_issues_csv(test_check_issues, issues_file)
Exemplo n.º 7
0
def test_check_fasta_gff_feature_format(tmpdir):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff` with
    FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and custom
    ``cds_feature_format`` and validate the TSV file output.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    """
    issues_file = tmpdir.join("issues.tsv")
    cds_feature_format = "{}-Custom"
    check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE,
                                    TEST_GFF_CHECK_FILE,
                                    issues_file,
                                    feature_format=cds_feature_format)
    # 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]))
    check_fasta_gff_issues_csv(test_check_issues, issues_file)
Exemplo n.º 8
0
def test_check_fasta_gff_stdout(tmpdir, capsys):
    """
    Test :py:func:`riboviz.check_fasta_gff.check_fasta_gff` with
    FASTA file (:py:const:`TEST_FASTA_CHECK_FILE`) and GFF file
    (:py:const:`TEST_GFF_CHECK_FILE`) and validate the standard
    output.

    :param tmpdir: Temporary directory (pytest built-in fixture)
    :type tmpdir: py._path.local.LocalPath
    :param capsys: Capture standard output (pytest built-in fixture)
    :type capsys: _pytest.capture.CaptureFixture
    """
    issues_file = tmpdir.join("issues.tsv")
    check_fasta_gff.check_fasta_gff(TEST_FASTA_CHECK_FILE,
                                    TEST_GFF_CHECK_FILE,
                                    issues_file,
                                    is_verbose=True)
    lines = capsys.readouterr()[0].split("\n")
    expected_config = [
        "Configuration:", "{}\t{}".format(check_fasta_gff.FASTA_FILE,
                                          TEST_FASTA_CHECK_FILE),
        "{}\t{}".format(check_fasta_gff.GFF_FILE, TEST_GFF_CHECK_FILE),
        "{}\t{}".format(check_fasta_gff.START_CODONS, [START_CODON]), ""
    ]
    assert lines[0:len(expected_config)] == expected_config,\
        "Unexpected Configuration header"
    lines = lines[len(expected_config):]
    expected_metadata = [
        "Metadata:", "{}\t{}".format(check_fasta_gff.NUM_SEQUENCES,
                                     TEST_NUM_SEQUENCES),
        "{}\t{}".format(check_fasta_gff.NUM_FEATURES, TEST_NUM_FEATURES),
        "{}\t{}".format(check_fasta_gff.NUM_CDS_FEATURES,
                        TEST_NUM_CDS_FEATURES), ""
    ]
    assert lines[0:len(expected_metadata)] == expected_metadata,\
        "Unexpected Metadata header"
    lines = lines[len(expected_metadata):]
    expected_summary = ["Issue summary:", "{}\t{}".format("Issue", "Count")]
    assert lines[0:len(expected_summary)] == expected_summary,\
        "Unexpected Issue summary header"
    lines = lines[len(expected_summary):]
    counts = check_fasta_gff.count_issues(TEST_CHECK_ISSUES)
    expected_counts = [
        "{}\t{}".format(issue, count) for issue, count in counts
    ]
    actual_counts = lines[0:len(expected_counts)]
    # Sort so test passes if same counts are reported but in
    # different order.
    expected_counts.sort()
    actual_counts.sort()
    assert actual_counts == expected_counts, "Unexpected counts"
    lines = lines[len(expected_counts):]
    line = lines.pop(0)
    assert line == "", "Missing blank line"
    line = lines.pop(0)
    assert line == "Issue details:", "Unexpected Issue details header"
    expected_details = [
        check_fasta_gff.ISSUE_FORMATS[issue_type].format(sequence=seq_id,
                                                         feature=feature_id,
                                                         data=issue_data)
        for seq_id, feature_id, issue_type, issue_data in TEST_CHECK_ISSUES
    ]
    actual_details = lines[0:len(expected_details)]
    # Sort so test passes if same details are reported but in
    # different order.
    expected_details.sort()
    actual_details.sort()
    assert actual_details == expected_details, "Unexpected details"
    lines = lines[len(expected_details):]
    assert lines == [""], "Missing blank line"