Skip to content

Commit

Permalink
updates relative to trc chemtwins #2
Browse files Browse the repository at this point in the history
  • Loading branch information
stuchalk committed Dec 30, 2022
1 parent 286e2e0 commit 7922165
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ scyjava = ">=1.5.1"
qwikidata = ">=0.4"
pytest = ">=7.1"
requests = ">=2.28.1"
setuptools = ">=65.5"
rdkit-pypi = "*"
paramiko = "*"
crossrefapi = "*"
Expand Down
20 changes: 0 additions & 20 deletions requirements.txt

This file was deleted.

28 changes: 26 additions & 2 deletions substances/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import django
import time
import requests
import urllib.parse

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sciflow.settings")
django.setup()
Expand All @@ -22,9 +23,32 @@
from django.test import RequestFactory
from django.db.models import Q

# search key2name for names with 'common name' in them and check names on OPSIN for valid IUPAC Name
# search keynames to find missing chemtwin files and extra ones(?)
if True:
resp = requests.get('')
resp = requests.get('https://scidata.unf.edu/tranche/chalklab/chemtwin/keynames.json')
jsn = resp.content
twins = json.loads(jsn)
for key, name in twins.items():
resp = requests.get('https://scidata.unf.edu/tranche/chalklab/chemtwin/' + key + '.jsonld')
if resp.status_code != 200:
print('missing ' + key)

# search keynames for names with 'common name' in them and check names on OPSIN for valid IUPAC Name
if False:
resp = requests.get('https://scidata.unf.edu/tranche/chalklab/chemtwin/keynames.json')
jsn = resp.content
twins = json.loads(jsn)
for key, name in twins.items():
if 'common' in name:
n = name.replace(' (common name)', '')
resp = requests.get('https://opsin.ch.cam.ac.uk/opsin/' + n)
jsn = resp.content.decode('utf-8')
out = json.loads(jsn)
if out['status'] == 'SUCCESS':
sub = Substances.objects.filter(inchikey=key).values_list('id', 'name')[0]
addkey = Identifiers(substance_id=sub[0], type='iupacname', value=sub[1], source='trc')
addkey.save()
print('IUPAC name added for ' + key)

# find missing twin files
if False:
Expand Down
5 changes: 3 additions & 2 deletions substances/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


def molfile(request, subid):
""" get the molefile of a substance"""
file = Structures.objects.get(substance_id=subid)
return HttpResponse(str(file.molfile), content_type="text/plain")

Expand Down Expand Up @@ -126,8 +127,8 @@ def subview(request, subid):
if not descs:
key = ""
for i in ids:
if i.type == 'inchikey':
key = i.value
if i[0] == 'inchikey': # tuple not dictionary
key = i[1]
break
m, i, descs, srcs = getsubdata(key)
savedescs(subid, descs)
Expand Down

0 comments on commit 7922165

Please sign in to comment.