Skip to content

Commit c9520b4

Browse files
authored
support gzipped yaml file for function load_spec (#60)
* support gzipped yaml file for function load_spec * fix bug in function run_check * support gzipped yaml file for function load_spec
1 parent a280567 commit c9520b4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

seqspec/seqspec_check.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def validate_check_args(parser, args):
4040
def run_check(spec_fn, o):
4141
spec = load_spec(spec_fn)
4242

43-
errors = check(spec)
43+
errors = check(spec, spec_fn)
4444

4545
if errors:
4646
if o:
@@ -51,7 +51,7 @@ def run_check(spec_fn, o):
5151
return errors
5252

5353

54-
def check(spec: Assay, spec_fn: str = None):
54+
def check(spec: Assay, spec_fn: str):
5555
schema_fn = path.join(path.dirname(__file__), "schema/seqspec.schema.json")
5656

5757
with open(schema_fn, "r") as stream:

seqspec/utils.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@
1313

1414

1515
def load_spec(spec_fn: str):
16-
with open(spec_fn, "r") as stream:
17-
return load_spec_stream(stream)
16+
"""
17+
Reads a YAML file that may be gzipped or not.
18+
19+
:param spec_fn: Path to the YAML or gzipped YAML file.
20+
:return: Parsed YAML content as a Assay object.
21+
"""
22+
try:
23+
# Check if the file is gzipped by attempting to open it as such
24+
with gzip.open(spec_fn, "rt") as stream:
25+
return load_spec_stream(stream)
26+
except gzip.BadGzipFile:
27+
# If opening as gzip fails, assume it's a regular YAML file
28+
with open(spec_fn, "r") as stream:
29+
return load_spec_stream(stream)
1830

1931

2032
def load_spec_stream(spec_stream: io.IOBase):

0 commit comments

Comments
 (0)