Example #1
0
def test_umitools_pre_dedup_group_tsv(group_umis, expected_fixture, tmp_dir,
                                      sample):
    """
    Test ``umi_tools group`` TSV files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    If UMI grouping was not enabled in the configuration that
    produced the data then this test is skipped.

    :param dedup_umi: Was UMI deduplication configured?
    :type dedup_umis: bool
    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    if not group_umis:
        pytest.skip('Skipped test applicable to UMI groups')
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.PRE_DEDUP_GROUPS_TSV),
        os.path.join(tmp_dir, sample, workflow_files.PRE_DEDUP_GROUPS_TSV))
Example #2
0
def test_samtools_view_sort_index_orf_map_clean_bam(expected_fixture, tmp_dir,
                                                    sample, nextflow_fixture):
    """
    Test ``samtools view | samtools sort`` BAM and ``samtools index``
    BAI files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    If Nextflow tests were requested then this test is run.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    :param nextflow_fixture: Should Nextflow tests be run?
    :type nextflow_fixture: bool
    """
    if not nextflow_fixture:
        pytest.skip('Skipped test applicable to Nextflow only')
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.ORF_MAP_CLEAN_BAM),
        os.path.join(tmp_dir, sample, workflow_files.ORF_MAP_CLEAN_BAM))
    bai_file_name = sam_bam.BAI_FORMAT.format(workflow_files.ORF_MAP_CLEAN_BAM)
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample, bai_file_name),
        os.path.join(tmp_dir, sample, bai_file_name))
Example #3
0
def compare_sam_files(expected_directory, directory, scratch_directory, sample,
                      file_name):
    """
    Test SAM files for equality. The SAM files are sorted
    into temporary SAM files which are then compared. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_directory: Expected data directory
    :type expected_directory: str or unicode
    :param directory: Data directory
    :type directory: str or unicode
    :param scratch_directory: scratch files directory
    :type scratch_directory: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    :param file_name: file name
    :type file_name: str or unicode
    """
    dir_name = os.path.basename(os.path.normpath(directory))
    expected_file = os.path.join(expected_directory, dir_name, sample,
                                 file_name)
    actual_file = os.path.join(directory, sample, file_name)
    expected_copy_dir = os.path.join(scratch_directory, "expected")
    os.mkdir(expected_copy_dir)
    actual_copy_dir = os.path.join(scratch_directory, "actual")
    os.mkdir(actual_copy_dir)
    expected_copy_file = os.path.join(expected_copy_dir, file_name)
    actual_copy_file = os.path.join(actual_copy_dir, file_name)
    pysam.sort("-o", expected_copy_file, expected_file)
    pysam.sort("-o", actual_copy_file, actual_file)
    compare_files.compare_files(expected_copy_file, actual_copy_file)
Example #4
0
def invoke_compare_files():
    """
    Parse command-line options then invoke
    :py:func:`riboviz.compare_files.compare_files`.
    """
    options = parse_command_line_options()
    file1 = options.file1
    file2 = options.file2
    names = options.names
    compare_files.compare_files(file1, file2, names)
Example #5
0
def test_trim5p_mismatch_tsv(expected_fixture, tmp_dir, sample):
    """
    Test :py:mod:`riboviz.tools.trim_5p_mismatch` TSV files for
    equality. See :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.TRIM_5P_MISMATCH_TSV),
        os.path.join(tmp_dir, sample, workflow_files.TRIM_5P_MISMATCH_TSV))
Example #6
0
def test_cutadapt_fq(expected_fixture, tmp_dir, sample):
    """
    Test ``cutadapt`` FASTQ files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.ADAPTER_TRIM_FQ),
        os.path.join(tmp_dir, sample, workflow_files.ADAPTER_TRIM_FQ))
Example #7
0
def test_hisat_fq(expected_fixture, tmp_dir, sample, file_name):
    """
    Test ``hisat`` FASTQ files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    :param file_name: file name
    :type file_name: str or unicode
    """
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample, file_name),
        os.path.join(tmp_dir, sample, file_name))
Example #8
0
def test_hisat2_build_index(expected_fixture, index_dir, index_prefix, index):
    """
    Test ``hisat2-build`` index files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param index_dir: Index files directory, from configuration file
    :type index_dir: str or unicode
    :param index_prefix: Index file name prefix
    :type index_prefix: str or unicode
    :param index: File name index
    :type index: int
    """
    file_name = hisat2.HT2_FORMAT.format(index_prefix, index)
    index_dir_name = os.path.basename(os.path.normpath(index_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, index_dir_name, file_name),
        os.path.join(index_dir, file_name))
Example #9
0
def test_collate_tpms_tsv(expected_fixture, output_dir):
    """
    Test ``collate_tpms.R`` TSV files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    Test non-sample-specific output TSV files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param output_dir: Output directory, from configuration file
    :type output_dir: str or unicode
    """
    output_dir_name = os.path.basename(os.path.normpath(output_dir))
    expected_file = os.path.join(expected_fixture, output_dir_name,
                                 workflow_r.TPMS_COLLATED_TSV)
    if not os.path.exists(expected_file):
        pytest.skip('Skipped as expected file does not exist')
    compare_files.compare_files(
        expected_file, os.path.join(output_dir, workflow_r.TPMS_COLLATED_TSV))
Example #10
0
def test_bam_to_h5_h5(expected_fixture, output_dir, sample):
    """
    Test ``bam_to_h5.R`` H5 files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param output_dir: Output directory, from configuration file
    :type output_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    file_name = h5.H5_FORMAT.format(sample)
    output_dir_name = os.path.basename(os.path.normpath(output_dir))
    expected_file = os.path.join(expected_fixture, output_dir_name, sample,
                                 file_name)
    if not os.path.exists(expected_file):
        pytest.skip('Skipped as expected file does not exist')
    compare_files.compare_files(expected_file,
                                os.path.join(output_dir, sample, file_name))
Example #11
0
def test_bedtools_bedgraph(expected_fixture, output_dir, sample, file_name):
    """
    Test ``bedtools genomecov`` bedgraph files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param output_dir: Output directory, from configuration file
    :type output_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    :param file_name: file name
    :type file_name: str or unicode
    """
    output_dir_name = os.path.basename(os.path.normpath(output_dir))
    expected_file = os.path.join(expected_fixture, output_dir_name, sample,
                                 file_name)
    if not os.path.exists(expected_file):
        pytest.skip('Skipped as expected file does not exist')
    compare_files.compare_files(expected_file,
                                os.path.join(output_dir, sample, file_name))
Example #12
0
def test_samtools_view_sort_index(dedup_umis, expected_fixture, output_dir,
                                  sample):
    """
    Test ``samtools view | samtools sort`` BAM and ``samtools index``
    BAI files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    If UMI deduplication was enabled in the configuration that
    produced the data then the only the existence of the files are
    checked as these files can differ between runs depending on which
    reads are removed by ``umi_tools dedup``.

    :param dedup_umi: Was UMI deduplication configured?
    :type dedup_umis: bool
    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param output_dir: Output directory, from configuration file
    :type output_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    file_name = sam_bam.BAM_FORMAT.format(sample)
    bai_file_name = sam_bam.BAI_FORMAT.format(file_name)
    output_dir_name = os.path.basename(os.path.normpath(output_dir))
    expected_file = os.path.join(expected_fixture, output_dir_name, sample,
                                 file_name)
    expected_bai_file = os.path.join(expected_fixture, output_dir_name, sample,
                                     bai_file_name)
    if not os.path.exists(expected_file):
        pytest.skip('Skipped as expected file does not exist')
    actual_file = os.path.join(output_dir, sample, file_name)
    actual_bai_file = os.path.join(output_dir, sample, bai_file_name)
    assert os.path.exists(actual_file)
    assert os.path.exists(actual_bai_file)
    if dedup_umis:
        return
    compare_files.compare_files(expected_file, actual_file)
    compare_files.compare_files(expected_bai_file, actual_bai_file)
Example #13
0
def test_samtools_view_sort_index_pre_dedup_bam(dedup_umis, expected_fixture,
                                                tmp_dir, sample,
                                                nextflow_fixture):
    """
    Test ``samtools view | samtools sort`` BAM and ``samtools index``
    BAI files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    If UMI deduplication was not enabled in the configuration that
    produced the data then this test is skipped.

    If Nextflow tests were requested then this test is skipped.

    :param dedup_umi: Was UMI deduplication configured?
    :type dedup_umis: bool
    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    :param nextflow_fixture: Should Nextflow tests be run?
    :type nextflow_fixture: bool
    """
    if not dedup_umis:
        pytest.skip('Skipped test applicable to UMI deduplication')
    if nextflow_fixture:
        pytest.skip('Skipped test not applicable to Nextflow')
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.PRE_DEDUP_BAM),
        os.path.join(tmp_dir, sample, workflow_files.PRE_DEDUP_BAM))
    bai_file_name = sam_bam.BAI_FORMAT.format(workflow_files.PRE_DEDUP_BAM)
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample, bai_file_name),
        os.path.join(tmp_dir, sample, bai_file_name))
Example #14
0
def test_umitools_extract_fq(extract_umis, expected_fixture, tmp_dir, sample):
    """
    Test ``umi_tools extract`` FASTQ files for equality. See
    :py:func:`riboviz.compare_files.compare_files`.

    If UMI extraction was not enabled in the configuration that
    produced the data then this test is skipped.

    :param extract_umi: Was UMI extraction configured?
    :type extract_umis: bool
    :param expected_fixture: Expected data directory
    :type expected_fixture: str or unicode
    :param tmp_dir: Temporary directory, from configuration file
    :type tmp_dir: str or unicode
    :param sample: sample name
    :type sample: str or unicode
    """
    if not extract_umis:
        pytest.skip('Skipped test applicable to UMI extraction')
    tmp_dir_name = os.path.basename(os.path.normpath(tmp_dir))
    compare_files.compare_files(
        os.path.join(expected_fixture, tmp_dir_name, sample,
                     workflow_files.UMI_EXTRACT_FQ),
        os.path.join(tmp_dir, sample, workflow_files.UMI_EXTRACT_FQ))