Exemplo n.º 1
0
    def test_write_loads_pbs_template_on_initial_call(self):
        self.setup_mock_read()
        bp = BasePipe(job_name='foo')
        bp.write_script('pbs_file')

        self.assertIsNotNone(bp.pbs_template)
        self.assertEqual(bp.pbs_template, 'Hello world')
Exemplo n.º 2
0
    def test_write_does_not_load_pbs_template_on_subsequent_calls(self):
        m_open = self.setup_mock_read()
        bp = BasePipe(job_name='foo')
        with patch.object(bp, '_BasePipe__write_pbs'):
            bp.write_script('pbs_file')
            bp.write_script('pbs_file')

        self.assertEqual(m_open.call_count, 1, 'PBS template init > 1x')
Exemplo n.º 3
0
    def test_write_script_sets_pbs_file_directory(self):

        bp = BasePipe(job_name='foo')
        bp.write_script(directory='~')
        self.assertEqual(
            bp.pbs_file, os.path.join(
                path.protect('~'), 'foo_{}.pbs'.format(bp.timestamp)
            )
        )
Exemplo n.º 4
0
    def test_write_attempts_to_update_permissions_on_pbs_script(self):
        bp = BasePipe(job_name='foo')
        bp.write_script('pbs_file')

        self.mock_oschmod.assert_called_once_with(
            bp.pbs_file, self.mock_osstat().st_mode.__or__())
Exemplo n.º 5
0
    def test_write_script_sets_pbs_file_using_job_name_and_timestamp(self):

        bp = BasePipe(job_name='foo')
        bp.write_script()
        self.assertEqual(bp.pbs_file, 'foo_{}.pbs'.format(bp.timestamp))
Exemplo n.º 6
0
def pipe(file_list, genome, project_dir, force=False):

    timestamp = time.strftime("%y%m%d-%H%M%S")

    for f in file_list:
        name = f[0]
        files = f[1:]
        out_dir = os.path.join(project_dir, name)
        path.makedirs(out_dir)

        # # 1st fast qc
        # fastqc_1 = FastqcCmd(*files, o=out_dir)
        #
        # # trimming
        # out_prefix = os.path.join(out_dir, name)
        # trim = SkewerCmd(*files, o=out_prefix)
        # trimmed_fastq = trim.output()
        #
        # # 2nd fastqc
        # fastqc_2 = FastqcCmd(*trimmed_fastq, o=out_dir)
        #
        # # setup alignment
        # # NOTE: need to check for encoding
        # align_kwargs = {
        #     '-x': genome,
        #     '-S': '{}_{}.sam'.format(
        #         out_prefix,
        #         os.path.basename(genome),
        #     ),
        #     '-p': 3,  # set for local (should use pbs paramters on qsub)
        # }
        # if len(trimmed_fastq) == 1:
        #     align_kwargs['U'] = trimmed_fastq[0]
        # else:
        #     align_kwargs['1'], align_kwargs['2'] = trimmed_fastq
        # align = HisatCmd(timestamp=timestamp, **align_kwargs)
        # # human_kw = [m for m in ['human', 'sapien', 'G37RCh'] if m in genome]
        # # if human_kw:
        # #     align = HisatCmd(timestamp=timestamp, **align_kwargs)
        # # else:
        # #     align = Bowtie2Cmd(timestamp=timestamp, **align_kwargs)
        #
        # # samtools
        # sam_sort = SamtoolsSortCmd(*(align.output()))
        # sam_index = SamtoolsIndexCmd(*(sam_sort.output()))

        # UPDATED
        fastqc_1 = FastqcCmd(*files, o=out_dir)

        # trimming
        out_prefix = os.path.join(out_dir, name)
        trim = SkewerCmd(*files, o=out_prefix)

        # 2nd fastqc
        fastqc_2 = FastqcCmd(o=out_dir)

        # setup alignment
        # NOTE: need to check for encoding
        align_kwargs = {
            '-x': genome,
            '-S': '{}_{}.sam'.format(
                out_prefix,
                os.path.basename(genome),
            ),
            '-p': 3,  # set for local (should use pbs paramters on qsub)
        }
        align = HisatCmd(timestamp=timestamp, **align_kwargs)

        # samtools
        sam_sort = SamtoolsSortCmd()
        sam_index = SamtoolsIndexCmd()

        # count
        kwargs = {'-bed': genome}
        bedtools_multicov = BedtoolsMulticovCmd(**kwargs)

        # Setup pipe
        # NOTE: This is the alpha test of the pipe class.
        job_name = name + '_' + os.path.basename(genome)
        pipe = BasePipe(job_name=job_name, force=force)
        pipe.add(
            fastqc_1, trim, fastqc_2, align, sam_sort, sam_index,
            bedtools_multicov,
        )

        # write pbs file & run
        # pbs_file = '{}  , timestamp, os.path.basename(genome))
        pipe.write_script()
        pipe.run()