Skip to content

Commit

Permalink
Update local
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Borrel committed Nov 14, 2024
2 parents b90bd17 + e4f3ffe commit 990d8a0
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Development in python3.12 with
- OPERA2.3_CL (https://github.com/kmansouri/OPERA/releases), fix the minor error in the install folder add a "/" at the path beginning
- OPERA will install PADEL in the same folder

## install OPERA --> install command line
$sudo ./OPERA2.6_XXX_mcr.install -mode silent -agreeToLicense yes


## run the server
$python manage makemigrations
$python migrate
Expand Down
10 changes: 6 additions & 4 deletions bodymap/templates/bodymap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Tox21BodyMap</h1>

<br>
<h2>Please cite</h2>
<p style="text-align: center; font-size: 25px">
<p style="text-align: center; font-size: 20px">
<a href="https://doi.org/10.1093/nar/gkaa433" style="color: darkred">Tox21BodyMap: a webtool to map chemical effects on the human body, <i>NAR webserver</i></a><br>
</p>
<p>* This website is free and open to all users and there is no login requirement.</p>
Expand All @@ -46,12 +46,14 @@ <h2>Visualization</h2>
Visualization includes three parts:
<ul style="margin-left:40px">

<li style="font-size: 20px;">chemical information, linked to the <a class = "aurl" href="https://comptox.epa.gov/dashboard">EPA chemical dashboard</a></li>
<li style="font-size: 20px;">body-mapping based on a consensus of assay AC50 (µM) and gene expression cutoffs</li>
<li style="font-size: 20px;">network representation integrating gene expression, body mapping and chemical activity by assay</li>
<li style="font-size: 15px;">chemical information, linked to the <a class = "aurl" href="https://comptox.epa.gov/dashboard">EPA chemical dashboard</a></li>
<li style="font-size: 15px;">body-mapping based on a consensus of assay AC50 (µM) and gene expression cutoffs</li>
<li style="font-size: 15px;">network representation integrating gene expression, body mapping and chemical activity by assay</li>
</ul>
</p>

<br><br>


<div class="row">
<div class="column">
Expand Down
3 changes: 2 additions & 1 deletion bodymap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .loadMapping import assaysMapping
from .mapChem import mapChem
from .prepInputChem import prepChem
from django.views.decorators.csrf import csrf_exempt


# Create your views here.
Expand All @@ -20,7 +21,7 @@ def help(request):
return render(request, 'bodymap/help.html', {
})


@csrf_exempt
def mappingChemicalToBody(request):

# form for bodypart
Expand Down
8 changes: 5 additions & 3 deletions chemmaps/DSSToxPrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def loadChemMapAddMap(self):
if nbChemAdd == 1:
center_map = 1
else:
center_map =0
center_map = 0


for chem in self.input["SMILESClass"].keys():
Expand Down Expand Up @@ -226,8 +226,10 @@ def loadChemMapAddMap(self):
else:
self.coord[chem] = deepcopy(self.input["coord"][chem])
self.dinfo[chem] = {}
for desc in self.input["info"][chem]:
self.dinfo[chem][DDESCDSSTOX[desc]] = self.input["info"][chem][desc]


for desc in list(self.input["info"][chem].keys()):
self.dinfo[chem][desc] = self.input["info"][chem][desc]
self.dneighbor[chem] = deepcopy(self.input["neighbor"][chem])
self.dSMILES[chem] = {}
self.dSMILES[chem]["SMILES"] = deepcopy(self.input["SMILESClass"][chem]["SMILES"])
Expand Down
4 changes: 2 additions & 2 deletions chemmaps/JSbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, nameMap, ldescMap = [], prout = ""):
self.prout = prout
self.ldescMap = ldescMap
self.cDB = DBrequest()
self.pMap = path.abspath("./static/chemmaps/map/" + self.nameMap + "/") + "/"
self.pMap = path.abspath(path.dirname(__file__) + "/../static/chemmaps/map/" + self.nameMap + "/") + "/"
self.cDB.verbose = 0
self.err = 0

Expand Down Expand Up @@ -382,7 +382,7 @@ def generateCoords(self, p1D2D, p3D):

# run R script
## add Rscript for windows install!
cmd = "Rscript %s/addonMap.R %s %s %s1D2Dscaling.csv %s3Dscaling.csv %sCP1D2D.csv %sCP3D.csv %s"%(path.abspath("./chemmaps/Rscripts"), p1D2D, p3D, self.pMap, self.pMap, self.pMap, self.pMap, self.prout)
cmd = "%s/addonMap.R %s %s %s1D2Dscaling.csv %s3Dscaling.csv %sCP1D2D.csv %sCP3D.csv %s"%(path.abspath(path.dirname(__file__) + "/Rscripts"), p1D2D, p3D, self.pMap, self.pMap, self.pMap, self.pMap, self.prout)
system(cmd)

if path.exists(p1D2Dcoord) and path.exists(p3Dcoord):
Expand Down
3 changes: 1 addition & 2 deletions chemmaps/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.urls import re_path as url
from django.views.generic import TemplateView
from django.conf.urls.static import static
from django.conf import settings
from . import views

Expand Down Expand Up @@ -225,4 +224,4 @@
r'^lowestAC50.csv',
views.download, {"name": "lowestAC50"}, name="lowestAC50",
)
]
]
15 changes: 8 additions & 7 deletions chemmaps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.views.generic import TemplateView
from django.core.files.storage import default_storage
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from random import randint
import json
from re import search
Expand Down Expand Up @@ -52,6 +53,7 @@ def download(request, name):
return response
raise Http404

@csrf_exempt
def launchMap(request, map, *args, **kwargs):

name_session = request.session.get("name_session")
Expand Down Expand Up @@ -155,10 +157,12 @@ def launchMap(request, map, *args, **kwargs):
build.err = 1
else:
build.loadChemMapCenterChem(chemIn, center = 1, nbChem = 10000)

if build.err == 1:
reponse = render(request, 'chemmaps/launchMap.html', {"form_info": formDesc, "form_smiles": form_smiles,
"from_upload": formUpload, "Error": "0", "map": map,
"ErrorDSSTox":"1", "dassays":d_assays})
return reponse
dcoord = json.dumps(build.coord)
dinfo = json.dumps(build.dinfo)
dneighbor = json.dumps(build.dneighbor)
Expand Down Expand Up @@ -190,6 +194,7 @@ def launchMap(request, map, *args, **kwargs):
"from_upload": formUpload, "Error": "0", "map":map, "dassays":d_assays})
return reponse

@csrf_exempt
def launchTox21AssayMap(request, assay):

cloadAssays = loadTox21AssayMap(assay)
Expand Down Expand Up @@ -237,7 +242,7 @@ def launchTox21TagetMap(request, target):
return render(request, 'chemmaps/Map3D.html', {"dcoord": dcoord, "dinfo": dinfo, "dneighbor": dneighbor,
"dSMILESClass":dSMILESClass,
"ldesc":ldescJS, "map":"Tox21Target", "mapJS": mapJS, "prSessionJS":prSessionJS, "target":target, "assay":"", "nb_assays": cloadAssays.nb_assays})#, "nb_active": cloadAssays.nb_active, "nb_tested": cloadAssays.nb_tested })

@csrf_exempt
def launchTox21MostPotent(request):


Expand All @@ -261,7 +266,7 @@ def launchTox21MostPotent(request):
return render(request, 'chemmaps/Map3D.html', {"dcoord": dcoord, "dinfo": dinfo, "dneighbor": dneighbor,
"dSMILESClass":dSMILESClass,
"ldesc":ldescJS, "map":"Tox21Target", "mapJS": mapJS, "prSessionJS":prSessionJS, "target":"Most active", "assay":"", "nb_assays": cloadAssays.nb_assays})#, "nb_active": cloadAssays.nb_active, "nb_tested": cloadAssays.nb_tested })

@csrf_exempt
def browseChemicals(request):

name_session = request.session.get("name_session")
Expand Down Expand Up @@ -302,6 +307,7 @@ def launchDSSToxMap(request, DTXSID):

return render(request, 'chemmaps/Map3D.html', {"dcoord": dcoord, "dinfo": dinfo, "dneighbor": dneighbor, "dSMILESClass":dSMILESClass, "ldesc":ldescJS, "map":"dsstox", "mapJS": mapJS,"prSessionJS":prSessionJS, "center_map":DTXSID, "assay":"" })

@csrf_exempt
def computeDescriptor(request, map):


Expand Down Expand Up @@ -381,11 +387,6 @@ def computeDescriptor(request, map):
mapJS = json.dumps(map)


print(len(list(dJS["coord"].keys())))
print(len(list(dJS["info"].keys())))
print(len(list(dJS["neighbor"].keys())))
print(len(list(dJS["SMILESClass"].keys())))
print(len(ldesc))
return render(request, 'chemmaps/Map3D.html', {"dcoord": dcoord, "dinfo": dinfo, "dneighbor": dneighbor,
"dSMILESClass": dSMILESClass, "ldesc": ldesc,
"map": map, "mapJS": mapJS, "prSessionJS":prSessionJS,
Expand Down
1 change: 1 addition & 0 deletions django_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.urls import path
from django.conf.urls import include
from .views import Home
from django.conf.urls.static import static
from django.urls import re_path as url

urlpatterns = [
Expand Down
4 changes: 1 addition & 3 deletions django_server/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@
# print ('%-30s %s' % (k,v[:70]))


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_server.settings')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_server.settings.production')
application = get_wsgi_application()
#application = "FUCK"
7 changes: 6 additions & 1 deletion interferences/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def computeDesc(self):
filout2D.write("ID\tSMILES\tinchikey\t" + "\t".join(ldesc1D2D) + "\n")
filoutOPERA.write("ID\tSMILES\t" + "\t".join(ldescOPERA) + "\n")

print("HERE2")
print(self.dclean)
for k in self.dclean["IN"].keys():
dout[k] = {}
SMICLEAN = self.dclean["OUT"][k]["SMILES"]
Expand All @@ -150,7 +152,7 @@ def computeDesc(self):

# check if chemical is in DB for 1D2D
lval1D2D_OPERA = downloadDescFromDB(self.cDB, ldesc1D2D, ldescOPERA, inch)

# case of error in computation
if lval1D2D_OPERA == []:
dout[k]["desc"] = "checkNo.png"
Expand Down Expand Up @@ -243,13 +245,16 @@ def downloadDescFromDB(cDB, ldesc1D2D, ldescOPERA, inchikey):

else:
nb_userDB = cDB.execCMD("SELECT COUNT(*) FROM chemical_description_user WHERE inchikey='%s' AND status != 'update'"%(inchikey))[0][0]
print(nb_userDB)
print("SELECT COUNT(*) FROM chemical_description_user WHERE inchikey='%s' AND status != 'update'"%(inchikey))
if nb_userDB > 0:
lval1D2D = cDB.extractColoumn("chemical_description_user", "desc_1d2d","where inchikey='%s' and status != 'update' limit(1)"%(inchikey))
lvalOPERA = cDB.extractColoumn("chemical_description_user", "desc_opera", "where inchikey='%s' and status != 'update' limit(1)"%(inchikey))

else:
return 0

# break if one descriptor error
if lval1D2D == "ERROR" or lval1D2D == [] or lvalOPERA == "ERROR" or lvalOPERA == [] or lvalOPERA == [(None)]:
return []

Expand Down
11 changes: 7 additions & 4 deletions interferences/predictInterference.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import subprocess

PMODEL = path.abspath("./static/interferences/models") + "/"

#PMODEL = path.abspath("./static/interferences/models") + "/"
PMODEL = path.abspath(path.dirname(__file__) + "/../static/interferences/models/") + "/"



class Predict:
Expand All @@ -18,6 +21,7 @@ def __init__(self, lmodels, noDB, prSession):
self.pdes2D = prSession + "2D.csv"
self.pOpera = prSession + "OPERA.csv"
self.prSession = prSession

self.err = 0
self.cDB = DBrequest()
self.noDB = noDB
Expand Down Expand Up @@ -45,7 +49,6 @@ def predictAll(self):

if type(lpred) == list and lpred != []:
#lpred = self.cDB.extractColoumn("interference_chemicals", "interference_prediction", "WHERE inchikey='%s'"%(inch))
print(lpred)
lpred = lpred[0]
if lpred[0] == None:
i = i + 1
Expand Down Expand Up @@ -111,14 +114,14 @@ def predictAll(self):
def predictRmodel(self, pmodel, pdesc2D, pOPERA, pout):

if os.name == "nt":
pRpredict = path.abspath("./interferences/Rscripts") + "/predictfromModel.R"
pRpredict = path.abspath(path.dirname(__file__) + "/Rscripts") + "/predictfromModel.R"

cmd = f'"C:\\Program Files\\R\\R-4.2.1\\bin\\Rscript.exe" "{pRpredict}" "{pdesc2D}" "{pOPERA}" "{pmodel}" "{pout}"'
print(cmd)
subprocess.run(cmd, shell=True, check=True)

else:
pRpredict = path.abspath("./interferences/Rscripts") + "/predictfromModel.R"
pRpredict = path.abspath(path.dirname(__file__) + "/Rscripts") + "/predictfromModel.R"
cmd = "%s %s %s %s %s" % (pRpredict, pdesc2D, pOPERA, pmodel, pout)
print(cmd)
system(cmd)
Expand Down
2 changes: 1 addition & 1 deletion interferences/templates/interferences/cleanSMILES.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>QSAR-ready SMILES</h1>
{% endif %}


<div class="row">
<div class="row" style="margin: auto;">
<div class="column" style="background-color:#004400;">
<h3 style="color:#ffffff">Inputs</h3>
<div class="divTable">
Expand Down
2 changes: 1 addition & 1 deletion interferences/templates/interferences/computeDESC.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>Chemical descriptors</h1>
<p class = "Errorform" style="margin-right: 0px"> No descriptor computed.</p>
{% endif %}

<div class="row">
<div class="row" style="margin: auto;">
<div class="column" style="background-color:#004400;">
<h3 style="color:#ffffff">Inputs</h3>
<div class="divTable">
Expand Down
13 changes: 8 additions & 5 deletions interferences/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.views.decorators.csrf import csrf_exempt
from random import randint
from os import path
import json
Expand All @@ -24,9 +25,11 @@ def help(request):
return render(request, 'interferences/help.html', {
})

def uploadSMILES(request):
@csrf_exempt
def uploadSMILES(request, *args, **kwargs):

name_session = request.session.get("name_session")
print(name_session)

if request.method == 'GET':
form_smiles = UploadChemList()
Expand All @@ -47,7 +50,7 @@ def uploadSMILES(request):
return render(request, 'interferences/uploadSMILES.html', {"form_smiles":form_smiles,
"from_upload": formUpload, "ErrorLine": "1"})

prSession = path.abspath("./temp") + "/" + str(name_session) + "/"
prSession = path.abspath(path.dirname(__file__) + "/../temp") + "/" + str(name_session) + "/"
createFolder(prSession, 1)

cinput = formatSMILES(content, prSession)
Expand All @@ -60,7 +63,7 @@ def uploadSMILES(request):

elif formUpload.is_valid() == True:

prSession = path.abspath("./temp") + "/" + str(name_session) + "/"
prSession = path.abspath(path.dirname(__file__) + "/../temp") + "/" + str(name_session) + "/"
createFolder(prSession, 1)

pfileserver = prSession + "upload.txt"
Expand Down Expand Up @@ -94,13 +97,13 @@ def uploadSMILES(request):

return render(request, 'interferences/uploadSMILES.html', {"form_smiles":form_smiles,
"from_upload": formUpload, "ErrorLine": "0"})

@csrf_exempt
def computeDesc(request):

name_session = request.session.get("name_session")

# open file with
prsession = path.abspath("./temp") + "/" + str(name_session) + "/"
prsession = path.abspath(path.dirname(__file__) + "/../temp") + "/" + str(name_session) + "/"
dSMI = loadMatrixToDict(prsession + "smiClean.csv", sep="\t")

cinput = formatSMILES(dSMI, prsession)
Expand Down
4 changes: 2 additions & 2 deletions settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
DEBUG = True


ALLOWED_HOSTS = ['localhost']#,'152.1.45.108', 'www.chemmaps.com', "www.alexborrel.com"]
ALLOWED_HOSTS = ['localhost', '192.168.167.131']#,'152.1.45.108', 'www.chemmaps.com', "www.alexborrel.com"]

# CORS
CORS_ORIGIN_ALLOW_ALL = False
Expand Down Expand Up @@ -156,4 +156,4 @@


# manage cookies
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
2 changes: 2 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pip install git+https://github.com/jazzband/django-cookie-consent@master#egg=dja

### BodyMap
#### Priority high
- redone chemsum with proper chemical name


### Priority low

2 changes: 1 addition & 1 deletion toolchem/computeCoords.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def computeCoordForOnlyNewChem(self):
self.cDBresquest.closeConnection()

# run R script
cmd = "%s/addonMap.R %s %s %s1D2Dscaling.csv %s3Dscaling.csv %sCP1D2D.csv %sCP3D.csv %s"%(path.abspath("./chemmaps/Rscripts"), p_desc1D2D, p_desc1D3D, self.p_staticMap, self.p_staticMap, self.p_staticMap, self.p_staticMap, self.pr_session)
cmd = "%s/addonMap.R %s %s %s1D2Dscaling.csv %s3Dscaling.csv %sCP1D2D.csv %sCP3D.csv %s"%(path.abspath(path.dirname(__file__) + "/Rscripts"), p_desc1D2D, p_desc1D3D, self.p_staticMap, self.p_staticMap, self.p_staticMap, self.p_staticMap, self.pr_session)
system(cmd)

p_coords1D2D = self.pr_session + "coord1D2D.csv"
Expand Down

0 comments on commit 990d8a0

Please sign in to comment.