def merge_forev_aln(self, forward_aln_list, reverse_aln_list, outputs):
orfm_regex = OrfM.regular_expression()<EOL>def remove_orfm_end(records):<EOL><INDENT>new_dict = {}<EOL>for key, record in records.iteritems():<EOL><INDENT>orfmregex = orfm_regex.match(key)<EOL>if orfmregex:<EOL><INDENT>new_dict[orfmregex.groups(<NUM_LIT:0>)[<NUM_LIT:0>]] = record<EOL><DEDENT>else:<EOL><INDENT>new_dict[key] = record<EOL><DEDENT><DEDENT>return new_dict<EOL><DEDENT>for idx, (forward_path, reverse_path) in enumerate(zip(forward_aln_list, reverse_aln_list)):<EOL><INDENT>output_path = outputs[idx]<EOL>logging.info('<STR_LIT>' % (os.path.basename(forward_path), os.path.basename(reverse_path)))<EOL>forward_reads = SeqIO.parse(forward_path, '<STR_LIT>')<EOL>reverse_reads = remove_orfm_end(SeqIO.to_dict(SeqIO.parse(reverse_path, '<STR_LIT>')))<EOL>with open(output_path, '<STR_LIT:w>') as out:<EOL><INDENT>for forward_record in forward_reads:<EOL><INDENT>regex_match = orfm_regex.match(forward_record.id)<EOL>if regex_match:<EOL><INDENT>id = regex_match.groups(<NUM_LIT:0>)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>id = forward_record.id<EOL><DEDENT>forward_sequence = str(forward_record.seq)<EOL>try:<EOL><INDENT>reverse_sequence = str(reverse_reads[id].seq)<EOL>new_seq = '<STR_LIT>'<EOL>if len(forward_sequence) == len(reverse_sequence):<EOL><INDENT>for f, r in zip(forward_sequence, reverse_sequence):<EOL><INDENT>if f == r:<EOL><INDENT>new_seq += f<EOL><DEDENT>elif f == '<STR_LIT:->' and r != '<STR_LIT:->':<EOL><INDENT>new_seq += r<EOL><DEDENT>elif r == '<STR_LIT:->' and f != '<STR_LIT:->':<EOL><INDENT>new_seq += f<EOL><DEDENT>elif f != '<STR_LIT:->' and r != '<STR_LIT:->':<EOL><INDENT>if f != r:<EOL><INDENT>new_seq += f<EOL><DEDENT><DEDENT>else:<EOL><INDENT>new_seq += '<STR_LIT:->'<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>logging.error('<STR_LIT>')<EOL>raise Exception('<STR_LIT>')<EOL><DEDENT>out.write('<STR_LIT>' % forward_record.id)<EOL>out.write('<STR_LIT>' % (new_seq))<EOL>del reverse_reads[id]<EOL><DEDENT>except:<EOL><INDENT>out.write('<STR_LIT>' % forward_record.id)<EOL>out.write('<STR_LIT>' % (forward_sequence))<EOL><DEDENT><DEDENT>for record_id, record in reverse_reads.iteritems():<EOL><INDENT>out.write('<STR_LIT>' % record.id)<EOL>out.write('<STR_LIT>' % (str(record.seq)))<EOL><DEDENT><DEDENT><DEDENT>
merge_forev_aln - Merges forward and reverse alignments for a given run

Parameters
----------
aln_list : array
    List of the forward and reverse alignments for each of the runs
    given to graftM. **MUST** be the following pattern:
    [forward_run1, reverse_run1, forward_run2, reverse_run2 ...]
outputs : array
    List of paths to output file to which the merged alignments from the
    aln_list will go into. Must be exactly half the size of the aln_list
    (i.e. one output file for every forward and reverse file provided)

Returns
-------
Nothing - output files are known.