about summary refs log tree commit diff
path: root/uploader/samples/models.py
blob: 15e509e30693cbff1042fed3da765713233d0393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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())