def mapreads(data, sample, nthreads, force):
LOGGER.info("<STR_LIT>", sample.name, nthreads)<EOL>derepfile = os.path.join(data.dirs.edits, sample.name+"<STR_LIT>")<EOL>sample.files.dereps = [derepfile]<EOL>mumapfile = sample.files.unmapped_reads<EOL>umap1file = os.path.join(data.dirs.edits, sample.name+"<STR_LIT>")<EOL>umap2file = os.path.join(data.dirs.edits, sample.name+"<STR_LIT>")        <EOL>if "<STR_LIT>" in data.paramsdict["<STR_LIT>"]:<EOL><INDENT>sample.files.split1 = os.path.join(data.dirs.edits, sample.name+"<STR_LIT>")<EOL>sample.files.split2 = os.path.join(data.dirs.edits, sample.name+"<STR_LIT>")<EOL>sample.files.dereps = [sample.files.split1, sample.files.split2]<EOL>split_merged_reads(sample.files.dereps, derepfile)<EOL><DEDENT>if "<STR_LIT>" in data._hackersonly["<STR_LIT>"]:<EOL><INDENT>cmd1 = [ipyrad.bins.smalt, "<STR_LIT>", <EOL>"<STR_LIT>", "<STR_LIT>", <EOL>"<STR_LIT>", str(max(<NUM_LIT:1>, nthreads)),<EOL>"<STR_LIT>", str(data.paramsdict['<STR_LIT>']), <EOL>"<STR_LIT>", os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>"),<EOL>"<STR_LIT>",<EOL>data.paramsdict['<STR_LIT>']<EOL>] + sample.files.dereps<EOL>cmd1_stdout = sps.PIPE<EOL>cmd1_stderr = sps.STDOUT<EOL><DEDENT>else:<EOL><INDENT>cmd1 = [ipyrad.bins.bwa, "<STR_LIT>",<EOL>"<STR_LIT>", str(max(<NUM_LIT:1>, nthreads)),<EOL>"<STR_LIT>",<EOL>data.paramsdict['<STR_LIT>']<EOL>] + sample.files.dereps<EOL>try:<EOL><INDENT>bwa_args = data._hackersonly["<STR_LIT>"].split()<EOL>bwa_args.reverse()<EOL>for arg in bwa_args:<EOL><INDENT>cmd1.insert(<NUM_LIT:2>, arg)<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>cmd1_stdout = open(os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>"), '<STR_LIT:w>')<EOL>cmd1_stderr = None<EOL><DEDENT>cmd2 = [ipyrad.bins.samtools, "<STR_LIT>", <EOL>"<STR_LIT>", <EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>"), <EOL>os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>")]<EOL>cmd3 = [ipyrad.bins.samtools, "<STR_LIT>", <EOL>"<STR_LIT>", os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>"),<EOL>"<STR_LIT>", "<STR_LIT>", <EOL>"<STR_LIT>", sample.files.mapped_reads]<EOL>cmd4 = [ipyrad.bins.samtools, "<STR_LIT:index>", sample.files.mapped_reads]<EOL>cmd5 = [ipyrad.bins.samtools, "<STR_LIT>", "<STR_LIT>",<EOL>os.path.join(data.dirs.refmapping, sample.name+"<STR_LIT>")]<EOL>if '<STR_LIT>' in data.paramsdict["<STR_LIT>"]:<EOL><INDENT>if "<STR_LIT>" in data._hackersonly["<STR_LIT>"]:<EOL><INDENT>cmd1.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL>cmd1.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT>cmd2.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL>cmd2.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL>cmd5.insert(<NUM_LIT:2>, umap1file)<EOL>cmd5.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL>cmd5.insert(<NUM_LIT:2>, umap2file)<EOL>cmd5.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>cmd5.insert(<NUM_LIT:2>, mumapfile)<EOL>cmd5.insert(<NUM_LIT:2>, "<STR_LIT>")<EOL><DEDENT>LOGGER.debug("<STR_LIT:U+0020>".join(cmd1))<EOL>proc1 = sps.Popen(cmd1, stderr=cmd1_stderr, stdout=cmd1_stdout)<EOL>try:<EOL><INDENT>error1 = proc1.communicate()[<NUM_LIT:0>]<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>proc1.kill()<EOL><DEDENT>if proc1.returncode:<EOL><INDENT>raise IPyradWarningExit(error1)<EOL><DEDENT>LOGGER.debug("<STR_LIT:U+0020>".join(cmd2))<EOL>proc2 = sps.Popen(cmd2, stderr=sps.STDOUT, stdout=sps.PIPE)<EOL>LOGGER.debug("<STR_LIT:U+0020>".join(cmd3))<EOL>proc3 = sps.Popen(cmd3, stderr=sps.STDOUT, stdout=sps.PIPE, stdin=proc2.stdout)<EOL>error3 = proc3.communicate()[<NUM_LIT:0>]<EOL>if proc3.returncode:<EOL><INDENT>raise IPyradWarningExit(error3)<EOL><DEDENT>proc2.stdout.close()<EOL>LOGGER.debug("<STR_LIT:U+0020>".join(cmd4))<EOL>proc4 = sps.Popen(cmd4, stderr=sps.STDOUT, stdout=sps.PIPE)<EOL>error4 = proc4.communicate()[<NUM_LIT:0>]<EOL>if proc4.returncode:<EOL><INDENT>raise IPyradWarningExit(error4)<EOL><DEDENT>LOGGER.debug("<STR_LIT:U+0020>".join(cmd5))<EOL>proc5 = sps.Popen(cmd5, stderr=sps.STDOUT, stdout=sps.PIPE)<EOL>error5 = proc5.communicate()[<NUM_LIT:0>]<EOL>if proc5.returncode:<EOL><INDENT>raise IPyradWarningExit(error5)<EOL><DEDENT>if '<STR_LIT>' in data.paramsdict["<STR_LIT>"]:<EOL><INDENT>LOGGER.info("<STR_LIT>".format(umap1file, umap2file))<EOL>merge_pairs_after_refmapping(data, [(umap1file, umap2file)], mumapfile)<EOL><DEDENT>
Attempt to map reads to reference sequence. This reads in the fasta files
(samples.files.edits), and maps each read to the reference. Unmapped reads 
are dropped right back in the de novo pipeline. Reads that map successfully
are processed and pushed downstream and joined with the rest of the data 
post muscle_align. 

Mapped reads end up in a sam file.