<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_linear2(fn, header=True):
 """Read a plink 2 output file of type glm.linear into a pandas DataFrame. Parameters fn : str Path to the plink file. The file can be gzipped or not. header : str True if the file has a header (this is generally the case unless the file has been processed after it was created). False if no header. Pass None if it's unknown whether the file has a header. Returns ------- res : pandas.DataFrame Dataframe with results. """

    dtypes = {'#CHROM':str, 'POS':int, 'ID':str, 'REF':str, 'ALT1':str,
              'TEST':str, 'OBS_CT':int, 'BETA':float, 'SE':float,
              'T_STAT':float, 'P':float}
    if header is None:
        if fn[-3:] == '.gz':
            from gzip import open
            with open(fn, 'r') as f:
                line = f.readline()
        else:
            with open(fn, 'r') as f:
                line = f.readline()
        header = line [0] == '#'
    if header:
        res = pd.read_table(fn, index_col=2, dtype=dtypes, low_memory=False)
    else:
        cols = ['#CHROM', 'POS', 'ID', 'REF', 'ALT1', 'TEST', 'OBS_CT',
                'BETA', 'SE', 'T_STAT', 'P']
        res = pd.read_table(fn, index_col=2, dtype=dtypes, names=cols,
                            low_memory=False)
    res.columns = [x.replace('#', '') for x in res.columns]
    return(res)