aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/sample_data.py
diff options
context:
space:
mode:
authorBonfaceKilz2022-04-06 16:25:23 +0300
committerBonfaceKilz2022-04-07 11:54:28 +0300
commitdc71058e894c9857de68c7844bfc4b813c0532da (patch)
tree1bd02314bd4e754673f307c905b247c2047b5f8d /gn3/db/sample_data.py
parenta7b7cdd1a5f1a9d071c5fd11c6f1fefa5302a838 (diff)
downloadgenenetwork3-dc71058e894c9857de68c7844bfc4b813c0532da.tar.gz
Use case attribute id inside brackets if present during insertions
* gn3/db/sample_data.py (insert_sample_data): If an id is present in the column header, use it. * tests/unit/db/test_sample_data.py (test_insert_sample_data): Update tests to capture the above.
Diffstat (limited to 'gn3/db/sample_data.py')
-rw-r--r--gn3/db/sample_data.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index 47be5b0..518d2a2 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -343,25 +343,28 @@ def insert_sample_data(
def __insert_case_attribute(conn, case_attr, value):
if value != "x":
with conn.cursor() as cursor:
- cursor.execute(
- "SELECT Id FROM " "CaseAttribute WHERE Name = %s",
- (case_attr,),
- )
- if case_attr_id := cursor.fetchone():
- case_attr_id = case_attr_id[0]
+ (id_, name) = parse_csv_column(case_attr)
+ if not id_:
+ cursor.execute(
+ "SELECT Id FROM CaseAttribute WHERE Name = %s",
+ (case_attr,),
+ )
+ if case_attr_id := cursor.fetchone():
+ id_ = case_attr_id[0]
+
cursor.execute(
"SELECT StrainId FROM "
"CaseAttributeXRefNew WHERE StrainId = %s "
"AND CaseAttributeId = %s "
"AND InbredSetId = %s",
- (strain_id, case_attr_id, inbredset_id),
+ (strain_id, id_, inbredset_id),
)
- if (not cursor.fetchone()) and case_attr_id:
+ if (not cursor.fetchone()) and id_:
cursor.execute(
"INSERT INTO CaseAttributeXRefNew "
"(StrainId, CaseAttributeId, Value, InbredSetId) "
"VALUES (%s, %s, %s, %s)",
- (strain_id, case_attr_id, value, inbredset_id),
+ (strain_id, id_, value, inbredset_id),
)
row_count = cursor.rowcount
return row_count