aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base/species.py
diff options
context:
space:
mode:
authorBonfaceKilz2021-05-04 23:46:45 +0300
committerBonfaceKilz2021-05-05 12:26:04 +0300
commitf2c3528cc81d228a62dfd9e362d0a1202412b098 (patch)
tree0188783979a35e6c2d0c8cfd8938f710ba91b43f /wqflask/base/species.py
parent7c6a60d62389fa945f5a7264cde31cf00ddf9fc4 (diff)
downloadgenenetwork2-f2c3528cc81d228a62dfd9e362d0a1202412b098.tar.gz
base: species: Rewrite Chromosomes using a dataclass
Diffstat (limited to 'wqflask/base/species.py')
-rw-r--r--wqflask/base/species.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/wqflask/base/species.py b/wqflask/base/species.py
index 628bcc56..db1975d4 100644
--- a/wqflask/base/species.py
+++ b/wqflask/base/species.py
@@ -1,6 +1,6 @@
-import collections
-
+from collections import OrderedDict
from dataclasses import dataclass
+from dataclasses import InitVar
from typing import Optional, Dict
from flask import g
@@ -32,17 +32,21 @@ class IndChromosome:
return self.length / 1000000
+@dataclass
class Chromosomes:
- def __init__(self, dataset=None, species=None):
- self.chromosomes = collections.OrderedDict()
- if species != None:
+ """Data related to a chromosome"""
+ dataset: InitVar[Dict] = None
+ species: Optional[str] = None
+
+ def __post_init__(self, dataset):
+ self.chromosomes = OrderedDict()
+ if self.species is not None:
query = (
"SELECT Chr_Length.Name, Chr_Length.OrderId, Length "
"FROM Chr_Length, Species WHERE "
"Chr_Length.SpeciesId = Species.SpeciesId AND "
"Species.Name = "
- "'%s' ORDER BY OrderId" % species.capitalize()
- )
+ "'%s' ORDER BY OrderId" % self.species.capitalize())
else:
self.dataset = dataset
query = (