def _hmmalign(self, input_path, directions, pipeline,<EOL>forward_reads_output_path, reverse_reads_output_path):
if pipeline == PIPELINE_AA:<EOL><INDENT>reverse_direction_reads_present=False<EOL><DEDENT>else:<EOL><INDENT>reverse_direction_reads_present=False in directions.values()<EOL><DEDENT>with tempfile.NamedTemporaryFile(prefix='<STR_LIT>', suffix='<STR_LIT>') as for_file_fh:<EOL><INDENT>for_file = for_file_fh.name<EOL>with tempfile.NamedTemporaryFile(prefix='<STR_LIT>', suffix='<STR_LIT>') as rev_file_fh:<EOL><INDENT>rev_file = rev_file_fh.name<EOL>if reverse_direction_reads_present:  <EOL><INDENT>reverse = []<EOL>forward = []<EOL>records = list(SeqIO.parse(open(input_path), '<STR_LIT>'))<EOL>for record in records:<EOL><INDENT>read_id = record.id<EOL>if directions[read_id] == True:<EOL><INDENT>forward.append(record)<EOL><DEDENT>elif directions[read_id] == False:<EOL><INDENT>reverse.append(record)<EOL><DEDENT>else:<EOL><INDENT>raise Exception(logging.error('<STR_LIT>'))<EOL>exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>logging.debug("<STR_LIT>" % len(forward))<EOL>logging.debug("<STR_LIT>" % len(reverse))<EOL>with open(for_file, '<STR_LIT:w>') as for_aln:<EOL><INDENT>logging.debug("<STR_LIT>" % for_file)<EOL>for record in forward:<EOL><INDENT>for_aln.write('<STR_LIT:>>' + record.id + '<STR_LIT:\n>')<EOL>for_aln.write(str(record.seq) + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>if any(forward):<EOL><INDENT>self.hmmalign_sequences(self.aln_hmm, for_file, forward_reads_output_path)<EOL><DEDENT>else:<EOL><INDENT>cmd = '<STR_LIT>' % (forward_reads_output_path)<EOL>extern.run(cmd)<EOL><DEDENT>with open(rev_file, '<STR_LIT:w>') as rev_aln:<EOL><INDENT>logging.debug("<STR_LIT>" % rev_file)<EOL>for record in reverse:<EOL><INDENT>if record.id and record.seq:<EOL><INDENT>rev_aln.write('<STR_LIT:>>' + record.id + '<STR_LIT:\n>')<EOL>rev_aln.write(str(record.seq.reverse_complement()) + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT><DEDENT>self.hmmalign_sequences(self.aln_hmm, rev_file, reverse_reads_output_path)<EOL>conv_files = [forward_reads_output_path, reverse_reads_output_path]<EOL>return conv_files<EOL><DEDENT>else:<EOL><INDENT>self.hmmalign_sequences(self.aln_hmm, input_path, forward_reads_output_path)<EOL>conv_files = [forward_reads_output_path]<EOL>return conv_files<EOL><DEDENT><DEDENT><DEDENT>
Align reads to the aln_hmm. Receives unaligned sequences and
aligns them.

Parameters
----------
input_path : str
    Filename of unaligned hits to be aligned
directions : dict
    dictionary containing read names as keys, and complement
    as the entry (True=Forward, False=Reverse)
pipeline: str
    either PIPELINE_AA = "P" or PIPELINE_NT = "D"
forward_reads_output_fh: str
    Where to write aligned forward reads
reverse_reads_output_fh: str
    Where to write aligned reverse reads
Returns
-------
Nothing.