aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2022-02-24 17:13:17 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commite225054a167086b97923a8449fd0af013ce26933 (patch)
tree7e72266aa739c2de8b55b70ef9c286522f342276 /gn3
parent613987ef99009574bfd403973210de4d90da7c73 (diff)
downloadgenenetwork3-e225054a167086b97923a8449fd0af013ce26933.tar.gz
Create new method for filling csv with a default value
* gn3/csvcmp.py (fill_csv): Given a csv text with uneven or incomplete fields whole length are less than width, fill them with a value which defaults to "x". * tests/unit/test_csvcmp.py (test_fill_csv): Test cases for the above.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/csvcmp.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index 35133dc..7a4a026 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -67,3 +67,14 @@ def csv_diff(base_csv, delta_csv, tmp_dir="/tmp"):
if os.path.exists(file_name2):
os.remove(file_name2)
return _r
+
+
+def fill_csv(csv_text, width, value="x"):
+ data = []
+ for line in csv_text.strip().split("\n"):
+ if line.startswith("Strain") or line.startswith("#"):
+ data.append(line)
+ elif line:
+ data.append(
+ ",".join((_n:=line.split(",")) + [value] * (width - len(_n))))
+ return "\n".join(data)