Skip to content

Commit

Permalink
Improve typing in sample_sheet_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Aug 7, 2024
1 parent 50d4b9d commit 68ae884
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 4 additions & 2 deletions micall/utils/sample_sheet_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

from csv import DictReader
from pathlib import Path
from typing import TextIO, Dict

from micall.utils.sample_sheet_v1_parser import sample_sheet_v1_parser

def sample_sheet_parser(handle):
def sample_sheet_parser(handle: TextIO) -> Dict[str, object]:
"""
Parse the contents of SampleSheet.csv, convert contents into a
Python dictionary object.
Samples are tracked by sample name and sample number (e.g., S9).
This is to distinguish replicates of the same sample.
"""

handle.seek(0)
return sample_sheet_v1_parser(handle)


Expand Down Expand Up @@ -44,7 +46,7 @@ def main():
parser.add_argument("samplesheet")
args = parser.parse_args()

with open(args.samplesheet, "rb") as f:
with open(args.samplesheet) as f:
ss = sample_sheet_parser(f)
print(ss)

Expand Down
15 changes: 5 additions & 10 deletions micall/utils/sample_sheet_v1_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import re
from typing import List, Dict, Any
from typing import List, Dict, Any, TextIO

def sample_sheet_v1_parser(handle):
def sample_sheet_v1_parser(handle: TextIO) -> Dict[str, object]:
tag = None
get_header = False
header = [] # store Data block column labels
Expand Down Expand Up @@ -147,14 +147,9 @@ def sample_sheet_v1_parser(handle):
# the description field up and change the values in entry
# appropriately.
for desc_field in desc_fields:
name, value, tmp = None, None, None
if sample_sheet_version == 1:
name = desc_field.split(':')[0] # slice #actually this is wrong...
value = desc_field.replace(name + ':', '')
tmp = value.split(sample_delimiter)
elif sample_sheet_version == 2:
name, value = desc_field.split(':')
tmp = value.split(sample_delimiter)
name = desc_field.split(':')[0] # slice #actually this is wrong...
value = desc_field.replace(name + ':', '')
tmp = value.split(sample_delimiter)

for elem in tmp:
samp, proj, val = None, None, None
Expand Down

0 comments on commit 68ae884

Please sign in to comment.