aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-01 15:41:56 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commitb6ecd0888ccf51b1dd2bfcbbbc4e03b1c5a92699 (patch)
tree59801fba61b68fb9d3f21e6441d033a57ac592b0 /gn3
parent59d2d0a8175c4a06c5363a8a3d3addd683ef9a8d (diff)
downloadgenenetwork3-b6ecd0888ccf51b1dd2bfcbbbc4e03b1c5a92699.tar.gz
Extract a strain name given a csv string and it's header
* gn3/csvcmp.py (extract_strain_name): New function. * gn3/db/sample_data (delete_sample_data): Use the aforementioned function. (insert_sample_data): Ditto. * tests/unit/test_csvcmp: Test cases for above.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/csvcmp.py7
-rw-r--r--gn3/db/sample_data.py5
2 files changed, 10 insertions, 2 deletions
diff --git a/gn3/csvcmp.py b/gn3/csvcmp.py
index ebd323e..360a101 100644
--- a/gn3/csvcmp.py
+++ b/gn3/csvcmp.py
@@ -4,6 +4,13 @@ import uuid
from gn3.commands import run_cmd
+def extract_strain_name(csv_header, data, seek="Strain Name"):
+ for column, value in zip(csv_header.split(","), data.split(",")):
+ if seek in column:
+ return value
+ return ""
+
+
def create_dirs_if_not_exists(dirs: list):
for dir_ in dirs:
if not os.path.exists(dir_):
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index 06b5767..a410978 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -1,3 +1,4 @@
+from gn3.csvcmp import extract_strain_name
from typing import Any, Tuple, Union
import MySQLdb
@@ -200,7 +201,7 @@ def delete_sample_data(conn: Any,
strain_id, data_id, inbredset_id = get_sample_data_ids(
conn=conn, publishxref_id=trait_name,
phenotype_id=phenotype_id,
- strain_name=strain_name)
+ strain_name=extract_strain_name(csv_header, data))
none_case_attrs = {
"Strain Name": lambda: 0,
@@ -273,7 +274,7 @@ def insert_sample_data(conn: Any, # pylint: disable=[R0913]
strain_id, data_id, inbredset_id = get_sample_data_ids(
conn=conn, publishxref_id=trait_name,
phenotype_id=phenotype_id,
- strain_name=strain_name)
+ strain_name=extract_strain_name(csv_header, data))
none_case_attrs = {
"Strain Name": lambda _: 0,