@staticmethod
    def from_file(filename):

        if filename.endswith('.gz'):
            f = gzip.open(filename, 'r')
        else:
            f = open(filename, 'r')
        l = f.readline()
        m = re.match('# (co\d(a|c)\d\d\d\d\d\d\d)', l) # line 1 has subject id
        subject_id = m.group(1)
        alcoholic = (m.group(2)=='a')
        f.readline() # skip line 2
        f.readline() # skip line 3
        l = f.readline()
        m = re.match('# (.*?), trial (\d+)', l) # line 4 has stimulus, trial number
        stimulus = re.sub('\W', '', m.group(1))
        trial_num = int(m.group(2))
        # begin real data, one channel at a time
        data = dict()
        o = []
        t = []
        channels = dict()
        curr = None
        for row in csv.reader(f, delimiter=' '):
            if row[0] == '#':
                if curr is not None:
                    data[curr] = Series(data=o, index=t)
                o = []
                t = []
                assert(row[1] not in channels)
                channels[row[1]] = int(row[3])
                curr = row[1]
            else:
                assert(curr is None or curr == row[1])
                t.append(int(row[2]))
                o.append(float(row[3]))
        if curr is not None:
            data[curr] = Series(data=o, index=t)
        f.close()

        return EegTrial(subject_id=subject_id, alcoholic=alcoholic, trial_num=trial_num, stimulus=stimulus, data=DataFrame(data), channels=Series(channels))
Static factory method for reading an EegTrial object from a (gzipped?) file in "eeg_full."
dataset/ETHPy150Open turambar/pyDatasets/pydatasets/uci/eeg.py/EegTrial.from_file