def test_correct_calls_are_made(self): """ Tests that the correct arguments are passed to the method which calls the DESeq script. Mostly tests the path renaming, etc. """ self.module.call_script = mock.Mock() project = Project() project.raw_count_matrices = [ '/path/to/raw_counts/raw_count_matrix.primary.counts', '/path/to/raw_counts/raw_count_matrix.primary.dedup.counts' ] project_params = Params() component_params = Params() project_params.add(raw_count_matrix_file_prefix='raw_count_matrix') project_params.add(feature_counts_file_extension='counts') component_params.add(deseq_output_dir='/path/to/final/deseq_dir') component_params.add(deseq_script='deseq_original.R') project_params.add(sample_annotation_file='/path/to/samples.txt') component_params.add(deseq_output_tag='deseq') component_params.add(deseq_contrast_flag='_vs_') component_params.add(number_of_genes_for_heatmap='30') component_params.add(heatmap_file_tag='heatmap.png') project.add_parameters(project_params) project.contrasts = [('X', 'Y'), ('X', 'Z')] # construct the expected call strings: call_1 = '/path/to/raw_counts/raw_count_matrix.primary.counts /path/to/samples.txt X Y /path/to/final/deseq_dir/Y_vs_X.primary.deseq /path/to/final/deseq_dir/Y_vs_X.primary.heatmap.png 30' call_2 = '/path/to/raw_counts/raw_count_matrix.primary.counts /path/to/samples.txt X Z /path/to/final/deseq_dir/Z_vs_X.primary.deseq /path/to/final/deseq_dir/Z_vs_X.primary.heatmap.png 30' call_3 = '/path/to/raw_counts/raw_count_matrix.primary.dedup.counts /path/to/samples.txt X Y /path/to/final/deseq_dir/Y_vs_X.primary.dedup.deseq /path/to/final/deseq_dir/Y_vs_X.primary.dedup.heatmap.png 30' call_4 = '/path/to/raw_counts/raw_count_matrix.primary.dedup.counts /path/to/samples.txt X Z /path/to/final/deseq_dir/Z_vs_X.primary.dedup.deseq /path/to/final/deseq_dir/Z_vs_X.primary.dedup.heatmap.png 30' m = mock.MagicMock(side_effect=[True, True]) path = self.module.os.path with mock.patch.object(path, 'isfile', m): self.module.call_deseq(project, component_params) calls = [ mock.call('deseq_original.R', call_1), mock.call('deseq_original.R', call_2), mock.call('deseq_original.R', call_3), mock.call('deseq_original.R', call_4) ] self.module.call_script.assert_has_calls(calls)
def test_missing_countfile_raises_exception(self): """ Test one of the files is ok (the first), but the second is not found (for whatever reason). Test that we throw an exception, and that the one successful call was indeed made correctly. """ self.module.call_script = mock.Mock() project = Project() project.raw_count_matrices = [ '/path/to/raw_counts/raw_count_matrix.primary.counts', '/path/to/raw_counts/raw_count_matrix.primary.dedup.counts' ] project_params = Params() component_params = Params() project_params.add(raw_count_matrix_file_prefix='raw_count_matrix') project_params.add(feature_counts_file_extension='counts') component_params.add(deseq_output_dir='/path/to/final/deseq_dir') component_params.add(deseq_script='deseq_original.R') project_params.add(sample_annotation_file='/path/to/samples.txt') component_params.add(deseq_output_tag='deseq') component_params.add(deseq_contrast_flag='_vs_') component_params.add(number_of_genes_for_heatmap='30') component_params.add(heatmap_file_tag='heatmap.png') project.add_parameters(project_params) project.contrasts = [('X', 'Y'), ('X', 'Z')] # construct the expected call strings: call_1 = '/path/to/raw_counts/raw_count_matrix.primary.counts /path/to/samples.txt X Y /path/to/final/deseq_dir/Y_vs_X.primary.deseq /path/to/final/deseq_dir/Y_vs_X.primary.heatmap.png 30' call_2 = '/path/to/raw_counts/raw_count_matrix.primary.counts /path/to/samples.txt X Z /path/to/final/deseq_dir/Z_vs_X.primary.deseq /path/to/final/deseq_dir/Z_vs_X.primary.heatmap.png 30' m = mock.MagicMock(side_effect=[True, False]) path = self.module.os.path with mock.patch.object(path, 'isfile', m): with self.assertRaises( self.module.MissingCountMatrixFileException): self.module.call_deseq(project, component_params) calls = [ mock.call('deseq_original.R', call_1), mock.call('deseq_original.R', call_2) ] self.module.call_script.assert_has_calls(calls)
def test_fill_template(self): project = Project() parameters = { 'bam_filter_level': 'sort.primary', 'project_directory': 'abc/foo/AB_12345', 'genome': 'hg19', 'genome_source_link': 'ftp://ftp.ensembl.org/pub/release-75/fasta/homo_sapiens/dna/', 'skip_align': False, 'skip_analysis': False } project.parameters = parameters component_params = cp.read_config( os.path.join(root, 'components', 'pdf_report', 'report.cfg'), 'COMPONENT_SPECIFIC') extra_params = cp.read_config( os.path.join(root, 'components', 'pdf_report', 'report.cfg'), 'STAR') mock_sample_ids = [ os.path.basename(x).split('.')[0] for x in glob.glob( os.path.join( 'test_data', '*' + component_params.get('coverage_file_suffix'))) ] project.samples = [Sample(x, 'X') for x in mock_sample_ids] project.contrasts = [('X', 'Y'), ('X', 'Z'), ('Y', 'Z')] component_params['report_output_dir'] = os.path.join( os.path.abspath(os.path.dirname(__file__)), test_output_dir, component_params.get('report_output_dir')) if not os.path.isdir(component_params['report_output_dir']): os.mkdir(component_params['report_output_dir']) # link figures so they appear where they should be. figure_list = glob.glob( os.path.join(os.path.dirname(__file__), 'test_data', '*' + component_params.get('coverage_plot_suffix'))) figure_list += [ os.path.join(os.path.dirname(__file__), 'test_data', 'bamfile_reads.pdf'), os.path.join(os.path.dirname(__file__), 'test_data', 'mapping_composition.pdf'), os.path.join(os.path.dirname(__file__), 'test_data', 'total_reads.pdf'), os.path.join('components', 'pdf_report', 'igv_typical.png'), os.path.join('components', 'pdf_report', 'igv_duplicates.png') ] [ os.symlink( os.path.join(root, f), os.path.join(component_params['report_output_dir'], os.path.basename(f))) for f in figure_list ] self.module.get_diff_exp_gene_summary = mock.Mock() self.module.get_diff_exp_gene_summary.return_value = [[ 'X', 'Y', 100, 200 ], ['Y_1', 'Z_2', 400, 300], ['X_2', 'Z_3', 150, 300]] env = jinja2.Environment(loader=jinja2.FileSystemLoader( os.path.join(root, 'components', 'pdf_report'))) template = env.get_template(component_params.get('report_template')) self.module.fill_template(template, project, component_params) self.module.compile_report(project, component_params)