def test_correct_calls_are_made(self):
		"""
		Tests that the correct arguments are passed to the method which calls the normalization 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')
		component_params.add(normalized_counts_file_prefix = 'normalized_count_matrix')
		component_params.add(normalized_counts_output_dir = '/path/to/final/norm_counts_dir')
		component_params.add(normalization_script = 'normalize.R')
		project_params.add(sample_annotation_file = '/path/to/samples.txt')
		project.add_parameters(project_params)

		m = mock.MagicMock(side_effect = [True, True])
		path = self.module.os.path
		with mock.patch.object(path, 'isfile', m):
			self.module.normalize(project, component_params)
			calls = [mock.call('normalize.R', '/path/to/raw_counts/raw_count_matrix.primary.counts', 
					'/path/to/final/norm_counts_dir/normalized_count_matrix.primary.counts', '/path/to/samples.txt' ), 
				mock.call('normalize.R', '/path/to/raw_counts/raw_count_matrix.primary.dedup.counts', 
					'/path/to/final/norm_counts_dir/normalized_count_matrix.primary.dedup.counts', '/path/to/samples.txt' )]
			self.module.call_script.assert_has_calls(calls)
Exemple #2
0
    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)
Exemple #3
0
    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)