Example #1
0
def test_genome_coverage_samples_second_scale(testdir, mock_testclass):
    samples = Path(__file__).parent.joinpath('samples.txt')
    genome = Path(__file__).parent.joinpath('sizes.txt')
    scale = 1.5
    gc.sample_splits_genome_coverage = MagicMock()
    gc.genome_coverage_samples(samples, genome, scale=scale, index=1)
    gc.sample_splits_genome_coverage.assert_called_once_with('ASDURF', genome, scale, None, '', '-cov', None, None, ())
Example #2
0
def test_genome_coverage_samples_all_three(testdir, mock_testclass):
    samples = Path(__file__).parent.joinpath('samples.txt')
    genome = Path(__file__).parent.joinpath('sizes.txt')
    gc.sample_splits_genome_coverage = MagicMock()
    gc.genome_coverage_samples(samples, genome, genomecov_args=('-3',))
    gc.sample_splits_genome_coverage.assert_any_call('POLR2A', genome, None, None, '', '-cov', None, None, ('-3',))
    gc.sample_splits_genome_coverage.assert_any_call('ASDURF', genome, None, None, '', '-cov', None, None, ('-3',))
    gc.sample_splits_genome_coverage.assert_any_call('POLR1C', genome, None, None, '', '-cov', None, None, ('-3',))
Example #3
0
def test_genome_coverage_samples(testdir, mock_testclass):
    samples = Path(__file__).parent.joinpath('samples.txt')
    genome = 'sacCer3.chrom.sizes'
    copyfile(Path(__file__).parent.joinpath('sizes.txt'), genome)
    gc.sample_splits_genome_coverage = MagicMock()
    gc.genome_coverage_samples(samples)
    gc.sample_splits_genome_coverage.assert_any_call('POLR2A', genome, None, None, '', '-cov', None, None, ())
    gc.sample_splits_genome_coverage.assert_any_call('ASDURF', genome, None, None, '', '-cov', None, None, ())
    gc.sample_splits_genome_coverage.assert_any_call('POLR1C', genome, None, None, '', '-cov', None, None, ())
Example #4
0
def test_genome_coverage_samples_all_scale_positivestrand(testdir, mock_testclass):
    samples = Path(__file__).parent.joinpath('samples.txt')
    genome = Path(__file__).parent.joinpath('sizes.txt')
    scale = 1.5
    strand = '+'
    gc.sample_splits_genome_coverage = MagicMock()
    gc.genome_coverage_samples(samples, genome, scale=scale, strand=strand)
    gc.sample_splits_genome_coverage.assert_any_call('POLR2A', genome, scale, strand, '', '-cov', None, None, ())
    gc.sample_splits_genome_coverage.assert_any_call('ASDURF', genome, scale, strand, '', '-cov', None, None, ())
    gc.sample_splits_genome_coverage.assert_any_call('POLR1C', genome, scale, strand, '', '-cov', None, None, ())
Example #5
0
def test_sample_splits_genome_coverage_three(testdir, mock_testclass):
    sample = 'POLR2A'
    genome = 'human.sizes'
    split1 = sample + '-100-110'
    split2 = sample + '-110-120'
    sb.splits = MagicMock(return_value=[split1, split2])
    gc.genome_coverage = MagicMock()
    gc.sample_splits_genome_coverage(sample, genome, genomecov_args=('-3'))
    sb.splits.assert_called_once_with(sample)
    gc.genome_coverage.assert_any_call(sample, genome, None, None, '', '-cov', None, None, ('-3'))
    gc.genome_coverage.assert_any_call(split1, genome, None, None, '', '-cov', None, None, ('-3'))
    gc.genome_coverage.assert_any_call(split2, genome, None, None, '', '-cov', None, None, ('-3'))
Example #6
0
def test_coverage_three(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    output = sample + '-out.bed'
    genome = 'human.sizes'
    subprocess.run = MagicMock(side_effect=create_file)
    Bed.sort = MagicMock(side_effect=create_file_sort)
    gc.coverage(bed, output, genome, sample, genomecov_args=('-3',))
    subprocess.run.assert_called_once_with(['bedtools', 'genomecov', '-bg', '-i', bed, '-g', genome, '-3'], stdout=ANY, check=True)
    Bed.sort.assert_called_once_with(ANY, ANY)
    with open(output, 'r') as infile:
        assert infile.readline() == 'track type=bedGraph name="' + sample + '"\n'
        assert infile.readline() == 'test'
Example #7
0
def test_sample_splits_genome_coverage_positivestrand(testdir, mock_testclass):
    sample = 'POLR2A'
    genome = 'human.sizes'
    split1 = sample + '-100-110'
    split2 = sample + '-110-120'
    strand = '+'
    sb.splits = MagicMock(return_value=[split1, split2])
    gc.genome_coverage = MagicMock()
    gc.sample_splits_genome_coverage(sample, genome, strand=strand)
    sb.splits.assert_called_once_with(sample)
    gc.genome_coverage.assert_any_call(sample, genome, None, strand, '', '-cov', None, None, ())
    gc.genome_coverage.assert_any_call(split1, genome, None, strand, '', '-cov', None, None, ())
    gc.genome_coverage.assert_any_call(split2, genome, None, strand, '', '-cov', None, None, ())
Example #8
0
def test_genome_coverage_scale(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    cov = sample + '-cov.bed'
    bw = sample + '-cov.bw'
    genome = 'human.sizes'
    scale = 1.5
    Bed.count_bed = MagicMock()
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, scale=scale)
    Bed.count_bed.assert_not_called()
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, scale, None, ())
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)
Example #9
0
def test_genome_coverage_three(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    cov = sample + '-cov.bed'
    bw = sample + '-cov.bw'
    genome = 'human.sizes'
    count = 2000000
    Bed.count_bed = MagicMock(return_value=count)
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, genomecov_args=('-3'))
    Bed.count_bed.assert_called_once_with(bed)
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, BASE_SCALE / count, None, ('-3'))
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)
Example #10
0
def test_genome_coverage_positivestrand(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    cov = sample + '-cov-pos.bed'
    bw = sample + '-cov-pos.bw'
    genome = 'human.sizes'
    strand = '+'
    count = 2000000
    Bed.count_bed = MagicMock(return_value=count)
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, scale=None, strand=strand)
    Bed.count_bed.assert_called_once_with(bed)
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, BASE_SCALE / count, strand, ())
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)
Example #11
0
def test_genome_coverage_samples_parameters(testdir, mock_testclass):
    samples = Path(__file__).parent.joinpath('samples.txt')
    genome = 'sacCer3.chrom.sizes'
    copyfile(Path(__file__).parent.joinpath('sizes.txt'), genome)
    scale = 1.5
    strand = '+'
    input_suffix = '-forcov'
    output_suffix = '-outcov'
    spike_suffix = '-pombe'
    control_suffix = '-input'
    gc.sample_splits_genome_coverage = MagicMock()
    gc.genome_coverage_samples(samples, genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, genomecov_args=('-5',))
    gc.sample_splits_genome_coverage.assert_any_call('POLR2A', genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
    gc.sample_splits_genome_coverage.assert_any_call('ASDURF', genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
    gc.sample_splits_genome_coverage.assert_any_call('POLR1C', genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
Example #12
0
def test_genome_coverage_suffix(testdir, mock_testclass):
    sample = 'POLR2A'
    input_suffix = '-forcov'
    output_suffix = '-outcov'
    bed = sample + input_suffix + '.bed'
    cov = sample + output_suffix + '.bed'
    bw = sample + output_suffix + '.bw'
    genome = 'human.sizes'
    count = 2000000
    Bed.count_bed = MagicMock(return_value=count)
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, input_suffix=input_suffix, output_suffix=output_suffix)
    Bed.count_bed.assert_called_once_with(bed)
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, BASE_SCALE / count, None, ())
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)
Example #13
0
def test_sample_splits_genome_coverage_parameters(testdir, mock_testclass):
    sample = 'POLR2A'
    genome = 'human.sizes'
    split1 = sample + '-100-110'
    split2 = sample + '-110-120'
    scale = 1.5
    strand = '+'
    input_suffix = '-forcov'
    output_suffix = '-outcov'
    spike_suffix = '-pombe'
    control_suffix = '-input'
    sb.splits = MagicMock(return_value=[split1, split2])
    gc.genome_coverage = MagicMock()
    gc.sample_splits_genome_coverage(sample, genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
    sb.splits.assert_called_once_with(sample)
    gc.genome_coverage.assert_any_call(sample, genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
    gc.genome_coverage.assert_any_call(split1, genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
    gc.genome_coverage.assert_any_call(split2, genome, scale, strand, input_suffix, output_suffix, spike_suffix, control_suffix, ('-5',))
Example #14
0
def test_genome_coverage_scale_and_controlsuffix(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    cov = sample + '-cov.bed'
    bw = sample + '-cov.bw'
    genome = 'human.sizes'
    control_suffix = '-input'
    control = sample + control_suffix + '.bed'
    count = 2000000
    control_count = 300000
    scale = BASE_SCALE / (count * control_count)
    Bed.count_bed = MagicMock(side_effect=[count, control_count])
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, scale=1.5, control_suffix=control_suffix)
    Bed.count_bed.assert_any_call(bed)
    Bed.count_bed.assert_any_call(control)
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, scale, None, ())
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)
Example #15
0
def test_genome_coverage_scale_and_spikesuffix(testdir, mock_testclass):
    sample = 'POLR2A'
    bed = sample + '.bed'
    cov = sample + '-cov.bed'
    bw = sample + '-cov.bw'
    genome = 'human.sizes'
    spike_suffix = '-pombe'
    spiked = sample + spike_suffix + '.bed'
    count = 2000000
    spiked_count = 400000
    scale = BASE_SCALE * spiked_count / count
    Bed.count_bed = MagicMock(side_effect=[count, spiked_count])
    gc.coverage = MagicMock()
    Bed.bedgraph_to_bigwig = MagicMock()
    gc.genome_coverage(sample, genome, scale=1.5, spike_suffix=spike_suffix)
    Bed.count_bed.assert_any_call(bed)
    Bed.count_bed.assert_any_call(spiked)
    gc.coverage.assert_called_once_with(bed, cov, genome, sample, scale, None, ())
    Bed.bedgraph_to_bigwig.assert_called_once_with(cov, bw, genome)