Commit cfecdeaa authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

compute counts for all, virgo and igc genes

parent 50ec042e
Pipeline #30380 passed with stages
in 3 minutes and 38 seconds
......@@ -37,12 +37,17 @@ class ComputeCounts(ComputeStatistics):
'count_all', 'count_has_function', 'count_has_taxonomy', 'count_has_function_has_taxonomy'
]
FUNCTION_SOURCES = ['kegg', 'eggnog']
def compute_count(self, method, **kwargs):
gene_stats = GeneStatistics()
logger.info("Call GeneStatistics.%s(%s)", method, kwargs)
GENE_SOURCES = ['all', 'igc', 'virgo']
def compute_count(self, method, filters=None, **kwargs):
if filters is None:
filters = {}
gene_stats = GeneStatistics(filters=filters)
print_kwargs = '_'.join([str(k) + '-' + str(v) for k, v in kwargs.items() if v])
print_filters = '_'.join([str(k) + '-' + str(v) for k, v in filters.items() if v])
logger.info("Call GeneStatistics(%s).%s(%s)", print_filters, method, print_kwargs)
payload = {
'stats_id': slugify(f"GeneStatistics.{method}({kwargs})"),
'stats_id': slugify(f"GeneStatistics({print_filters}).{method}({print_kwargs})"),
'body': {
'count': getattr(gene_stats, method)(**kwargs)
}
......@@ -50,10 +55,15 @@ class ComputeCounts(ComputeStatistics):
self._save_to_db(payload)
def all(self):
for method in self.METHODS:
self.compute_count(method)
for source in self.FUNCTION_SOURCES:
self.compute_count('count_has_function', source=source)
for gene_source in self.GENE_SOURCES:
if gene_source == 'all':
filters = {}
else:
filters = {'source': gene_source}
for method in self.METHODS:
self.compute_count(method, filters=filters)
for source in self.FUNCTION_SOURCES:
self.compute_count('count_has_function', filters=filters, source=source)
class ComputeGeneLength(ComputeStatistics):
......
......@@ -11,10 +11,17 @@ from metagenedb.common.utils.dict import extract_labels_and_values
class Statistics(ABC):
model = None
def get_queryset(self, filters=None):
def __init__(self, filters=None):
if filters is None:
filters = {}
return self.model.objects.filter(**filters)
self.filters = {}
else:
self.filters = filters
def get_queryset(self, filters=None):
add_filters = filters
if add_filters is None:
add_filters = {}
return self.model.objects.filter(**self.filters).filter(**add_filters)
class GeneStatistics(Statistics):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment