예제 #1
0
    def testIndexPresetCompressed(self):
        '''test indexing via preset.'''

        pysam.tabix_compress(self.tmpfilename, self.tmpfilename + ".gz")
        pysam.tabix_index(self.tmpfilename + ".gz", preset=self.preset)
        checkBinaryEqual(self.tmpfilename + ".gz", self.filename)
        checkBinaryEqual(self.tmpfilename + ".gz.tbi", self.filename_idx)
예제 #2
0
    def testIndexPresetUncompressed(self):
        '''test indexing via preset.'''

        pysam.tabix_index(self.tmpfilename, preset=self.preset)
        # check if uncompressed file has been removed
        self.assertEqual(os.path.exists(self.tmpfilename), False)
        checkBinaryEqual(self.tmpfilename + ".gz", self.filename)
        checkBinaryEqual(self.tmpfilename + ".gz.tbi", self.filename_idx)
예제 #3
0
 def checkCommand(self, command):
     if command:
         samtools_target, pysam_target = self.commands[
             command][0][0], self.commands[command][1][0]
         samtools_target = os.path.join(WORKDIR, samtools_target)
         pysam_target = os.path.join(WORKDIR, pysam_target)
         self.assertTrue(checkBinaryEqual(samtools_target, pysam_target),
                         "%s failed: files %s and %s are not the same" % (command, samtools_target, pysam_target))
예제 #4
0
 def checkCommand(self, command):
     if command:
         samtools_target, pysam_target = self.commands[
             command][0][0], self.commands[command][1][0]
         samtools_target = os.path.join(WORKDIR, samtools_target)
         pysam_target = os.path.join(WORKDIR, pysam_target)
         self.assertTrue(checkBinaryEqual(samtools_target, pysam_target),
                         "%s failed: files %s and %s are not the same" % (command, samtools_target, pysam_target))
예제 #5
0
    def check_statement(self, statement):

        parts = statement.split(" ")
        r_samtools = {"out": self.executable}
        r_pysam = {"out": "pysam"}

        command = parts[0]
        command = self.map_command.get(command, command)
        # self.assertTrue(command in pysam.SAMTOOLS_DISPATCH)

        targets = [x for x in parts if "%(out)s" in x]
        samtools_targets = [x % r_samtools for x in targets]
        pysam_targets = [x % r_pysam for x in targets]

        pysam_method = getattr(self.module, command)
        # run samtools
        full_statement = re.sub("%\(out\)s", self.executable, statement)
        run_command(" ".join((self.executable, full_statement)))
        # sys.stdout.write("%s %s ok" % (command, self.executable))

        # run pysam
        if ">" in statement:
            assert parts[-2] == ">"
            parts = parts[:-2]

        # avoid interpolation to preserve string quoting, tab chars, etc.
        pysam_parts = [re.sub("%\(out\)s", "pysam", x) for x in parts[1:]]
        output = pysam_method(*pysam_parts, raw=True, catch_stdout=True)

        # sys.stdout.write(" pysam ok\n")

        if ">" in statement:
            with open(pysam_targets[-1], "wb") as outfile:
                if output is not None:
                    outfile = outfile.write(output)

        for samtools_target, pysam_target in zip(samtools_targets,
                                                 pysam_targets):
            if os.path.isdir(samtools_target):
                samtools_files = glob.glob(os.path.join(samtools_target, "*"))
                pysam_files = glob.glob(os.path.join(pysam_target, "*"))
                self.assertEqual(len(samtools_files), len(pysam_files))
                # need to be able to exclude files like README, etc.
                continue
            else:
                samtools_files = [samtools_target]
                pysam_files = [pysam_target]

            for s, p in zip(samtools_files, pysam_files):
                self.assertTrue(
                    checkBinaryEqual(s, p),
                    "%s failed: files %s and %s are not the same" %
                    (command, s, p))
예제 #6
0
    def check_statement(self, statement):

        parts = statement.split(" ")
        r_samtools = {"out": self.executable}
        r_pysam = {"out": "pysam"}

        command = parts[0]
        command = self.map_command.get(command, command)
        # self.assertTrue(command in pysam.SAMTOOLS_DISPATCH)

        targets = [x for x in parts if "%(out)s" in x]
        samtools_targets = [x % r_samtools for x in targets]
        pysam_targets = [x % r_pysam for x in targets]

        pysam_method = getattr(self.module, command)
        # run samtools
        full_statement = re.sub("%\(out\)s", self.executable, statement)
        run_command(" ".join((self.executable, full_statement)))
        # sys.stdout.write("%s %s ok" % (command, self.executable))

        # run pysam
        if ">" in statement:
            assert parts[-2] == ">"
            parts = parts[:-2]

        # avoid interpolation to preserve string quoting, tab chars, etc.
        pysam_parts = [re.sub("%\(out\)s", "pysam", x) for x in parts[1:]]
        output = pysam_method(*pysam_parts, raw=True, catch_stdout=True)

        # sys.stdout.write(" pysam ok\n")

        if ">" in statement:
            with open(pysam_targets[-1], "wb") as outfile:
                if output is not None:
                    outfile = outfile.write(output)

        for samtools_target, pysam_target in zip(samtools_targets, pysam_targets):
            if os.path.isdir(samtools_target):
                samtools_files = glob.glob(os.path.join(samtools_target, "*"))
                pysam_files = glob.glob(os.path.join(pysam_target, "*"))
                self.assertEqual(len(samtools_files), len(pysam_files))
                # need to be able to exclude files like README, etc.
                continue
            else:
                samtools_files = [samtools_target]
                pysam_files = [pysam_target]

            for s, p in zip(samtools_files, pysam_files):
                self.assertTrue(checkBinaryEqual(s, p), "%s failed: files %s and %s are not the same" % (command, s, p))
예제 #7
0
 def testCompression(self):
     '''see also issue 106'''
     pysam.tabix_compress(self.tmpfilename, self.tmpfilename + ".gz")
     checkBinaryEqual(self.tmpfilename, self.tmpfilename + ".gz")