From 789d483fe8877c08a07d0f94cb22e3e33a5888bc Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 12 Apr 2022 12:54:57 +0300 Subject: Strip any newline, tab or carriage-return chars from sample data * gn3/db/sample_data.py (get_trait_csv_sample_data): Strip out "\n", "\t", or "\r" from the sample data. See: --- gn3/db/sample_data.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gn3') diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index 9e9d527..3f7e2da 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -1,6 +1,7 @@ """Module containing functions that work with sample data""" from typing import Any, Tuple, Dict, Callable +import re import collections import MySQLdb @@ -90,10 +91,13 @@ def get_trait_csv_sample_data( if data[1] == "x": csv_data[data[0]] = None else: - sample, case_attr, value = data[0], data[1], data[2] + sample, case_attr, value = [ + re.sub(r"(\\n|\\r|\\t|\\)", "", x).strip() + for x in [data[0], data[1], data[2]] + ] if not csv_data.get(sample): csv_data[sample] = {} - csv_data[sample][case_attr] = None if value == "x" else value + csv_data[sample][case_attr] = value case_attr_columns.add(case_attr) if not case_attr_columns: return "Strain Name,Value,SE,Count\n" + "\n".join(csv_data.keys()) -- cgit v1.2.3