forked from enviPath/enviPy
[Feature] External Identifier/References
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#139
This commit is contained in:
@ -116,7 +116,7 @@ class Command(BaseCommand):
|
||||
'full_name': 'KEGG Reaction Database',
|
||||
'description': 'Database of biochemical reactions',
|
||||
'base_url': 'https://www.genome.jp',
|
||||
'url_pattern': 'https://www.genome.jp/entry/reaction+{id}'
|
||||
'url_pattern': 'https://www.genome.jp/entry/{id}'
|
||||
},
|
||||
{
|
||||
'name': 'UniProt',
|
||||
|
||||
57
epdb/management/commands/import_external_identifiers.py
Normal file
57
epdb/management/commands/import_external_identifiers.py
Normal file
@ -0,0 +1,57 @@
|
||||
from csv import DictReader
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from epdb.models import *
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
STR_TO_MODEL = {
|
||||
'Compound': Compound,
|
||||
'CompoundStructure': CompoundStructure,
|
||||
'Reaction': Reaction,
|
||||
}
|
||||
|
||||
STR_TO_DATABASE = {
|
||||
'ChEBI': ExternalDatabase.objects.get(name='ChEBI'),
|
||||
'RHEA': ExternalDatabase.objects.get(name='RHEA'),
|
||||
'KEGG Reaction': ExternalDatabase.objects.get(name='KEGG Reaction'),
|
||||
'PubChem Compound': ExternalDatabase.objects.get(name='PubChem Compound'),
|
||||
'PubChem Substance': ExternalDatabase.objects.get(name='PubChem Substance'),
|
||||
}
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--data',
|
||||
type=str,
|
||||
help='Path of the ID Mapping file.',
|
||||
required=True,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--replace-host',
|
||||
type=str,
|
||||
help='Replace https://envipath.org/ with this host, e.g. http://localhost:8000/',
|
||||
)
|
||||
|
||||
@transaction.atomic
|
||||
def handle(self, *args, **options):
|
||||
with open(options['data']) as fh:
|
||||
reader = DictReader(fh)
|
||||
for row in reader:
|
||||
clz = self.STR_TO_MODEL[row['model']]
|
||||
|
||||
url = row['url']
|
||||
if options['replace_host']:
|
||||
url = url.replace('https://envipath.org/', options['replace_host'])
|
||||
|
||||
instance = clz.objects.get(url=url)
|
||||
db = self.STR_TO_DATABASE[row['identifier_type']]
|
||||
|
||||
ExternalIdentifier.objects.create(
|
||||
content_object=instance,
|
||||
database=db,
|
||||
identifier_value=row['identifier_value'],
|
||||
url=db.url_pattern.format(id=row['identifier_value']),
|
||||
is_primary=False
|
||||
)
|
||||
Reference in New Issue
Block a user