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

change table to contain version of eggnog

parent db4cb890
Pipeline #19817 passed with stages
in 2 minutes and 25 seconds
......@@ -54,7 +54,7 @@ class CustomRouter(DefaultRouter):
api_router = CustomRouter()
api_router.register(r'functions', views.FunctionViewSet, basename='functions')
api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='kegg-orthologies')
api_router.register(r'eggnogs', views.EggNogViewSet, basename='eggnogs')
api_router.register(r'eggnogs', views.EggNOGv5ViewSet, basename='eggnogs')
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
......
from .function import EggNogViewSet, KeggOrthologyViewSet, FunctionViewSet # noqa
from .function import EggNOGv5ViewSet, KeggOrthologyViewSet, FunctionViewSet # noqa
from .gene import GeneViewSet # noqa
from .taxonomy import TaxonomyViewSet # noqa
......@@ -7,8 +7,8 @@ from rest_framework.viewsets import ModelViewSet
from metagenedb.api.catalog.filters import FunctionFilter
from metagenedb.api.catalog.qparams_validators.function import FunctionQueryParams
from metagenedb.apps.catalog.models import EggNog, Function, KeggOrthology
from metagenedb.apps.catalog.serializers import EggNogSerializer, FunctionSerializer, KeggOrthologySerializer
from metagenedb.apps.catalog.models import EggNOGv5, Function, KeggOrthology
from metagenedb.apps.catalog.serializers import EggNOGSerializer, FunctionSerializer, KeggOrthologySerializer
from metagenedb.common.utils.external_api.togows import GetFunctionExternalInfo
from .bulk_viewset import BulkViewSet
......@@ -57,7 +57,7 @@ class KeggOrthologyViewSet(ModelViewSet):
return Response(returned_data)
class EggNogViewSet(ModelViewSet):
queryset = EggNog.objects.all()
serializer_class = EggNogSerializer
class EggNOGv5ViewSet(ModelViewSet):
queryset = EggNOGv5.objects.all()
serializer_class = EggNOGSerializer
lookup_field = 'function_id'
......@@ -2,7 +2,7 @@ from rest_framework.test import APITestCase
import mock
from metagenedb.apps.catalog.factory import EggNogFactory, KeggOrthologyFactory
from metagenedb.apps.catalog.factory import EggNOGv5Factory, KeggOrthologyFactory
from metagenedb.common.utils.mocks.metagenedb import (
MetageneDBCatalogFunctionAPIMock, MetageneDBCatalogKeggOrthologyAPIMock
)
......@@ -14,7 +14,7 @@ class TestKeggOrthologyViewSet(APITestCase):
self.function_api = MetageneDBCatalogFunctionAPIMock(self.client)
self.kegg_ortho_api = MetageneDBCatalogKeggOrthologyAPIMock(self.client)
self.kegg_function = KeggOrthologyFactory.create()
self.eggnog_function = EggNogFactory.create()
self.eggnog_function = EggNOGv5Factory.create()
def test_retrieve(self):
for function in [self.kegg_function, self.eggnog_function]:
......
from django.contrib import admin
from metagenedb.apps.catalog.models import EggNog, EggNogFunctionalCategory, Function, KeggOrthology
from metagenedb.apps.catalog.models import EggNOGv5, EggNOGFunctionalCategory, Function, KeggOrthology
@admin.register(KeggOrthology)
......@@ -17,8 +17,8 @@ class FunctionAdmin(admin.ModelAdmin):
search_fields = ('function_id',)
@admin.register(EggNog)
class EggNogAdmin(admin.ModelAdmin):
@admin.register(EggNOGv5)
class EggNOGv5Admin(admin.ModelAdmin):
list_display = ('function_id', 'name', 'get_functional_categories')
search_fields = ('function_id', 'name')
......@@ -30,8 +30,8 @@ class EggNogAdmin(admin.ModelAdmin):
get_functional_categories.short_description = 'Functional categories'
@admin.register(EggNogFunctionalCategory)
class EggNogFunctionalCategoryAdmin(admin.ModelAdmin):
@admin.register(EggNOGFunctionalCategory)
class EggNOGFunctionalCategoryAdmin(admin.ModelAdmin):
list_display = ('category_id', 'name', 'group')
search_fields = ('category_id', 'name')
from .function import EggNogFactory, FunctionFactory, KeggOrthologyFactory # noqa
from .function import EggNOGv5Factory, FunctionFactory, KeggOrthologyFactory # noqa
from .gene import GeneFactory # noqa
from .taxonomy import TaxonomyFactory # noqa
......@@ -22,9 +22,9 @@ class FunctionFactory(BaseFunctionFactory):
function_id = FuzzyLowerText(prefix='function-', length=15)
class EggNogFactory(BaseFunctionFactory):
class EggNOGv5Factory(BaseFunctionFactory):
class Meta:
model = models.EggNog
model = models.EggNOGv5
class KeggOrthologyFactory(BaseFunctionFactory):
......
......@@ -3,7 +3,7 @@ import logging
from django.core.management.base import BaseCommand
from django.core.exceptions import ValidationError
from metagenedb.apps.catalog.models import EggNogFunctionalCategory
from metagenedb.apps.catalog.models import EggNOGFunctionalCategory
from metagenedb.common.utils.parsers.eggnog import EggNOGFunctionalCategoriesParser
logging.basicConfig(format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s')
......@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
class ImportEggNOGFunctionalCategories(object):
LOOKUP_FIELD = 'category_id'
MODEL = EggNogFunctionalCategory
MODEL = EggNOGFunctionalCategory
GROUP_MAPPING = {
'Information storage and processing': 'info_storage_processing',
'Cellular processes and signaling': 'cellular_processes_signaling',
......
......@@ -3,7 +3,7 @@ import logging
from django.core.management.base import BaseCommand
from django.core.exceptions import ValidationError
from metagenedb.apps.catalog.models import EggNog, EggNogFunctionalCategory
from metagenedb.apps.catalog.models import EggNOGv5, EggNOGFunctionalCategory
from metagenedb.common.utils.chunks import file_len
from metagenedb.common.utils.parsers import EggNOGAnnotationLineParser
......@@ -24,7 +24,7 @@ class ImportEggNOG(object):
self.skipped_errors = []
def _build_functional_category_dict(self):
all_categories = EggNogFunctionalCategory.objects.all()
all_categories = EggNOGFunctionalCategory.objects.all()
if not all_categories:
raise Exception("You need to create Functional categories first.")
self.functional_cat_instances = {cat.category_id: cat for cat in all_categories}
......@@ -43,14 +43,14 @@ class ImportEggNOG(object):
payload = {k: v for k, v in eggnog_dict.items() if v != ""}
eggnog = None
try:
eggnog = EggNog(**payload)
eggnog = EggNOGv5(**payload)
eggnog.full_clean()
eggnog.save()
self.created_count += 1
except ValidationError as validation_error:
if 'function_id' in validation_error.error_dict.keys():
try:
eggnog = EggNog.objects.get(function_id=payload.get('function_id'))
eggnog = EggNOGv5.objects.get(function_id=payload.get('function_id'))
for k, v in payload.items():
setattr(eggnog, k, v)
eggnog.full_clean()
......
# Generated by Django 3.0 on 2019-12-11 22:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0015_m2m_func_cat_eggnog'),
]
operations = [
migrations.RenameModel(
old_name='EggNog',
new_name='EggNOGv5',
),
migrations.AlterField(
model_name='eggnogv5',
name='functional_categories',
field=models.ManyToManyField(to='catalog.EggNOGFunctionalCategory'),
),
]
from .function import EggNog, EggNogFunctionalCategory, Function, KeggOrthology # noqa
from .function import EggNOGv5, EggNOGFunctionalCategory, Function, KeggOrthology # noqa
from .gene import Gene, GeneFunction # noqa
from .taxonomy import Taxonomy # noqa
......@@ -36,7 +36,7 @@ class KeggOrthology(Function):
verbose_name_plural = "KEGG orthologies"
class EggNogFunctionalCategory(models.Model):
class EggNOGFunctionalCategory(models.Model):
GROUP_CHOICES = [
('info_storage_processing', 'Information Storage and Processing'),
('cellular_processes_signaling', 'Cellular Processes and Signaling'),
......@@ -56,14 +56,14 @@ class EggNogFunctionalCategory(models.Model):
verbose_name_plural = "EggNOG functional categories"
class EggNog(Function):
class EggNOGv5(Function):
SOURCE = 'eggnog'
functional_categories = models.ManyToManyField(EggNogFunctionalCategory)
functional_categories = models.ManyToManyField(EggNOGFunctionalCategory)
def __init__(self, *args, **kwargs):
super(EggNog, self).__init__(source=self.SOURCE, *args, **kwargs)
super(EggNOGv5, self).__init__(source=self.SOURCE, *args, **kwargs)
class Meta:
verbose_name = "EggNOG"
verbose_name_plural = "EggNOGs"
verbose_name = "EggNOG v5.0"
verbose_name_plural = "EggNOGs v5.0"
from .function import EggNogSerializer, FunctionSerializer, KeggOrthologySerializer # noqa
from .function import EggNOGSerializer, FunctionSerializer, KeggOrthologySerializer # noqa
from .gene import GeneSerializer # noqa
from .taxonomy import TaxonomySerializer # noqa
from rest_framework import serializers
from metagenedb.apps.catalog.models import EggNog, Function, KeggOrthology
from metagenedb.apps.catalog.models import EggNOGv5, Function, KeggOrthology
from .bulk_list import BulkListSerializer
......@@ -18,17 +18,17 @@ class FunctionSerializer(serializers.ModelSerializer):
fields = ('function_id', 'source', 'name')
class EggNogListSerializer(BulkListSerializer):
class EggNOGListSerializer(BulkListSerializer):
class Meta:
model = EggNog
model = EggNOGv5
class EggNogSerializer(serializers.ModelSerializer):
class EggNOGSerializer(serializers.ModelSerializer):
class Meta:
model = EggNog
list_serializer_class = EggNogListSerializer
model = EggNOGv5
list_serializer_class = EggNOGListSerializer
fields = ('function_id', 'name', 'functional_categories')
......
......@@ -90,5 +90,5 @@ class MetageneDBCatalogKeggOrthologyAPIMock(MetageneDBCatalogFunctionAPIMock):
REVERSE_PATH = 'catalog:v1:kegg-orthologies'
class MetageneDBCatalogEggNogAPIMock(MetageneDBCatalogFunctionAPIMock):
class MetageneDBCatalogEggNOGv5APIMock(MetageneDBCatalogFunctionAPIMock):
REVERSE_PATH = 'catalog:v1:eggnogs'
......@@ -4,13 +4,13 @@ from rest_framework.test import APITestCase
from metagenedb.common.utils.mocks.metagenedb import (
MetageneDBCatalogTaxonomyAPIMock,
MetageneDBCatalogEggNogAPIMock,
MetageneDBCatalogEggNOGv5APIMock,
MetageneDBCatalogKeggOrthologyAPIMock
)
from metagenedb.apps.catalog.factory import (
TaxonomyFactory,
KeggOrthologyFactory,
EggNogFactory
EggNOGv5Factory
)
from scripts.populate_db.import_igc_data import ImportIGCGenes
......@@ -302,12 +302,12 @@ class TestBuildBuildFunctionCatalog(APITestCase):
@classmethod
def setUpTestData(cls):
cls.keggs = KeggOrthologyFactory.create_batch(100)
cls.eggnogs = EggNogFactory.create_batch(100)
cls.eggnogs = EggNOGv5Factory.create_batch(100)
def setUp(self):
self.import_igc_genes = ImportIGCGenes('test', 'test_url', 'test_token')
self.kegg_api_mock = MetageneDBCatalogKeggOrthologyAPIMock(self.client)
self.eggnog_api_mock = MetageneDBCatalogEggNogAPIMock(self.client)
self.eggnog_api_mock = MetageneDBCatalogEggNOGv5APIMock(self.client)
self.import_igc_genes.metagenedb_kegg_api = self.kegg_api_mock
self.import_igc_genes.metagenedb_eggnog_api = self.eggnog_api_mock
......
Markdown is supported
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