def test_bowtie2_exec_notexist(): """Error thrown if bowtie2 executable does not exist""" try: obj = bowtie_map.Bowtie2_Map(os.path.join(".", "bowtie2")) except NotExecutableError: return True else: return False
def test_bowtie2_notexec(): """Error thrown if bowtie2 not executable""" try: obj = bowtie_map.Bowtie2_Map("LICENSE") except NotExecutableError: return True else: return False
def test_bowtie2_cmd(): """bowtie2-map returns correct form of cmd-line""" bt2_map = bowtie_map.Bowtie2_Map("bowtie2") outfilename = os.path.join(OUTDIR, "_vs_".join([os.path.split(os.path.splitext(READS)[0])[-1], os.path.split(os.path.splitext(FA_INDEX)[0])[-1]]) + ".sam") target = ' '.join(["bowtie2", "--very-sensitive", "--no-unal", "-p", THREADS, "-x", FA_INDEX, "-f", READS, "-S", outfilename]) result = bt2_map.run(READS.split(".gz")[0], FA_INDEX, outfilename, THREADS, fasta=True, dry_run=True) assert_equal(result.command, target)
def test_bowtie2_build_exec(): """bowtie2 maps reads correctly with FASTA test data""" bt2_map = bowtie_map.Bowtie2_Map("bowtie2") outfilename = os.path.join(OUTDIR, "_vs_".join([os.path.split(os.path.splitext(READS)[0])[-1], os.path.split(os.path.splitext(FA_INDEX)[0])[-1]]) + ".sam") result = bt2_map.run(READS, FA_INDEX, outfilename, THREADS, fasta=True) # Test for equality of output and target MD5 files # To establish equality, we need to ignore the @PG line that describes the # path to bowtie2, as this may differ between systems with open(os.path.join(outfilename), "r") as outfh: with open(TARGET, "r") as tgtfh: tgtdata = '\n'.join([l for l in tgtfh.readlines() if not l.startswith('@PG')]) outdata = '\n'.join([l for l in outfh.readlines() if not l.startswith('@PG')]) assert_equal(tgtdata, outdata)
def test_bowtie_map_cmd_fq(): """bowtie2 map instantiates FQ input, runs and returns correct form of cmd-line""" obj = bowtie_map.Bowtie2_Map("bowtie2") first = os.path.split(ASSEM_READS)[-1].split(".f")[0] second = "_Vs_" + os.path.split(FA_INDEX)[-1] + ".sam" outfile_name = first + second target = ' '.join(["bowtie2", "--very-sensitive", "--no-unal", "-p", THREADS, "-x", FA_INDEX, "-q", ASSEM_READS, "-S", os.path.join(OUTDIR, outfile_name)]) assert_equal(obj.run(ASSEM_READS, FA_INDEX, OUTDIR, THREADS, dry_run=True), target)
def test_bowtie_map_FQ_exec(): """Run bowtie_map on test FQ data and compare output to precomputed target""" # wont work with .gz files, so have to decomp these decompcmd = decomp(ASSEM_READS) pipe = subprocess.run(decompcmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) obj = bowtie_map.Bowtie2_Map("bowtie2") result = obj.run(ASSEM_READS.split(".gz")[0], FA_INDEX, OUTDIR, THREADS) # compress them again comp_cmd = comp(ASSEM_READS.split(".gz")[0]) pipe = subprocess.run(comp_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) # test to see if it has produced the sam file. if not os.path.isfile(result.sam): return False
def test_bowtie2path(): """bowtie2-map executable is in $PATH""" bowtie_map.Bowtie2_Map("bowtie2")
def test_bowtie(): """bowtie_map instantiates with cmd-line if bowtie is in $PATH""" bowtie_map.Bowtie2_Map("bowtie2")