def gunzip_file(infile, outfile=None, outdir=None, delete_original=False, force_rerun_flag=False):
    """Decompress a gzip file and optionally set output values.

    Args:
        infile: Path to .gz file
        outfile: Name of output file
        outdir: Path to output directory
        delete_original: If original .gz file should be deleted
        force_rerun_flag: If file should be decompressed if outfile already exists

    Returns:
        str: Path to decompressed file

    """
    if not outfile:
        outfile = infile.replace('.gz', '')

    if not outdir:
        outdir = ''
    else:
        outdir = op.dirname(infile)
    outfile = op.join(outdir, op.basename(outfile))

    if force_rerun(flag=force_rerun_flag, outfile=outfile):
        gz = gzip.open(infile, "rb")
        decoded = gz.read()

        with open(outfile, "wb") as new_file:
            new_file.write(decoded)

        gz.close()
        log.debug('{}: file unzipped'.format(outfile))
    else:
        log.debug('{}: file already unzipped'.format(outfile))

    if delete_original:
        os.remove(infile)

    return outfile
def gunzip_file ( infile , outfile = None , outdir = None , delete_original = False , force_rerun_flag = False ) : if not outfile : outfile = infile . replace ( '.gz' , '' ) if not outdir : outdir = '' else : outdir = op . dirname ( infile ) outfile = op . join ( outdir , op . basename ( outfile ) ) if force_rerun ( flag = force_rerun_flag , outfile = outfile ) : gz = gzip . open ( infile , "rb" ) decoded = gz . read ( ) with open ( outfile , "wb" ) as new_file : new_file . write ( decoded ) gz . close ( ) log . debug ( '{}: file unzipped' . format ( outfile ) ) else : log . debug ( '{}: file already unzipped' . format ( outfile ) ) if delete_original : os . remove ( infile ) return outfile
Decompress a gzip file and optionally set output values.

    Args:
        infile: Path to .gz file
        outfile: Name of output file
        outdir: Path to output directory
        delete_original: If original .gz file should be deleted
        force_rerun_flag: If file should be decompressed if outfile already exists

    Returns:
        str: Path to decompressed file