Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

add Dockerfile to build this repo #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM openjdk:8-jdk as buildContainer

RUN apt-get update
RUN apt-get install -y maven

WORKDIR /opt/app
COPY . /opt/app

RUN chmod +x ./make.sh
RUN bash ./make.sh

CMD bash
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ target/lychi-0.5.1-jar-with-dependencies.jar
The self-contained jar file can be invoked directly. For example:

```
java -jar target/lychi-0.5.1-jar-with-dependencies.jar tests/standardizer_case1.smi
java -jar target/lychi-0.7.1-jar-with-dependencies.jar tests/standardizer_case1.smi
```


55 changes: 55 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from flask import Flask, request, jsonify, render_template
import subprocess
import tempfile
import os

lychify = Flask("lychify")

@lychify.route('/')
def index():
return render_template('index.html')

@lychify.route('/standardize', methods=['POST'])
def standardize():
# Get the list of SMILES objects from the request
smiles_list = request.json['smiles_list']
counter = 0
if len(smiles_list) == 0:
return jsonify({'result': []})
# Write the SMILES objects to a temporary file
with tempfile.NamedTemporaryFile(delete=False, mode='w') as f:
for obj in smiles_list:
if ("id" in obj):
f.write(obj['smiles'] + '\t' + str(obj['id']) + '\n')
else:
counter += 1
f.write(obj["smiles"] + '\t' + "no_id:" + str(counter) + '\n')
filepath = f.name

# Create the command to call the Java application with the input file
command = ['java', '-jar', 'lychi-0.7.1-jar-with-dependencies.jar', filepath]

# Call the Java application using subprocess
process = subprocess.run(command, capture_output=True, text=True)

# Remove the temporary file
os.remove(filepath)

# Check if the command completed successfully
if process.returncode != 0:
return jsonify({'error': 'Failed to run Java application',
'output': process.stdout.strip().split('\n')})

# Parse the output from the Java application and format the response
output = process.stdout.strip().split('\n')
formatted_output = []
for i, line in enumerate(output):
smiles, id, lychi = line.split('\t')
formatted_output.append({'smiles': smiles, 'id': id, 'lychi': lychi})

# Return the formatted output as a JSON response
return jsonify({'result': formatted_output})


if __name__ == '__main__':
lychify.run(debug=True)
Binary file added api/lychi-0.7.1-jar-with-dependencies.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions api/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<title>lychify</title>
</head>
<body>
<h1>Welcome to lychify!</h1>
<p>This is a web service to calculate lychi keys for any given chemical structure. See the repo here: <a href="https://github.com/ncats/lychi">https://github.com/ncats/lychi</a>.</p>
<p>To use this application, send a POST request to /standardize with a JSON payload containing a list of SMILES strings. The response will contain a JSON payload with the standardized SMILES strings.</p>
<p>Here's an example payload:</p>
<pre>{
"smiles_list": [
{"smiles": "CCO", "id": "1"},
{"smiles": "COC", "id": "2"}
]
}</pre>
</body>
</html>
31 changes: 31 additions & 0 deletions api/testapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import requests

url = 'http://localhost:5000/standardize'

response = requests.post(url, json={'smiles_list': []})
print (response.json())

long_smiles = "".join(['C' for i in range(10)])
response = requests.post(url, json={'smiles_list': [{"smiles": long_smiles}]})
print(response.json())

invalid_list = [
{'smiles':'invalid','id':'1'},
{'smiles':'SMILES','id':'2'},
{'smiles':'strings','id':'3'}
]
response = requests.post(url, json={'smiles_list': invalid_list})
print(response.json()) # Should return an error message or an empty result

duplicate_list = [
{"smiles": "C", "id": "1"},
{"smiles": "CC", "id": "2"},
{"smiles": "C", "id": "3"},
{"smiles": "CCC", "id": "4"}
]
response = requests.post(url, json={'smiles_list': duplicate_list})
print(response.json())

aminophylline = [{"smiles":"Cn1c2nc[nH]c2c(=O)n(C)c1=O", "id": "aminophylline"}]
response = requests.post(url, json={'smiles_list': aminophylline})
print(response.json())
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
dev:
build:
context: .
dockerfile: Dockerfile
tty: true