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

start modifying source

parent de1d5a5a
from .gene import GeneAdmin # noqa
from .function import FunctionAdmin, KeggOrthologyAdmin # noqa
from .statistics import Statistics # noqa
from .statistics import StatisticsAdmin # noqa
from .source import SourceAdmin # noqa
from .taxonomy import TaxonomyAdmin # noqa
from django.contrib import admin
from metagenedb.apps.catalog.models import Source
@admin.register(Source)
class SourceAdmin(admin.ModelAdmin):
list_display = ('name', 'url', 'doi')
search_fields = ('name',)
......@@ -18,7 +18,6 @@ class GeneFactory(DjangoModelFactory):
gene_id = Faker('bothify', text='gene-?#?#??-#??#?#')
name = Faker('bothify', text='Gene_name-##-????')
length = Faker('pyint', min_value=200, max_value=4200)
source = fuzzy.FuzzyChoice(GENE_SOURCES)
class GeneWithTaxonomyFactory(GeneFactory):
......
......@@ -6,7 +6,7 @@ from django.core.management.base import BaseCommand
from metagenedb.apps.catalog.factory import GeneFactory, GeneWithEggNOGFactory, GeneWithKeggFactory
from metagenedb.apps.catalog.factory.taxonomy import generate_simple_db as gen_tax_db
from metagenedb.apps.catalog.models import (
Gene, Function, Taxonomy
Gene, Function, Source, Taxonomy
)
from metagenedb.apps.catalog.management.commands.compute_stats import (
ComputeCounts, ComputeGeneLength, ComputeTaxonomyRepartition, ComputeTaxonomyPresence
......@@ -21,6 +21,12 @@ def empty_db():
Gene.objects.all().delete()
Taxonomy.objects.all().delete()
Function.objects.all().delete()
Source.objects.all().delete()
def create_source_db():
test_source = Source(name="Test-source")
test_source.save()
def create_taxonomy_db():
......@@ -48,6 +54,7 @@ def compute_stats():
def create_small_db():
empty_db()
create_source_db()
create_taxonomy_db()
create_genes_db()
compute_stats()
......
# Generated by Django 3.1.7 on 2021-04-12 10:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0028_index_source_and_functions'),
]
operations = [
migrations.CreateModel(
name='Source',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(db_index=True, max_length=100, unique=True)),
('url', models.CharField(blank=True, max_length=100)),
('doi', models.CharField(blank=True, max_length=100)),
('tools', models.JSONField(blank=True, null=True)),
],
),
]
# Generated by Django 3.1.7 on 2021-04-12 10:26
from django.db import migrations, models
import django.db.models.deletion
def link_to_source(apps, schema_editor):
Gene = apps.get_model('catalog', 'Gene')
Source = apps.get_models('catalog', 'Source')
mapping_source = {
'igc': Source.objects.get(name='IGC-9.9M'),
'virgo': Source.objects.get(name='Virgo')
}
for row in Gene.objects.all():
print(row.source)
if row.source != 'undef':
row.new_source = mapping_source.get(row.source)
row.save()
class Migration(migrations.Migration):
dependencies = [
('catalog', '0029_source'),
]
operations = [
migrations.AddField(
model_name='gene',
name='new_source',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='genes', to='catalog.source'),
),
migrations.RemoveField(
model_name='gene',
name='source',
),
migrations.RenameField(
model_name='gene',
old_name='new_source',
new_name='source',
),
]
from .function import EggNOG, EggNogFunctionalCategory, Function, KeggOrthology # noqa
from .gene import Gene, GeneFunction # noqa
from .statistics import Statistics # noqa
from .source import Source # noqa
from .taxonomy import Taxonomy # noqa
......@@ -30,7 +30,11 @@ class Gene(models.Model):
on_delete=models.SET_NULL,
null=True, blank=True
)
source = models.CharField(max_length=10, db_index=True, choices=SOURCE_CHOICES, default=UNDEFINED)
source = models.ForeignKey(
'Source', related_name='genes',
on_delete=models.SET_NULL,
null=True, blank=True
)
def __str__(self) -> str:
return self.gene_id
......
from django.db import models
class Source(models.Model):
name = models.CharField(max_length=100, unique=True, db_index=True)
url = models.CharField(max_length=100, blank=True)
doi = models.CharField(max_length=100, blank=True)
tools = models.JSONField(blank=True, null=True)
def __str__(self):
return f"{self.name}"
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