Example #1
0
def test_validate_dir_option_raises_exception_for_non_existing_dir_if_dir_should_exist():
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    with pytest.raises(SchemaError):
        validate_dir_option(dir_path, "dummy")
Example #2
0
def test_run_in_directory_executes_command_in_directory():
    with temp_dir_created() as dirname:
        _write_and_run_script(dirname, "pwd > out.txt")

        with open(dirname + os.path.sep + 'out.txt') as f:
            path = f.readlines()[0].strip()
            assert path == dirname
Example #3
0
def test_write_flux_simulator_params_files_writes_correct_params_when_paired_ends_are_specified():
    with temp_dir_created() as dirname:
        _write_flux_simulator_params_files(dirname, paired_end=True)

        d = _get_simulation_params_dict(dirname)
        assert d["PAIRED_END"] == "YES"
        assert d["UNIQUE_IDS"] == "YES"
Example #4
0
def test_read_directory_checker_returns_correct_checker_if_directory_shouldnt_exist_and_doesnt_exist():
    with utils.temp_dir_created() as temp_dir:
        test_options = _get_test_options(temp_dir)

        directory_checker = piq._reads_directory_checker(False)
        directory_checker(_get_logger(), test_options,
                          **get_test_qr_options())
Example #5
0
def test_run_in_directory_executes_command_in_directory():
    with utils.temp_dir_created() as dirname:
        _write_and_run_script(dirname, "pwd > out.txt")

        with open(dirname + os.path.sep + 'out.txt') as f:
            path = f.readlines()[0].strip()
            assert path == os.path.realpath(dirname)
Example #6
0
def test_validate_dir_option_does_not_raise_exception_for_non_existing_dir_if_dir_should_not_exist(
):
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    validate_dir_option(dir_path, "dummy", should_exist=False)
Example #7
0
def test_validate_dir_option_raises_exception_for_non_existing_dir_if_dir_should_exist(
):
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    with pytest.raises(SchemaError):
        validate_dir_option(dir_path, "dummy")
Example #8
0
def test_read_directory_checker_returns_correct_checker_if_directory_should_exist_and_doesnt_exist():
    with utils.temp_dir_created() as temp_dir:
        test_options = _get_test_options(temp_dir)

        directory_checker = piq._reads_directory_checker(True)
        with pytest.raises(SystemExit):
            directory_checker(_get_logger(), test_options,
                              **get_test_qr_options())
Example #9
0
def test_prepare_quantification_creates_correct_file():
    with utils.temp_dir_created() as dir_path:
        options = _get_test_options(dir_path)
        qr_options = get_test_qr_options(quant_method=quant._Cufflinks())
        piq._prepare_quantification(
            _get_logger(), options, **qr_options)

        quant_dir = piq._get_options_dir(True, options, **qr_options)
        _check_file_exists(quant_dir, "run_quantification.sh")
Example #10
0
def test_prepare_read_simulation_creates_correct_files():
    with utils.temp_dir_created() as dir_path:
        options = _get_test_options(dir_path)
        qr_options = get_test_qr_options()
        piq._prepare_read_simulation(_get_logger(), options, **qr_options)

        reads_dir = piq._get_options_dir(False, options, **qr_options)
        _check_file_exists(reads_dir, "run_simulation.sh")
        _check_file_exists(reads_dir, "flux_simulator_main_expression.par")
        _check_file_exists(reads_dir, "flux_simulator_main_simulation.par")
Example #11
0
def test_validate_dir_option_exception_message_contains_correct_info():
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    msg = "dummy"
    with pytest.raises(SchemaError) as exc_info:
        validate_dir_option(dir_path, msg)

    check_exception_message(exc_info, msg, dir_path)
Example #12
0
def test_validate_dir_option_exception_message_contains_correct_info():
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    msg = "dummy"
    with pytest.raises(SchemaError) as exc_info:
        validate_dir_option(dir_path, msg)

    check_exception_message(exc_info, msg, dir_path)
Example #13
0
def test_write_flux_simulator_params_files_writes_correct_common_params():
    with temp_dir_created() as dirname:
        _write_flux_simulator_params_files(dirname)

        for d in [_get_expression_params_dict(dirname),
                  _get_simulation_params_dict(dirname)]:
            assert d["REF_FILE_NAME"] == TRANSCRIPT_GTF_FILE
            assert d["GEN_DIR"] == GENOME_FASTA_DIR
            assert d["NB_MOLECULES"] == str(NUM_MOLECULES)
            assert d["POLYA_SCALE"] == "NaN"
            assert d["POLYA_SHAPE"] == "NaN"
def test_write_flux_simulator_params_files_writes_correct_simulation_params():
    with temp_dir_created() as dirname:
        _write_flux_simulator_params_files(dirname)

        d = _get_simulation_params_dict(dirname)
        assert d["SEQ_FILE_NAME"] == fs.SIMULATED_READS_PREFIX + ".bed"
        assert d["PRO_FILE_NAME"] == fs.EXPRESSION_PROFILE_FILE
        assert d["FASTA"] == "YES"
        assert d["READ_NUMBER"] == fs.READ_NUMBER_PLACEHOLDER
        assert d["READ_LENGTH"] == str(READ_LENGTH)
        assert d["PCR_DISTRIBUTION"] == "none"
        assert "PAIRED_END" not in d
        assert "UNIQUE_IDS" not in d
        assert "ERR_FILE" not in d
Example #15
0
def test_create_reads_executes_run_simulation_script():
    with utils.temp_dir_created() as dir_path:
        options = _get_test_options(dir_path)
        qr_options = get_test_qr_options()

        reads_dir = piq._get_options_dir(False, options, **qr_options)
        os.mkdir(reads_dir)

        test_filename = "test"
        utils.write_executable_script(
            reads_dir, "run_simulation.sh", "touch " + test_filename)

        piq._create_reads(_get_logger(), options, **qr_options)
        time.sleep(0.1)

        assert os.path.exists(reads_dir + os.path.sep + test_filename)
Example #16
0
def test_write_flux_simulator_params_files_writes_correct_simulation_params():
    with temp_dir_created() as dirname:
        _write_flux_simulator_params_files(dirname)

        spd = _get_simulation_params_dict(dirname)
        assert spd["SEQ_FILE_NAME"] == \
            "main_" + fs.SIMULATED_READS_PREFIX + ".bed"
        assert spd["PRO_FILE_NAME"] == \
            fs.get_expression_profile_file(fs.MAIN_TRANSCRIPTS)
        assert spd["FASTA"] == "YES"
        assert spd["READ_NUMBER"] == fs.READ_NUMBER_PLACEHOLDER
        assert spd["READ_LENGTH"] == str(READ_LENGTH)
        assert spd["PCR_DISTRIBUTION"] == "none"
        assert "PAIRED_END" not in spd
        assert "UNIQUE_IDS" not in spd
        assert "ERR_FILE" not in spd
Example #17
0
def test_run_in_directory_include_command_line_args():
    with utils.temp_dir_created() as dirname:
        ps.run_in_directory(dirname, "touch", [SCRIPT_NAME])
        time.sleep(0.1)
        assert os.path.exists(dirname + os.path.sep + SCRIPT_NAME)
Example #18
0
def test_validate_dir_option_does_not_raise_exception_for_existing_dir_if_dir_should_exist(
):
    with temp_dir_created() as dir_path:
        validate_dir_option(dir_path, "dummy")
Example #19
0
def test_run_in_directory_include_command_line_args():
    with temp_dir_created() as dirname:
        ps.run_in_directory(dirname, "touch", [SCRIPT_NAME])
        time.sleep(0.1)
        assert os.path.exists(dirname + os.path.sep + SCRIPT_NAME)
Example #20
0
def test_validate_dir_option_raises_exception_for_existing_dir_if_dir_should_not_exist():
    with temp_dir_created() as dir_path:
        with pytest.raises(SchemaError):
            validate_dir_option(dir_path, "dummy", should_exist=False)
Example #21
0
def test_validate_dir_option_does_not_raise_exception_for_non_existing_dir_if_dir_should_not_exist():
    dir_path = None
    with temp_dir_created() as dp:
        dir_path = dp

    validate_dir_option(dir_path, "dummy", should_exist=False)
Example #22
0
def test_write_flux_simulator_params_files_writes_simulation_params_file():
    with temp_dir_created() as dirname:
        _write_flux_simulator_params_files(dirname)
        assert os.path.exists(_get_simulation_params_file(dirname))
Example #23
0
def test_validate_dir_option_raises_exception_for_existing_dir_if_dir_should_not_exist(
):
    with temp_dir_created() as dir_path:
        with pytest.raises(SchemaError):
            validate_dir_option(dir_path, "dummy", should_exist=False)
Example #24
0
def test_validate_dir_option_does_not_raise_exception_for_existing_dir_if_dir_should_exist():
    with temp_dir_created() as dir_path:
        validate_dir_option(dir_path, "dummy")