From 941680d5266159fc5c9f2a65131bf283bd1cef1d Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 4 May 2021 23:55:58 +0300 Subject: base: chromosomes: Fetch the chromosomes lazily --- wqflask/base/species.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wqflask/base/species.py b/wqflask/base/species.py index db1975d4..430bb675 100644 --- a/wqflask/base/species.py +++ b/wqflask/base/species.py @@ -39,7 +39,13 @@ class Chromosomes: species: Optional[str] = None def __post_init__(self, dataset): - self.chromosomes = OrderedDict() + if self.species is None: + self.dataset = dataset + + @property + def chromosomes(self): + """Lazily fetch the chromosomes""" + chromosomes = OrderedDict() if self.species is not None: query = ( "SELECT Chr_Length.Name, Chr_Length.OrderId, Length " @@ -48,7 +54,6 @@ class Chromosomes: "Species.Name = " "'%s' ORDER BY OrderId" % self.species.capitalize()) else: - self.dataset = dataset query = ( "SELECT Chr_Length.Name, Chr_Length.OrderId, " "Length FROM Chr_Length, InbredSet WHERE " @@ -57,5 +62,6 @@ class Chromosomes: "'%s' ORDER BY OrderId" % self.dataset.group.name) results = g.db.execute(query).fetchall() for item in results: - self.chromosomes[item.OrderId] = IndChromosome( + chromosomes[item.OrderId] = IndChromosome( item.Name, item.Length) + return chromosomes -- cgit v1.2.3