예제 #1
0
    def test_pipe_may_be_used_as_command(self):
        a = self.mock_cmd()
        b = self.mock_cmd()
        subpipe = BasePipe()
        subpipe.add(a, b)

        pipe = BasePipe()
        pipe.add(a, subpipe)  # should not raise
예제 #2
0
    def test_add_links_commands(self):
        bp = BasePipe()
        a = self.mock_cmd()
        b = self.mock_cmd()

        bp.add(a, b)

        a.link.assert_called_once_with(b)
예제 #3
0
    def test_add_supports_chaining(self):
        bp = BasePipe()
        a = self.mock_cmd()
        b = self.mock_cmd()

        bp.add(a).add(b)

        self.assertEqual(bp.cmds, [a, b])
예제 #4
0
    def test_add_accepts_multiple_commands(self):
        bp = BasePipe()
        a = self.mock_cmd()
        b = self.mock_cmd()

        bp.add(a, b)

        self.assertEqual(bp.cmds, [a, b])
예제 #5
0
    def test_add_links_output_of_first_command_to_input_of_next(self):
        bp = BasePipe()

        a = self.CMD()
        b = self.CMD()
        bp.add(a, b)

        self.assertEqual(a.output, b.input)
예제 #6
0
    def setUp(self):
        super().setUp()

        a = self.mock_cmd()
        b = self.mock_cmd()
        cmd = BasePipe()
        cmd.add(a, b)

        self.cmd = cmd
예제 #7
0
    def test_add_extends_command_list(self):
        bp = BasePipe()
        a = self.mock_cmd()
        b = self.mock_cmd()

        bp.add(a)
        bp.add(b)

        self.assertEqual(bp.cmds, [a, b])
예제 #8
0
    def test_add_sets_timestamp_on_each_cmd(self):

        bp = BasePipe()
        a = self.mock_cmd()
        b = self.mock_cmd()

        bp.add(a, b)

        self.assertEqual(bp.timestamp, a.timestamp)
        self.assertEqual(bp.timestamp, b.timestamp)
예제 #9
0
    def test_link_integrity_maintained_through_cmd_output(self):
        bp = BasePipe()

        a = self.CMD(foo='meh')
        b = self.CMD()
        bp.add(a, b)

        a.kwargs['-foo'] = 'hehe.txt'
        self.assertEqual(b.cmd(readable=False), '{} {} {}'.format(
            self.CMD.INVOKE_STR, '-foo', 'hehe.txt'))
예제 #10
0
    def test_output_returns_unique_combined_list_from_all_if_passed_true(self):

        pipe = BasePipe()

        a = Mock(output=lambda: list('abc'))
        b = Mock(output=lambda: list('def'))
        c = Mock(output=lambda: list('beg'))

        pipe.add(a, b, c)

        self.assertEqual(pipe.output(from_all=True), list('abcdefg'))
예제 #11
0
    def test_subpipe_should_return_expected_output(self):
        a = Mock(output=lambda: list('abc'))
        b = Mock(output=lambda: list('def'))
        c = Mock(output=lambda: list('beg'))

        subpipe = BasePipe()
        subpipe.add(a, b)

        pipe = BasePipe()
        pipe.add(c, subpipe)  # should not raise

        self.assertEqual(pipe.output(), subpipe.output())
예제 #12
0
    def test_add_double_check_link_integrity(self):
        bp = BasePipe()

        a = self.CMD(foo='meh')
        b = self.CMD()
        bp.add(a, b)

        self.assertEqual(a.output(), ['meh'])
        self.assertEqual(b.input(), ['meh'])

        a.kwargs['-foo'] = 'hehe'
        self.assertEqual(b.input(), ['hehe'])
예제 #13
0
    def test_subpipe_input_set_as_expected(self):
        a = Mock(output=lambda: list('abc'))
        b = Mock(output=lambda: list('def'))
        c = Mock(output=lambda: list('beg'))

        def ugh(x):
            x.input = c.output
        c.link = Mock(side_effect=ugh)

        subpipe = BasePipe()
        subpipe.add(a, b)

        pipe = BasePipe()
        pipe.add(c, subpipe)  # should not raise

        c.link.assert_called_once_with(subpipe)
        self.assertEqual(subpipe.input(), c.output())
예제 #14
0
 def sample_pipe(self):
     a = self.mock_cmd()
     b = self.mock_cmd()
     pipe = BasePipe()
     pipe.add(a, b)
     return pipe
예제 #15
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()