File tree 4 files changed +24
-12
lines changed
4 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 17
17
18
18
# Reads in data files. Base handler for data analysis
19
19
20
+ import gzip
21
+
20
22
class ReadData :
21
23
22
24
def __init__ (self , filename ):
23
- with open (filename ,'r' ) as self .inp :
24
- self .__read_data ()
25
- self .inp .close ()
25
+ if filename .split ('.' )[- 1 ] == 'gz' :
26
+ self .lines = gzip .open (filename ,'rb' ).read ()
27
+ else :
28
+ self .lines = open (filename ,'r' ).read ()
29
+ self .__read_data ()
26
30
self .N = len (self .data [0 ])
27
31
28
32
def __read_data (self ):
29
- lines = self .inp . readlines ( )
33
+ lines = self .lines . split ( ' \n ' )
30
34
lines = map (lambda x : x .strip (), lines )
31
35
if lines [0 ][0 ] == '#' :
32
36
self .has_header = True
Original file line number Diff line number Diff line change 17
17
18
18
# Reads in data files. Base handler for data analysis
19
19
20
+ import gzip
21
+
20
22
class ReadData :
21
23
22
24
def __init__ (self , filename ):
23
- with open (filename ,'r' ) as self .inp :
24
- self .__read_data ()
25
- self .inp .close ()
25
+ if filename .split ('.' )[- 1 ] == 'gz' :
26
+ self .lines = gzip .open (filename ,'rb' ).read ()
27
+ else :
28
+ self .lines = open (filename ,'r' ).read ()
29
+ self .__read_data ()
26
30
self .N = len (self .data [0 ])
27
31
28
32
def __read_data (self ):
29
- lines = self .inp . readlines ( )
33
+ lines = self .lines . split ( ' \n ' )
30
34
lines = map (lambda x : x .strip (), lines )
31
35
if lines [0 ][0 ] == '#' :
32
36
self .has_header = True
Original file line number Diff line number Diff line change 17
17
18
18
# Reads in data files. Base handler for data analysis
19
19
20
+ import gzip
21
+
20
22
class ReadData :
21
23
22
24
def __init__ (self , filename ):
23
- with open (filename ,'r' ) as self .inp :
24
- self .__read_data ()
25
- self .inp .close ()
25
+ if filename .split ('.' )[- 1 ] == 'gz' :
26
+ self .lines = gzip .open (filename ,'rb' ).read ()
27
+ else :
28
+ self .lines = open (filename ,'r' ).read ()
29
+ self .__read_data ()
26
30
self .N = len (self .data [0 ])
27
31
28
32
def __read_data (self ):
29
- lines = self .inp . readlines ( )
33
+ lines = self .lines . split ( ' \n ' )
30
34
lines = map (lambda x : x .strip (), lines )
31
35
if lines [0 ][0 ] == '#' :
32
36
self .has_header = True
You can’t perform that action at this time.
0 commit comments