From 68dd9d55cf41e057658b7e2ed3bdd7c5dfadf354 Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 22 May 2023 17:30:27 +0000 Subject: Use 'with open()' syntax Initialize samplelist variable --- gn3/db/datasets.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'gn3') diff --git a/gn3/db/datasets.py b/gn3/db/datasets.py index 48cd195..470e430 100644 --- a/gn3/db/datasets.py +++ b/gn3/db/datasets.py @@ -12,25 +12,25 @@ def retrieve_sample_list(group: str): the "official" sample list is stored """ + samplelist = [] genofile_path = os.environ.get("GENENETWORK_FILES") + "/genotype/" + group + ".geno" if os.path.isfile(genofile_path): - genofile = open(genofile_path) + with open(genofile_path, "r") as genofile: + for line in genofile: + line = line.strip() + if not line: + continue + if line.startswith(("#", "@")): + continue + break - for line in genofile: - line = line.strip() - if not line: - continue - if line.startswith(("#", "@")): - continue - break + headers = line.split("\t") - headers = line.split("\t") - - if headers[3] == "Mb": - samplelist = headers[4:] - else: - samplelist = headers[3:] - return samplelist + if headers[3] == "Mb": + samplelist = headers[4:] + else: + samplelist = headers[3:] + return samplelist def retrieve_group_name( group_id: int, connection: any): -- cgit v1.2.3