Example #1
0
def test_bowtie2_align(variables):
    outpath = os.path.join(variables.path, 'bait')
    outfile = os.path.join(outpath, 'map_test_sorted.bam')
    targetpath = os.path.join(variables.targetpath, 'bait')
    # Use samtools wrapper to set up the bam sorting command
    samsort = SamtoolsSortCommandline(input=outfile, o=True, out_prefix="-")
    samtools = [
        # When bowtie2 maps reads to all possible locations rather than choosing a 'best' placement, the
        # SAM header for that read is set to 'secondary alignment', or 256. Please see:
        # http://davetang.org/muse/2014/03/06/understanding-bam-flags/ The script below reads in the stdin
        # and subtracts 256 from headers which include 256
        'python3 {}'.format(scriptpath),
        # Use samtools wrapper to set up the samtools view
        SamtoolsViewCommandline(b=True, S=True, h=True, input_file="-"),
        samsort
    ]
    # Add custom parameters to a dictionary to be used in the bowtie2 alignment wrapper
    indict = {
        '--very-sensitive-local': True,
        '-U': os.path.join(targetpath, 'genesippr.fastq.gz'),
        '-a': True,
        '--threads': multiprocessing.cpu_count(),
        '--local': True
    }
    # Create the bowtie2 reference mapping command
    bowtie2align = Bowtie2CommandLine(bt2=os.path.join(targetpath,
                                                       'baitedtargets'),
                                      threads=multiprocessing.cpu_count(),
                                      samtools=samtools,
                                      **indict)
    bowtie2align(cwd=outpath)
    size = os.stat(outfile)
    assert size.st_size > 0
 def test_view(self):
     """Test for samtools view."""
     cmdline = SamtoolsViewCommandline(samtools_exe)
     cmdline.set_parameter("input_file", self.bamfile1)
     stdout_bam, stderr_bam = cmdline()
     self.assertTrue(
         stderr_bam.startswith(""),
         "SAM file viewing failed: \n%s\nStdout:%s" % (cmdline, stdout_bam))
     cmdline.set_parameter("input_file", self.samfile1)
     cmdline.set_parameter("S", True)
     stdout_sam, stderr_sam = cmdline()
     self.assertTrue(
         stdout_sam.startswith("HWI-1KL120:88:D0LRBACXX:1:1101:1780:2146"),
         "SAM file  viewing failed:\n%s\nStderr:%s" % (cmdline, stderr_sam))
Example #3
0
    def test_view(self):
        """Test for samtools view"""

        cmdline = SamtoolsViewCommandline(samtools_exe)
        cmdline.set_parameter("input_file", self.bamfile1)
        stdout_bam, stderr_bam = cmdline()
        self.assertTrue(
            stderr_bam.startswith(""),
            "SAM file viewing failed: \n%s\nStdout:%s" % (cmdline, stdout_bam))
        cmdline.set_parameter("input_file", self.samfile1)
        cmdline.set_parameter("S", True)
        stdout_sam, stderr_sam = cmdline()
        self.assertTrue(
            stderr_sam.startswith("[samopen] SAM header is present:"),
            "SAM file  viewing failed:\n%s\nStderr:%s" % (cmdline, stderr_sam))
Example #4
0
    def test_view(self):
        """Test for samtools view"""

        cmdline = SamtoolsViewCommandline(samtools_exe)
        cmdline.set_parameter("input_file", self.bamfile1)
        stdout_bam, stderr_bam = cmdline()
        self.assertTrue(stderr_bam.startswith(""), "SAM file viewing failed: \n%s\nStdout:%s" % (cmdline, stdout_bam))
        cmdline.set_parameter("input_file", self.samfile1)
        cmdline.set_parameter("S", True)
        stdout_sam, stderr_sam = cmdline()
        self.assertTrue(
            stderr_sam.startswith("[samopen] SAM header is present:"),
            "SAM file  viewing failed:\n%s\nStderr:%s" % (cmdline, stderr_sam),
        )
 def test_view(self):
     """Test for samtools view."""
     cmdline = SamtoolsViewCommandline(samtools_exe)
     cmdline.set_parameter("input_file", self.bamfile1)
     stdout_bam, stderr_bam = cmdline()
     self.assertTrue(stderr_bam.startswith(""),
                     "SAM file viewing failed: \n%s\nStdout:%s"
                     % (cmdline, stdout_bam))
     cmdline.set_parameter("input_file", self.samfile1)
     cmdline.set_parameter("S", True)
     stdout_sam, stderr_sam = cmdline()
     self.assertTrue(
         stdout_sam.startswith("HWI-1KL120:88:D0LRBACXX:1:1101:1780:2146"),
         "SAM file  viewing failed:\n%s\nStderr:%s"
         % (cmdline, stderr_sam))