diff options
author | Muriithi Frederick Muriuki | 2021-09-06 06:47:52 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2021-09-06 06:47:52 +0300 |
commit | 4ce5695a35e92a704add8d497266bb2986a593f6 (patch) | |
tree | d6c866b3c4e99fdcb1cff2e27c45fdeef4ce0e12 /gn3 | |
parent | 608ff9c6ff668d18f0c42aebf658ef80b517a6de (diff) | |
download | genenetwork3-4ce5695a35e92a704add8d497266bb2986a593f6.tar.gz |
Handle type-coercion exceptions
* gn3/computations/qtlreaper.py: handle exceptions
Sometimes, the values being parsed are plain strings and cannot be cast to
the float types. This commit handles that by casting only those values that
can be cast to float, and returning the others as strings.
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/computations/qtlreaper.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py index 30c7051..eff2a80 100644 --- a/gn3/computations/qtlreaper.py +++ b/gn3/computations/qtlreaper.py @@ -94,9 +94,15 @@ def parse_reaper_main_results(results_file): with open(results_file, "r") as infile: lines = infile.readlines() + def __parse_column_value(value): + try: + return float(value) + except: + return value + def __parse_line(line): items = line.strip().split("\t") - return items[0:2] + [float(item) for item in items[2:]] + return items[0:2] + [__parse_column_value(item) for item in items[2:]] header = lines[0].strip().split("\t") return [dict(zip(header, __parse_line(line))) for line in lines[1:]] |