diff options
author | Frederick Muriuki Muriithi | 2024-09-09 14:06:31 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-09 16:41:46 -0500 |
commit | 9cd33ddac3d6848c5443962d66494635feadef51 (patch) | |
tree | 385a559380f4d6a961fefb38ad410ad9ca27b052 /uploader/samples/models.py | |
parent | 707c715d1e336ee45bdcced031881ed603b9297a (diff) | |
download | gn-uploader-9cd33ddac3d6848c5443962d66494635feadef51.tar.gz |
Initialise samples uploads
* Move existing code to new module
* Rework the UI: create new templates
* Rework the routes: Select species and populations before attempting
an upload.
Diffstat (limited to 'uploader/samples/models.py')
-rw-r--r-- | uploader/samples/models.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/uploader/samples/models.py b/uploader/samples/models.py new file mode 100644 index 0000000..15e509e --- /dev/null +++ b/uploader/samples/models.py @@ -0,0 +1,19 @@ +"""Functions for handling samples.""" +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +def samples_by_species_and_population( + conn: mdb.Connection, + species_id: int, + population_id: int +) -> tuple[dict, ...]: + """Fetch the samples by their species and population.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + "SELECT iset.InbredSetId, s.* FROM InbredSet AS iset " + "INNER JOIN StrainXRef AS sxr ON iset.InbredSetId=sxr.InbredSetId " + "INNER JOIN Strain AS s ON sxr.StrainId=s.Id " + "WHERE s.SpeciesId=%(species_id)s " + "AND iset.InbredSetId=%(population_id)s", + {"species_id": species_id, "population_id": population_id}) + return tuple(cursor.fetchall()) |