<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_needle_alignment(seq_a, seq_b, gapopen=10, gapextend=0.5, write_outfile=True, outdir=None, outfile=None, force_rerun=False):
 """Run the needle alignment program for two strings and return the raw alignment result. More info: EMBOSS needle: http://www.bioinformatics.nl/cgi-bin/emboss/help/needle Biopython wrapper: http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc84 Using strings as input: https://www.biostars.org/p/91124/ Args: id_a: ID of reference sequence seq_a (str, Seq, SeqRecord):
 Reference sequence id_b: ID of sequence to be aligned seq_b (str, Seq, SeqRecord):
 String representation of sequence to be aligned gapopen: Gap open penalty is the score taken away when a gap is created gapextend: Gap extension penalty is added to the standard gap penalty for each base or residue in the gap outdir (str, optional):
 Path to output directory. Default is the current directory. outfile (str, optional):
 Name of output file. If not set, is {id_a}_{id_b}_align.txt force_rerun (bool):
 Default False, set to True if you want to rerun the alignment if outfile exists. Returns: str: Raw alignment result of the needle alignment in srspair format. """

    # TODO: check if needle is installed and raise error if not

    if not outdir:
        outdir = ''

    # TODO: rewrite using utils functions - does not report error if needle is not installed currently
    # TODO: rethink outdir/outfile, also if this should return the tempfile or just a file object or whatever
    if write_outfile:
        seq_a = ssbio.protein.sequence.utils.cast_to_str(seq_a)
        seq_b = ssbio.protein.sequence.utils.cast_to_str(seq_b)

        if not outfile:
            outfile = op.join(tempfile.gettempdir(), 'temp_alignment.needle')
        else:
            outfile = op.join(outdir, outfile)

        if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
            cmd = 'needle -outfile="{}" -asequence=asis::{} -bsequence=asis::{} -gapopen={} -gapextend={}'.format(
                outfile, seq_a, seq_b, gapopen, gapextend)
            command = subprocess.Popen(cmd,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=True)
            out, err = command.communicate()

        return outfile

    else:
        seq_a = ssbio.protein.sequence.utils.cast_to_str(seq_a)
        seq_b = ssbio.protein.sequence.utils.cast_to_str(seq_b)

        cmd = 'needle -auto -stdout -asequence=asis::{} -bsequence=asis::{} -gapopen={} -gapextend={}'.format(seq_a, seq_b, gapopen, gapextend)
        command = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
        stdout = command.stdout.read()
        return stdout