aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-04 23:55:58 +0300
committerBonfaceKilz2021-05-05 12:26:04 +0300
commit941680d5266159fc5c9f2a65131bf283bd1cef1d (patch)
tree78e60a88ba28bec2a43683c7417f1f6f37d1e688 /wqflask
parentf2c3528cc81d228a62dfd9e362d0a1202412b098 (diff)
downloadgenenetwork2-941680d5266159fc5c9f2a65131bf283bd1cef1d.tar.gz
base: chromosomes: Fetch the chromosomes lazily
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/base/species.py12
1 files 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