コード例 #1
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)
コード例 #2
0
    def test_system_call_to_bedtools(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

        mock_dir = '/abc/def/'
        mock_sample_names = ['AAA', 'BBB', 'CCC']
        levels = ['sort.bam', 'sort.primary.bam', 'sort.primary.dedup.bam']

        all_samples = []
        for sn in mock_sample_names:
            bamfiles = map(lambda x: os.path.join(mock_dir, sn + '.' + x),
                           levels)
            s = Sample(sn, 'X', bamfiles=bamfiles)
            all_samples.append(s)

        project.samples = all_samples

        component_params = cp.read_config(
            os.path.join(root, 'components', 'pdf_report', 'report.cfg'),
            'COMPONENT_SPECIFIC')

        self.module.subprocess.Popen = mock.Mock()

        mock_process = mock.Mock()
        mock_process.communicate.return_value = (('abc', 'def'))
        mock_process.returncode = 0
        self.module.subprocess.Popen.return_value = mock_process
        self.module.subprocess.STDOUT = 'abc'
        self.module.subprocess.STDERR = 'def'

        m = mock.mock_open()
        with mock.patch.object(__builtin__, 'open', m) as x:
            expected_calls = [
                mock.call([
                    component_params.get('bedtools_path'),
                    component_params.get('bedtools_cmd'), '-ibam',
                    '/abc/def/AAA.sort.primary.bam', '-bga'
                ],
                          stderr='abc',
                          stdout=m()),
                mock.call().communicate(),
                mock.call([
                    component_params.get('bedtools_path'),
                    component_params.get('bedtools_cmd'), '-ibam',
                    '/abc/def/BBB.sort.primary.bam', '-bga'
                ],
                          stderr='abc',
                          stdout=m()),
                mock.call().communicate(),
                mock.call([
                    component_params.get('bedtools_path'),
                    component_params.get('bedtools_cmd'), '-ibam',
                    '/abc/def/CCC.sort.primary.bam', '-bga'
                ],
                          stderr='abc',
                          stdout=m()),
                mock.call().communicate()
            ]
            self.module.calculate_coverage_data(project, component_params)

        self.module.subprocess.Popen.assert_has_calls(expected_calls)
コード例 #3
0
    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)