Skip to content

Commit

Permalink
Merge pull request #4 from NBISweden/experimental/add-initial-annotat…
Browse files Browse the repository at this point in the history
…ion-functionality

Experimental/add initial annotation functionality
  • Loading branch information
pdmnyberg authored Apr 4, 2024
2 parents 415b475 + f800151 commit 131fd1c
Show file tree
Hide file tree
Showing 24 changed files with 35,302 additions and 211 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
__pycache__/
__pycache__/
venv
23 changes: 2 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
# syntax=docker/dockerfile:1.4
FROM python:3.9-slim as BUILDER
FROM python:3.9-slim

WORKDIR /app

RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt

COPY . /app

ENTRYPOINT ["python3"]
CMD ["app.py"]

FROM builder as dev-envs

RUN <<EOF
apk update
apk add git
EOF

RUN <<EOF
addgroup -S docker
adduser -S --shell /bin/bash --ingroup docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /
CMD ["flask", "--app", "app.py", "--debug", "run", "--host", "0.0.0.0"]
2 changes: 0 additions & 2 deletions add.py

This file was deleted.

91 changes: 70 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,86 @@
from flask import Flask, request, render_template, Response
from add import add
from placeholder import VectorOligoSearch
from flask import (
Flask,
request,
render_template,
Response,
json,
make_response,
jsonify
)
import io
import csv
import logging
from itertools import chain
from search.oligo_search import search, search_to_file
from search.search import SearchError


logger = logging.getLogger(__name__)
app = Flask(__name__)



@app.route('/')
def hello():
return render_template('root.html')
def root():
return render_template('root.html')

@app.route('/form', methods=['POST', 'GET'])
# Sample form POST to get input and render result

@app.route('/search', methods=['POST', 'GET'])
def form():
form_input = None
gene_ids = []
output = None
error = None
status_code = 200

if request.method == 'POST':
form_input = request.form['userInput']
output = VectorOligoSearch(form_input)
try:
gene_id = request.form['gene-id']
gene_list = request.form.get('gene-list', "").strip()
gene_ids = (
[gene_id] if len(gene_list) == 0
else [g.strip().rstrip('\r\n') for g in gene_list.split("\n")]
)
output = search(gene_ids)
except SearchError as e:
error = str(e)
status_code = 404

return render_template(
'form.html',
gene_ids=gene_ids,
output=output,
error=error,
status_code=status_code,
)


return render_template('form.html',
input=form_input,
output=output)
@app.route('/oligo-search')
def oligo_search():
gene_ids = request.args.getlist('gene-id')
try:
output = search(gene_ids)
return jsonify(output)
except SearchError as e:
error = str(e)
return make_response(jsonify({"error": error}), 404)

# Sample download generated CSV
@app.route("/get")
def getPlotCSV():
genome_id = request.args.get('id')
csv = VectorOligoSearch(genome_id)
def get_data():
gene_ids = request.args.getlist('gene-id')
format = request.args.get('format', 'csv')
(output, ext) = search_to_file(
gene_ids,
output_format=format
)
return Response(
csv,
output,
mimetype="text/csv",
headers={"Content-disposition":
f"attachment; filename={genome_id}.csv"})
headers={
"Content-disposition":
f"attachment; filename=oligo-sequences.{ext}"
}
)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
app.run(host='0.0.0.0', port=8000)
7 changes: 3 additions & 4 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ services:
web:
build:
context: .
target: builder
# flask requires SIGINT to stop gracefully
# (default stop signal from Compose is SIGTERM)
stop_signal: SIGINT
ports:
- '8000:8000'
- '127.0.0.1:5000:5000'
volumes:
- ./:/app
104 changes: 0 additions & 104 deletions placeholder.py

This file was deleted.

4 changes: 4 additions & 0 deletions questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Technical questions
- How strictly do we want to stick to the original code?
- Are there any restrictions on how much we can clean up the code?
-
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 131fd1c

Please sign in to comment.