create_sources.py 1.23 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import logging

from django.core.management.base import BaseCommand
from django.db.utils import IntegrityError

from metagenedb.apps.catalog.models import Source

logging.basicConfig(format='[%(asctime)s] %(levelname)s:%(name)s:%(message)s')
logger = logging.getLogger()

ITEMS_TO_CREATE = [
    {
        'name': 'Virgo',
        'url': 'https://virgo.igs.umaryland.edu/',
        'doi': '10.1038/s41467-020-14677-3'
    },
    {
        'name': 'IGC-9.9M',
        'url': 'https://db.cngb.org/microbiome/genecatalog/genecatalog_human/',
        'doi': '10.1038/nbt.2942'
    },
]


def create_all_sources():
    items_to_create = ITEMS_TO_CREATE
    for item in items_to_create:
        new_entry = Source(**item)
        try:
            new_entry.save()
        except IntegrityError:
            logger.info("%s already exists.", item['name'])


class Command(BaseCommand):
    help = 'Create gene sources (Virgo and IGC 9.9M at the moment).'

    def set_logger_level(self, verbosity):
        if verbosity > 2:
            logger.setLevel(logging.DEBUG)
        elif verbosity > 1:
            logger.setLevel(logging.INFO)

    def handle(self, *args, **options):
        self.set_logger_level(int(options['verbosity']))
        create_all_sources()