def index_reference_sequence(data, force=False):
<EOL>refseq_file = data.paramsdict['<STR_LIT>']<EOL>index_files = []<EOL>if "<STR_LIT>" in data._hackersonly["<STR_LIT>"]:<EOL><INDENT>index_files.extend(["<STR_LIT>", "<STR_LIT>"])<EOL><DEDENT>else:<EOL><INDENT>index_files.extend(["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"])<EOL><DEDENT>index_files.extend(["<STR_LIT>"])<EOL>if not force:<EOL><INDENT>if all([os.path.isfile(refseq_file+i) for i in index_files]):<EOL><INDENT>return<EOL><DEDENT><DEDENT>if "<STR_LIT>" in data._hackersonly["<STR_LIT>"]:<EOL><INDENT>cmd1 = [ipyrad.bins.smalt, "<STR_LIT:index>", <EOL>"<STR_LIT>", str(data._hackersonly["<STR_LIT>"]), <EOL>refseq_file, <EOL>refseq_file]<EOL><DEDENT>else:<EOL><INDENT>cmd1 = [ipyrad.bins.bwa, "<STR_LIT:index>", refseq_file]<EOL><DEDENT>LOGGER.info("<STR_LIT:U+0020>".join(cmd1))<EOL>proc1 = sps.Popen(cmd1, stderr=sps.STDOUT, stdout=sps.PIPE)<EOL>error1 = proc1.communicate()[<NUM_LIT:0>]<EOL>cmd2 = [ipyrad.bins.samtools, "<STR_LIT>", refseq_file]<EOL>LOGGER.info("<STR_LIT:U+0020>".join(cmd2))<EOL>proc2 = sps.Popen(cmd2, stderr=sps.STDOUT, stdout=sps.PIPE)<EOL>error2 = proc2.communicate()[<NUM_LIT:0>]<EOL>if proc1.returncode:<EOL><INDENT>raise IPyradWarningExit(error1)<EOL><DEDENT>if error2:<EOL><INDENT>if "<STR_LIT>" in error2:<EOL><INDENT>raise IPyradWarningExit(NO_ZIP_BINS.format(refseq_file))<EOL><DEDENT>else:<EOL><INDENT>raise IPyradWarningExit(error2)<EOL><DEDENT><DEDENT>
Index the reference sequence, unless it already exists. Also make a mapping
of scaffolds to index numbers for later user in steps 5-6.