Ejemplo n.º 1
0
 def test_sort(self):
     cmdline = SamtoolsSortCommandline(samtools_exe)
     cmdline.set_parameter("input_bam", self.bamfile1)
     cmdline.set_parameter("out_prefix", "SamBam/out")
     stdout, stderr = cmdline()
     self.assertFalse(
         stderr, "Samtools sort failed:\n%s\nStderr:%s" % (cmdline, stderr))
Ejemplo n.º 2
0
 def test_sort(self):
     cmdline = SamtoolsSortCommandline(samtools_exe)
     cmdline.set_parameter("input_bam", self.bamfile1)
     cmdline.set_parameter("out_prefix", "bam1")
     stdout, stderr = cmdline()
     self.assertFalse(stderr,
                      "Samtools sort failed:\n%s\nStderr:%s"
                      % (cmdline, stderr))
Ejemplo n.º 3
0
 def test_sort(self):
     cmdline = SamtoolsSortCommandline(samtools_exe)
     cmdline.set_parameter("input_bam", self.bamfile1)
     cmdline.set_parameter("out_prefix", "SamBam/out")
     try:
         stdout, stderr = cmdline()
     except ApplicationError as err:
         if "[bam_sort] Use -T PREFIX / -o FILE to specify temporary and final output files" in str(err):
             # TODO: The samtools sort API changed...
             return
         else:
             raise
     self.assertFalse(stderr,
                      "Samtools sort failed:\n%s\nStderr:%s"
                      % (cmdline, stderr))
Ejemplo n.º 4
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