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

do not erase kegg while linking eggnog for virgo

parent e346db16
Pipeline #29999 passed with stages
in 3 minutes and 29 seconds
......@@ -9,6 +9,7 @@ logger = logging.getLogger(__name__)
class HandleFunctions:
FUN_SOURCE_TO_DELETE = ['kegg', 'eggnog'] # links to get rid of everytime
def _build_function_mapping(self, source):
logger.info("Building local mapping for %s function...", source)
......@@ -67,11 +68,15 @@ class HandleFunctions:
mapping.append(GeneFunction(gene=genes[gene_id], function=function))
return mapping
def _delete_previous_annotations(self, genes):
for function_source in self.FUN_SOURCE_TO_DELETE:
GeneFunction.objects.filter(gene__in=genes.values(), function__source=function_source).delete()
def link_genes_to_functions(self, functions):
cleaned_functions = self._clean_functions(functions)
genes = Gene.objects.in_bulk(cleaned_functions.keys(), field_name='gene_id')
# Get all link with corresponding genes & Delete them
GeneFunction.objects.filter(gene__in=genes.values()).delete()
self._delete_previous_annotations(genes)
# Generate table for bulk_create of function <-> gene and create it
GeneFunction.objects.bulk_create(
self._generate_gene_function_mapping(cleaned_functions, genes)
......
......@@ -19,6 +19,8 @@ class ImportVirgoGeneEggNOGAnnotation(BaseImportGenes, HandleFunctions):
SOURCE = 'virgo'
PARSER = VirgoEggNOGLineParser
FUN_SOURCE_TO_DELETE = ['eggnog']
def _clean_functions(self, functions, unknown_val='unknown'):
"""
Get rid of functions that are not in the db or entitled unknown
......
......@@ -19,6 +19,8 @@ class ImportVirgoGeneKeggAnnotation(BaseImportGenes, HandleFunctions):
SOURCE = 'virgo'
PARSER = VirgoKEGGLineParser
FUN_SOURCE_TO_DELETE = ['kegg']
def _clean_functions(self, functions, unknown_val='unknown'):
"""
Get rid of functions that are not in the db or entitled unknown
......
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