コード例 #1
0
    def test_build_run_bowtie_with_existing_output_index(self):
        """test that build_run_bowtie_exsiting_output_index correctly raises an OSError when
        the specified output index base name exists"""

        _BOTIE_INDEX_FILE_EXT = '.bt2'
        _SAMPLE_BOWTIE_STR = 'unittest test_build_run_bowtie_with_existing_output_index'

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        if not os.path.exists(self.output_index_dir):
            os.mkdir(self.output_index_dir)

        for x in range(1, 7):
            sample_index_str = self.output_scaffold_index + '.' + str(
                x) + _BOTIE_INDEX_FILE_EXT
            sample_index_file = open(sample_index_str, 'w+')
            sample_index_file.write(_SAMPLE_BOWTIE_STR)
            sample_index_file.close()

        with self.assertRaises(OSError):
            exec_bowtie.build_run_bowtie(self.bowtie_path,
                                         self.sample_reference_fa,
                                         self.output_scaffold_index,
                                         sample_fq_1, sample_fq_2, sample_fq_u,
                                         self.output_sam)
コード例 #2
0
    def test_build_run_bowtie_output_sam_exists(self):
        """test that bowtie2-build subprocess call generates the expected output sam file when build_run_bowtie is
         passed valid arguments for the bowtie file path, input index base name, output to sam path,
         input forward, reverse, and unparied fastq files"""

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        exec_bowtie.build_run_bowtie(self.bowtie_path, self.sample_reference_fa, self.output_scaffold_index,
                                     sample_fq_1, sample_fq_2, sample_fq_u, self.output_sam)

        self.assertTrue(os.stat(self.output_sam) > 0)
コード例 #3
0
    def test_build_run_bowtie_output_sam_exists(self):
        """test that bowtie2-build subprocess call generates the expected output sam file when build_run_bowtie is
         passed valid arguments for the bowtie file path, input index base name, output to sam path,
         input forward, reverse, and unparied fastq files"""

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        exec_bowtie.build_run_bowtie(self.bowtie_path,
                                     self.sample_reference_fa,
                                     self.output_scaffold_index, sample_fq_1,
                                     sample_fq_2, sample_fq_u, self.output_sam)

        self.assertTrue(os.stat(self.output_sam) > 0)
コード例 #4
0
    def test_build_run_bowtie_no_args(self):
        """test that build_run_bowtie correctly raises a Value Error when invalid empty arguments are passed instead of
        expected bowtie file path, reference contigs, output index base name, unpaired and paired end fastq, and an
        output sam file path"""

        # arguments to be formatted
        null_bowtie_path = ''
        null_input_contigs_fa = ''
        null_index_path = ''
        null_pe1_fastq = []
        null_pe2_fastq = []
        null_u_fastq = []
        null_output_sam_path = ''

        with self.assertRaises(ValueError):
            exec_bowtie.build_run_bowtie(null_bowtie_path, null_input_contigs_fa, null_index_path, null_pe1_fastq,
                                         null_pe2_fastq, null_u_fastq, null_output_sam_path)
コード例 #5
0
    def test_build_run_bowtie_index_exists(self):
        """test that bowtie2-build subprocess call generates nonempty output index directory when build_run_bowtie is
         passed valid arguments for the bowtie file path, input index base name, output to sam path,
         input forward, reverse, and unparied fastq files"""

        index_file_count = 0

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        exec_bowtie.build_run_bowtie(self.bowtie_path, self.sample_reference_fa, self.output_scaffold_index,
                                     sample_fq_1, sample_fq_2, sample_fq_u, self.output_sam)

        if os.stat(self.output_index_dir) > 0:
            for f in os.listdir(self.output_index_dir):
                index_file_count += 1

        self.assertTrue(index_file_count > 0)
コード例 #6
0
    def test_build_run_bowtie_no_args(self):
        """test that build_run_bowtie correctly raises a Value Error when invalid empty arguments are passed instead of
        expected bowtie file path, reference contigs, output index base name, unpaired and paired end fastq, and an
        output sam file path"""

        # arguments to be formatted
        null_bowtie_path = ''
        null_input_contigs_fa = ''
        null_index_path = ''
        null_pe1_fastq = []
        null_pe2_fastq = []
        null_u_fastq = []
        null_output_sam_path = ''

        with self.assertRaises(ValueError):
            exec_bowtie.build_run_bowtie(null_bowtie_path,
                                         null_input_contigs_fa,
                                         null_index_path, null_pe1_fastq,
                                         null_pe2_fastq, null_u_fastq,
                                         null_output_sam_path)
コード例 #7
0
    def test_build_run_bowtie_index_exists(self):
        """test that bowtie2-build subprocess call generates nonempty output index directory when build_run_bowtie is
         passed valid arguments for the bowtie file path, input index base name, output to sam path,
         input forward, reverse, and unparied fastq files"""

        index_file_count = 0

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        exec_bowtie.build_run_bowtie(self.bowtie_path,
                                     self.sample_reference_fa,
                                     self.output_scaffold_index, sample_fq_1,
                                     sample_fq_2, sample_fq_u, self.output_sam)

        if os.stat(self.output_index_dir) > 0:
            for f in os.listdir(self.output_index_dir):
                index_file_count += 1

        self.assertTrue(index_file_count > 0)
コード例 #8
0
    def test_build_run_bowtie_with_existing_output_index(self):
        """test that build_run_bowtie_exsiting_output_index correctly raises an OSError when
        the specified output index base name exists"""

        _BOTIE_INDEX_FILE_EXT = '.bt2'
        _SAMPLE_BOWTIE_STR = 'unittest test_build_run_bowtie_with_existing_output_index'

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        if not os.path.exists(self.output_index_dir):
            os.mkdir(self.output_index_dir)

        for x in range(1,7):
            sample_index_str = self.output_scaffold_index + '.' + str(x) + _BOTIE_INDEX_FILE_EXT
            sample_index_file = open(sample_index_str, 'w+')
            sample_index_file.write(_SAMPLE_BOWTIE_STR)
            sample_index_file.close()

        with self.assertRaises(OSError):
            exec_bowtie.build_run_bowtie(self.bowtie_path, self.sample_reference_fa, self.output_scaffold_index,
                                         sample_fq_1, sample_fq_2, sample_fq_u, self.output_sam)
コード例 #9
0
    def test_build_run_bowtie_cmd_good_stderr(self):
        """test that bowtie2-build and bowtie2 suprocess call do not report execution errors when build_run_bowtie is
        passed valid arguments for the bowtie file path, input index base name, output to sam path,
        input forward, reverse, and unpaired fastq files"""

        _BOWTIE_EXECUTION_ERROR = 'Error:'

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        buildout, builderr, stdout, stderr = exec_bowtie.build_run_bowtie(self.bowtie_path, self.sample_reference_fa,
                                                      self.output_scaffold_index, sample_fq_1, sample_fq_2, sample_fq_u,
                                                      self.output_sam)

        self.assertTrue(builderr.find(_BOWTIE_EXECUTION_ERROR) is -1 and
                        stderr.find(_BOWTIE_EXECUTION_ERROR) is -1)
コード例 #10
0
    def test_build_run_bowtie_cmd_good_stderr(self):
        """test that bowtie2-build and bowtie2 suprocess call do not report execution errors when build_run_bowtie is
        passed valid arguments for the bowtie file path, input index base name, output to sam path,
        input forward, reverse, and unpaired fastq files"""

        _BOWTIE_EXECUTION_ERROR = 'Error:'

        sample_fq_1 = [self.sample_fq_1]
        sample_fq_2 = [self.sample_fq_2]
        sample_fq_u = []

        buildout, builderr, stdout, stderr = exec_bowtie.build_run_bowtie(
            self.bowtie_path, self.sample_reference_fa,
            self.output_scaffold_index, sample_fq_1, sample_fq_2, sample_fq_u,
            self.output_sam)

        self.assertTrue(
            builderr.find(_BOWTIE_EXECUTION_ERROR) is -1
            and stderr.find(_BOWTIE_EXECUTION_ERROR) is -1)
コード例 #11
0
    def test_build_run_bowtie_invalid_num_args(self):
        """test that build_run_bowtie correctly raises a Type Error when the wrong number of arguments are passed"""

        with self.assertRaises(TypeError):
            exec_bowtie.build_run_bowtie(self.bowtie_path)
コード例 #12
0
    def test_build_run_bowtie_invalid_num_args(self):
        """test that build_run_bowtie correctly raises a Type Error when the wrong number of arguments are passed"""

        with self.assertRaises(TypeError):
            exec_bowtie.build_run_bowtie(self.bowtie_path)