def test_bad_bamfile_path_raises_exception(self):

        self.module.subprocess = mock.Mock()

        p = Params()
        p.add(gtf='/path/to/GTF/mock.gtf')
        p.add(feature_counts='/path/to/bin/featureCounts')
        p.add(feature_counts_file_extension='counts')
        p.add(feature_counts_output_dir='/path/to/final/featureCounts')
        p.add(paired_alignment=False)

        s1 = Sample('A', 'X')
        s1.bamfiles = [
            '/path/to/bamdir/A.bam', '/path/to/bamdir/A.primary.bam',
            '/path/to/bamdir/A.primary.dedup.bam'
        ]
        s2 = Sample('B', 'X')
        s2.bamfiles = ['/path/to/bamdir/B.bam', '/bad/path/B.sort.bam']

        project = Project()
        project.add_parameters(p)
        project.add_samples([s1, s2])

        m = mock.MagicMock(side_effect=[True, True, True, True, False])
        path = self.module.os.path
        with mock.patch.object(path, 'isfile', m):
            with self.assertRaises(self.module.MissingBamFileException):
                self.module.execute_counting(project, util_methods)
Пример #2
0
    def test_alignment_calls(self):

        mock_process = mock.Mock(name='mock_process')
        mock_process.communicate.return_value = (('', ''))
        mock_process.returncode = 0

        mock_popen = mock.Mock(name='mock_popen')
        mock_popen.return_value = mock_process

        self.module.subprocess = mock.Mock()
        self.module.subprocess.Popen = mock_popen
        self.module.subprocess.STDOUT = ''
        self.module.subprocess.PIPE = ''

        self.module.os.chmod = mock.Mock()
        self.module.assert_memory_reasonable = mock.Mock()
        self.module.assert_memory_reasonable.return_value = True
        p = Params()
        p.add(wait_length='10')
        p.add(wait_cycles='50')
        p.add(min_memory='40')
        paths = ['/path/to/a.sh', '/path/to/b.sh']
        self.module.execute_alignments(paths, p)

        calls = [
            mock.call('/path/to/a.sh',
                      shell=True,
                      stderr=self.module.subprocess.STDOUT,
                      stdout=self.module.subprocess.PIPE),
            mock.call('/path/to/b.sh',
                      shell=True,
                      stderr=self.module.subprocess.STDOUT,
                      stdout=self.module.subprocess.PIPE)
        ]
        self.module.subprocess.Popen.assert_has_calls(calls)
Пример #3
0
    def test_alignment_call_raises_exception(self):
        import subprocess

        mock_process = mock.Mock(name='mock_process')
        mock_process.communicate.return_value = (('', ''))
        mock_process.returncode = 1

        mock_popen = mock.Mock(name='mock_popen')
        mock_popen.return_value = mock_process

        self.module.subprocess = mock.Mock()
        self.module.subprocess.Popen = mock_popen
        self.module.subprocess.STDOUT = ''
        self.module.subprocess.PIPE = ''

        self.module.os.chmod = mock.Mock()
        self.module.assert_memory_reasonable = mock.Mock()
        self.module.assert_memory_reasonable.return_value = True
        p = Params()
        p.add(wait_length='10')
        p.add(wait_cycles='50')
        p.add(min_memory='40')
        paths = ['/path/to/a.sh', '/path/to/b.sh']
        with self.assertRaises(self.module.AlignmentScriptErrorException):
            self.module.execute_alignments(paths, p)

        # assert that the second script was not called due to the first one failing.
        calls = [
            mock.call('/path/to/a.sh',
                      shell=True,
                      stderr=self.module.subprocess.STDOUT,
                      stdout=self.module.subprocess.PIPE)
        ]
        self.module.subprocess.Popen.assert_has_calls(calls)
Пример #4
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')
		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, False])
		path = self.module.os.path
		with mock.patch.object(path, 'isfile', m):
			with self.assertRaises(self.module.MissingCountMatrixFileException):
				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' )]
			self.module.call_script.assert_has_calls(calls)
Пример #5
0
 def test_add_multiple_key_value_pairs(self):
     p = Params()
     v1 = "some_value"
     v2 = "other_value"
     p.add(key1=v1, key2=v2)
     self.assertEqual(p.get("key1"), v1)
     self.assertEqual(p.get("key2"), v2)
Пример #6
0
    def test_asking_for_missing_value_kills_pipeline(self):
        p = Params()

        # add some value. Not necessary to do this.
        v = "some_value"
        p.add(key=v)
        self.assertRaises(ParameterNotFoundException, p.get, "missing_val")
Пример #7
0
	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)
Пример #8
0
 def test_add_multiple_dicts(self):
     p = Params()
     d1 = {"a": 1, "b": 2}
     d2 = {"c": 3, "d": 4}
     p.add(d1, d2)
     self.assertEqual(p.get("a"), 1)
     self.assertEqual(p.get("b"), 2)
     self.assertEqual(p.get("c"), 3)
     self.assertEqual(p.get("d"), 4)
Пример #9
0
    def test_add_both_simultaneously(self):
        p = Params()
        v = "some_value"
        d = {"a": 1, "b": 2}

        p.add(d, key=v)

        self.assertEqual(p.get("a"), 1)
        self.assertEqual(p.get("b"), 2)
        self.assertEqual(p.get("key"), v)
    def test_group_countfiles_raises_exception_if_missing_type(self):
        """
		Test the method that aggregates all the countfiles generated from each 'type' of bam file.  That is, we may have multiple bam files for each sample (e.g. primary alignments, deduplicated, etc).
		We will be generating a countfile for each one of those.  When we assemble into a count matrix, we obviously group the files of a particular 'type' (e.g. those coming from deduplicated BAM files).
		This tests that the the glob methods are called with the correct parameters given the sample annotations prescribed.

		This one tests that an exception is raised if one of the countfile 'types' is missing.  Here, sample B is missing a countfile corresponding to the primary.counts- based BAM files
		"""

        p = Params()
        p.add(feature_counts_output_dir='/path/to/final/featureCounts')

        s1 = Sample('A', 'X')
        s1.countfiles = [
            '/path/to/final/featureCounts/A.counts',
            '/path/to/final/featureCounts/A.primary.counts',
            '/path/to/final/featureCounts/A.primary.dedup.counts'
        ]
        s2 = Sample('B', 'Y')
        s2.countfiles = [
            '/path/to/final/featureCounts/B.counts',
            '/path/to/final/featureCounts/B.primary.dedup.counts'
        ]
        s3 = Sample('C', 'Z')
        s3.countfiles = [
            '/path/to/final/featureCounts/C.counts',
            '/path/to/final/featureCounts/C.primary.counts',
            '/path/to/final/featureCounts/C.primary.dedup.counts'
        ]

        project = Project()
        project.add_parameters(p)
        project.add_samples([s1, s2, s3])

        mock_util_methods = mock.Mock()
        mock_case_insensitive_glob = mock.Mock()
        mock_case_insensitive_glob.side_effect = [
            [
                '/path/to/final/featureCounts/A.counts',
                '/path/to/final/featureCounts/B.counts',
                '/path/to/final/featureCounts/C.counts'
            ],
            [
                '/path/to/final/featureCounts/A.primary.counts',
                '/path/to/final/featureCounts/C.primary.counts'
            ],
            [
                '/path/to/final/featureCounts/A.primary.dedup.counts',
                '/path/to/final/featureCounts/B.primary.dedup.counts',
                '/path/to/final/featureCounts/C.primary.dedup.counts'
            ]
        ]
        with self.assertRaises(self.module.CountfileQuantityException):
            result = self.module.get_countfile_groupings(
                project, mock_case_insensitive_glob)
Пример #11
0
    def test_raises_exception_if_adding_param_objects_with_same_values(self):
        """
		This tests the operator overload of '+'
		"""
        p1 = Params()
        p1.add(a=1, b=2)
        p2 = Params()
        p2.add(a=3, d=4)

        with self.assertRaises(ParameterOverwriteException):
            p3 = p1 + p2
Пример #12
0
    def test_group_countfiles(self):
        """
		Test the method that aggregates all the countfiles generated from each 'type' of bam file.  That is, we may have multiple bam files for each sample (e.g. primary alignments, deduplicated, etc).
		We will be generating a countfile for each one of those.  When we assemble into a count matrix, we obviously group the files of a particular 'type' (e.g. those coming from deduplicated BAM files).
		This tests that the the glob methods are called with the correct parameters given the sample annotations prescribed.
		"""

        p = Params()
        cp = Params()
        cp.add(feature_counts_output_dir='/path/to/final/featureCounts')

        s1 = Sample('A', 'X')
        s1.countfiles = [
            '/path/to/final/featureCounts/A.counts',
            '/path/to/final/featureCounts/A.primary.counts',
            '/path/to/final/featureCounts/A.primary.dedup.counts'
        ]
        s2 = Sample('B', 'Y')
        s2.countfiles = [
            '/path/to/final/featureCounts/B.counts',
            '/path/to/final/featureCounts/B.primary.counts',
            '/path/to/final/featureCounts/B.primary.dedup.counts'
        ]
        s3 = Sample('C', 'Z')
        s3.countfiles = [
            '/path/to/final/featureCounts/C.counts',
            '/path/to/final/featureCounts/C.primary.counts',
            '/path/to/final/featureCounts/C.primary.dedup.counts'
        ]

        project = Project()
        project.add_parameters(p)
        project.add_samples([s1, s2, s3])

        result = self.module.get_countfile_groupings(project, cp)
        expected_result = [
            [
                '/path/to/final/featureCounts/A.counts',
                '/path/to/final/featureCounts/B.counts',
                '/path/to/final/featureCounts/C.counts'
            ],
            [
                '/path/to/final/featureCounts/A.primary.counts',
                '/path/to/final/featureCounts/B.primary.counts',
                '/path/to/final/featureCounts/C.primary.counts'
            ],
            [
                '/path/to/final/featureCounts/A.primary.dedup.counts',
                '/path/to/final/featureCounts/B.primary.dedup.counts',
                '/path/to/final/featureCounts/C.primary.dedup.counts'
            ]
        ]
        self.assertEqual(result, expected_result)
	def test_samples_created_correctly_for_skipping_align(self, mock_find_files, mock_parse_method):
		"""
		Tests the case where we want to skip alignment and the target suffix is given for the BAM files
		In this test, the call to the find_file method is mocked out with a dummy return value
		"""
		# list of tuples linking the sample names and conditions:
		pairings = [('A', 'X'),('B', 'X'),('C', 'Y')]
		mock_parse_method.return_value = pairings
		
		# mock the find_file() method returning some paths to bam files:
		bamfiles = [['A.sort.bam'],['B.sort.bam'],['C.sort.bam']]
		mock_find_files.side_effect = bamfiles

		# setup all the necessary parameters that the method will look at:
		p = PipelineBuilder('')
		p.all_samples = []
		mock_pipeline_params = Params()
		mock_pipeline_params.add(project_directory = '/path/to/project_dir')
		mock_pipeline_params.add(sample_annotation_file = '/path/to/project_dir/samples.txt')
		mock_pipeline_params.add(skip_align = True)
		mock_pipeline_params.add(target_bam = 'sort.bam')
		p.builder_params = mock_pipeline_params

		p._PipelineBuilder__check_and_create_samples()
		for i,s in enumerate(p.all_samples):
			self.assertTrue(s.sample_name == pairings[i][0])
			self.assertTrue(s.read_1_fastq == None)
			self.assertTrue(s.read_2_fastq == None)
			self.assertTrue(s.bamfiles == bamfiles[i] )
Пример #14
0
    def test_addition_of_param_objects(self):
        """
		This tests the operator overload of '+'
		"""
        p1 = Params()
        p1.add(a=1, b=2)
        p2 = Params()
        p2.add(c=3, d=4)

        p3 = p1 + p2
        self.assertEqual(p3.get("a"), 1)
        self.assertEqual(p3.get("b"), 2)
        self.assertEqual(p3.get("c"), 3)
        self.assertEqual(p3.get("d"), 4)
	def test_bad_genome_parameter_raises_exception(self, mock_os):
		"""
		Pass a genome parameter that is not in the genomes directory
		"""

		p = PipelineBuilder('/path/to/dir')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(genomes_dir = 'genome_info', genome = 'XYZ')
		p.builder_params = mock_pipeline_params

		mock_os.listdir.return_value = ['hg19.cfg', 'mm10.cfg']			

		with self.assertRaises(IncorrectGenomeException):
			p._PipelineBuilder__check_genome_valid()
Пример #16
0
    def test_raises_exception_if_skipping_align_and_pairing_not_specified(
            self, mock_find_files, mock_parse_method):
        """
		Tests the case where we want to skip alignment and the user has not given whether the BAM files were created
		from paired or unpaired protocol
		"""
        # list of tuples linking the sample names and conditions:
        pairings = [('A', 'X'), ('B', 'X'), ('C', 'Y')]
        mock_parse_method.return_value = pairings

        # mock the find_file() method returning some paths to bam files:
        bamfiles = [['A.sort.bam'], ['B.sort.bam'], ['C.sort.bam']]
        mock_find_files.side_effect = bamfiles

        # setup all the necessary parameters that the method will look at:
        p = PipelineBuilder('')
        p.all_samples = []
        mock_pipeline_params = Params()
        mock_pipeline_params.add(project_directory='/path/to/project_dir')
        mock_pipeline_params.add(
            sample_annotation_file='/path/to/project_dir/samples.txt')
        mock_pipeline_params.add(skip_align=True)
        mock_pipeline_params.add(target_bam='sort.bam')
        p.builder_params = mock_pipeline_params

        with self.assertRaises(ParameterNotFoundException):
            p._PipelineBuilder__check_and_create_samples()
Пример #17
0
	def test_general_portion_of_template_injected_correctly(self):
		template = 'STAR=%STAR%\nSAMTOOLS=%SAMTOOLS%\nPICARD_DIR=%PICARD_DIR%\nGTF=%GTF%\nGENOME_INDEX=%GENOME_INDEX%'
		expected_result = 'STAR=STARPATH\nSAMTOOLS=SAM\nPICARD_DIR=PIC\nGTF=my.gtf\nGENOME_INDEX=GI'
		p = Params()
		p.add(star_align = 'STARPATH')
		p.add(samtools = 'SAM')
		p.add(gtf = 'my.gtf')
		p.add(star_genome_index= 'GI')
		p.add(picard = 'PIC') 
		myproject = Project()
		myproject.parameters = p

		result = self.module.fill_out_general_template_portion(myproject, template)
		self.assertEqual( result, expected_result)
	def test_samples_created_correctly_for_skipping_align_with_mocked_directory_structure(self, mock_os, mock_join, mock_parse_method):
		"""
		Tests the case where we want to skip alignment and the target suffix is given for the BAM files
		In this case, we mock the return value from os.walk() and make the actual call to the find_files() method
		"""
		# list of tuples linking the sample names and conditions:
		pairings = [('A', 'X'),('B', 'X'),('C', 'Y')]
		mock_parse_method.return_value = pairings
		
		# mock the find_files() method returning some paths to bam files:
		bamfiles = ['/path/to/project/dir/Sample_A/A.sort.primary.bam','/path/to/project/dir/Sample_B/B.sort.primary.bam','/path/to/project/dir/C.sort.primary.bam']

		# setup all the necessary parameters that the method will look at:
		p = PipelineBuilder('')
		p.all_samples = []
		mock_pipeline_params = Params()
		mock_pipeline_params.add(project_directory = '/path/to/project_dir')
		mock_pipeline_params.add(sample_annotation_file = '/path/to/project_dir/samples.txt')
		mock_pipeline_params.add(skip_align = True)
		mock_pipeline_params.add(target_bam = 'sort.primary.bam')
		p.builder_params = mock_pipeline_params

		mock_os.walk.return_value = [('/path/to/project/dir', ['Sample_A', 'Sample_B'], ['C.sort.primary.bam']),
			('/path/to/project/dir/Sample_A', ['another_dir'], ['A.sort.primary.bam']),
			('/path/to/project/dir/Sample_B', [], ['B.sort.primary.bam']),
			('/path/to/project/dir/Sample_A/another_dir', [], ['A.sort.bam']),
			]

		p._PipelineBuilder__check_and_create_samples()
		for i,s in enumerate(p.all_samples):
			self.assertTrue(s.sample_name == pairings[i][0])
			self.assertTrue(s.read_1_fastq == None)
			self.assertTrue(s.read_2_fastq == None)
			self.assertTrue(s.bamfiles == [bamfiles[i]] )
	def test_creates_contrasts_correctly_with_no_contrast_file_given(self):

		#make some samples:
		all_samples = [Sample('A', 'X'), Sample('B', 'Y'), Sample('C', 'Z')]
		p = PipelineBuilder('')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(skip_analysis = False)
		mock_pipeline_params.add(contrast_file = None)
		p.builder_params = mock_pipeline_params
		p.all_samples = all_samples

		p._PipelineBuilder__check_contrast_file()
		expected_result = set([('X','Y'),('X','Z'),('Y','Z')])
		self.assertTrue(set_of_tuples_is_equivalent(p.contrasts, expected_result))
	def test_missing_pipeline_config_file(self, mock_os):
		"""
		The pipeline configuration file is missing (not likely, but possible!)
		"""
		
		p = PipelineBuilder('')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(pipeline_home = '/path/to/dir')
		p.builder_params = mock_pipeline_params

		# mock the missing config file: 
		mock_os.listdir.return_value = []

		with self.assertRaises(ConfigFileNotFoundException):
			p._PipelineBuilder__read_pipeline_config()
Пример #21
0
	def test_alignment_calls(self):
		self.module.subprocess = mock.Mock()
		self.module.os.chmod = mock.Mock()
		self.module.assert_memory_reasonable = mock.Mock()
		self.module.assert_memory_reasonable.return_value = True
		p = Params()
		p.add(wait_length = '10')
		p.add(wait_cycles = '50')
		p.add(min_memory = '40')
		paths = ['/path/to/a.sh', '/path/to/b.sh']
		self.module.execute_alignments(paths, p)

		calls = [mock.call('/path/to/a.sh', shell=True),
			mock.call('/path/to/b.sh', shell=True)]
		self.module.subprocess.check_call.assert_has_calls(calls)
	def test_missing_default_project_config_file_with_no_alternative_given(self, mock_os):
		"""
		No config file passed via commandline and none found in the project_configuration directory
		"""
		
		p = PipelineBuilder('/path/to/dir')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(project_configuration_file = None,
					project_configurations_dir = '/path/to/dir')
		p.builder_params = mock_pipeline_params

		# mock the missing config file: 
		mock_os.listdir.return_value = ['something.cfg'] # anything here, just not 'default.cfg'

		with self.assertRaises(ConfigFileNotFoundException):
			p._PipelineBuilder__check_project_config()
	def test_raises_exception_if_non_sensible_contrast_specified(self, mock_parse):

		#make some samples:
		all_samples = [Sample('A', 'X'), Sample('B', 'Y'), Sample('C', 'Z')]
		p = PipelineBuilder('')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(skip_analysis = False)
		mock_pipeline_params.add(contrast_file = 'contrast.txt')
		p.builder_params = mock_pipeline_params
		p.all_samples = all_samples

		# note the specification of a contrast of Y against A.  However, we have no samples from condition A.
		mock_parse.return_value = set([('X','Y'),('X','Z'),('Y','A')]) 

		with self.assertRaises(ContrastSpecificationException):
			p._PipelineBuilder__check_contrast_file()
    def test_system_calls_single_end_experiment(self):
        self.module.subprocess = mock.Mock()

        p = Params()
        p.add(gtf='/path/to/GTF/mock.gtf')
        p.add(feature_counts='/path/to/bin/featureCounts')
        p.add(feature_counts_file_extension='counts')
        p.add(feature_counts_output_dir='/path/to/final/featureCounts')
        p.add(paired_alignment=False)

        s1 = Sample('A', 'X')
        s1.bamfiles = [
            '/path/to/bamdir/A.bam', '/path/to/bamdir/A.primary.bam',
            '/path/to/bamdir/A.primary.dedup.bam'
        ]

        project = Project()
        project.add_parameters(p)
        project.add_samples([s1])

        m = mock.MagicMock(side_effect=[True, True, True])
        path = self.module.os.path
        with mock.patch.object(path, 'isfile', m):
            self.module.execute_counting(project, util_methods)

            calls = [
                mock.call(
                    '/path/to/bin/featureCounts -a /path/to/GTF/mock.gtf -t exon -g gene_name -o /path/to/final/featureCounts/A.counts /path/to/bamdir/A.bam',
                    shell=True),
                mock.call(
                    '/path/to/bin/featureCounts -a /path/to/GTF/mock.gtf -t exon -g gene_name -o /path/to/final/featureCounts/A.primary.counts /path/to/bamdir/A.primary.bam',
                    shell=True),
                mock.call(
                    '/path/to/bin/featureCounts -a /path/to/GTF/mock.gtf -t exon -g gene_name -o /path/to/final/featureCounts/A.primary.dedup.counts /path/to/bamdir/A.primary.dedup.bam',
                    shell=True)
            ]
            self.module.subprocess.check_call.assert_has_calls(calls)

            # check that the sample contains paths to the new count files in the correct locations:
            expected_files = [
                os.path.join('/path/to/final/featureCounts',
                             re.sub('bam', 'counts', os.path.basename(f)))
                for f in s1.bamfiles
            ]
            actual_files = s1.countfiles
            self.assertEqual(actual_files, expected_files)
Пример #25
0
    def test_alignment_call_waits_properly(self):
        import subprocess

        mock_process = mock.Mock(name='mock_process')
        mock_process.communicate.return_value = (('', ''))
        mock_process.returncode = 0

        mock_popen = mock.Mock(name='mock_popen')
        mock_popen.return_value = mock_process

        self.module.subprocess = mock.Mock()
        self.module.subprocess.Popen = mock_popen
        self.module.subprocess.STDOUT = ''
        self.module.subprocess.PIPE = ''

        self.module.os.chmod = mock.Mock()
        self.module.assert_memory_reasonable = mock.Mock()
        self.module.sleep = mock.Mock()
        self.module.assert_memory_reasonable.side_effect = [
            False, False, True, True
        ]
        p = Params()
        p.add(wait_length='10')
        p.add(wait_cycles='50')
        p.add(min_memory='40')
        paths = ['/path/to/a.sh', '/path/to/b.sh']

        self.module.execute_alignments(paths, p)

        # assert that the script was eventually called.
        calls = [
            mock.call('/path/to/a.sh',
                      shell=True,
                      stderr=self.module.subprocess.STDOUT,
                      stdout=self.module.subprocess.PIPE),
            mock.call('/path/to/b.sh',
                      shell=True,
                      stderr=self.module.subprocess.STDOUT,
                      stdout=self.module.subprocess.PIPE)
        ]
        self.module.subprocess.Popen.assert_has_calls(calls)

        # assert that it had to wait twice (via calling sleep() twice)
        calls = [mock.call(600), mock.call(600)]
        self.module.sleep.assert_has_calls(calls)
Пример #26
0
	def test_alignment_call_raises_exception(self):
		import subprocess
		self.module.subprocess = mock.Mock()
		self.module.os.chmod = mock.Mock()
		self.module.assert_memory_reasonable = mock.Mock()
		self.module.assert_memory_reasonable.return_value = True
		p = Params()
		p.add(wait_length = '10')
		p.add(wait_cycles = '50')
		p.add(min_memory = '40')
		paths = ['/path/to/a.sh', '/path/to/b.sh']
		self.module.subprocess.check_call.side_effect = [subprocess.CalledProcessError(0,'cmd'), None]
		with self.assertRaises(subprocess.CalledProcessError):
			self.module.execute_alignments(paths, p)

		# assert that the second script was not called due to the first one failing.
		calls = [mock.call('/path/to/a.sh', shell=True)]
		self.module.subprocess.check_call.assert_has_calls(calls)
	def test_bad_aligner_parameter_raises_exception(self):
		"""
		Pass a aligner parameter that is not specified in the aligners config file
		"""

		available_aligners = ('star', 'snapr')
		default_aligner = 'star'

		# create a PipelineBuilder and add mocked pipeline/project objects as patches
		p = PipelineBuilder('/path/to/dir')
		mock_pipeline_params = Params()
		mock_pipeline_params.add(available_aligners = available_aligners, 
					default_aligner = default_aligner,
					aligner='junk')
		p.builder_params = mock_pipeline_params
		p._PipelineBuilder__get_aligner_info = mock.Mock()
		
		with self.assertRaises(IncorrectAlignerException):
			p._PipelineBuilder__check_aligner_valid()
Пример #28
0
    def test_missing_aligner_config_file_raises_exception(self, mock_os):

        available_aligners = ('star', 'snapr')
        default_aligner = 'star'

        # create a PipelineBuilder and add mocked pipeline/project objects as patches
        p = PipelineBuilder('/path/to/dir')
        mock_pipeline_params = Params()
        mock_pipeline_params.add(available_aligners=available_aligners,
                                 default_aligner=default_aligner,
                                 aligner=None,
                                 aligners_dir='/path/to/dir',
                                 genome='mm9')
        p.builder_params = mock_pipeline_params
        p._PipelineBuilder__get_aligner_info = mock.Mock()

        mock_os.listdir.return_value = []

        with self.assertRaises(ConfigFileNotFoundException):
            p._PipelineBuilder__check_aligner_valid()
Пример #29
0
	def test_alignment_call_timesout_properly(self):
		import subprocess
		self.module.subprocess = mock.Mock()
		self.module.os.chmod = mock.Mock()
		self.module.assert_memory_reasonable = mock.Mock()
		self.module.sleep = mock.Mock()
		self.module.assert_memory_reasonable.side_effect = [False, False, False, False]
		p = Params()
		p.add(wait_length = '10')
		p.add(wait_cycles = '3')
		p.add(min_memory = '40')
		paths = ['/path/to/a.sh']
			
		with self.assertRaises(self.module.AlignmentTimeoutException):
			self.module.execute_alignments(paths, p)


		# assert that it had to wait the proper amount of times (via calling sleep())
		calls = [mock.call(600), mock.call(600), mock.call(600)]
		self.module.sleep.assert_has_calls(calls)
Пример #30
0
	def test_alignment_call_waits_properly(self):
		import subprocess
		self.module.subprocess = mock.Mock()
		self.module.os.chmod = mock.Mock()
		self.module.assert_memory_reasonable = mock.Mock()
		self.module.sleep = mock.Mock()
		self.module.assert_memory_reasonable.side_effect = [False, False, True, True]
		p = Params()
		p.add(wait_length = '10')
		p.add(wait_cycles = '50')
		p.add(min_memory = '40')
		paths = ['/path/to/a.sh', '/path/to/b.sh']
			
		self.module.execute_alignments(paths, p)

		# assert that the script was eventually called.
		calls = [mock.call('/path/to/a.sh', shell=True),
			mock.call('/path/to/b.sh', shell=True)]
		self.module.subprocess.check_call.assert_has_calls(calls)

		# assert that it had to wait twice (via calling sleep() twice)
		calls = [mock.call(600), mock.call(600)]
		self.module.sleep.assert_has_calls(calls)