diff options
author | Nathan Fargo <32229490+ntfargo@users.noreply.github.com> | 2024-06-13 10:38:04 +0200 |
---|---|---|
committer | Nathan Fargo <32229490+ntfargo@users.noreply.github.com> | 2024-06-13 10:38:04 +0200 |
commit | 839616dc230800c9eb4d44baa9d3814c2916b999 (patch) | |
tree | 67edefbf94ee2500830b76eed531d922d16a580d | |
parent | 8551ebd090b4cfac3d552b682aceb040ebce79c6 (diff) |
Basic setup for Sequence Viewer
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | SequenceViewer/README.md | 1 | ||||
-rw-r--r-- | SequenceViewer/app/__init__.py | 4 | ||||
-rw-r--r-- | SequenceViewer/app/routes.py | 48 | ||||
-rw-r--r-- | SequenceViewer/app/static/genview.css | 23 | ||||
-rw-r--r-- | SequenceViewer/app/templates/index.html | 16 | ||||
-rw-r--r-- | SequenceViewer/app/templates/view.html | 29 | ||||
-rw-r--r-- | SequenceViewer/example.fasta | 10 | ||||
-rw-r--r-- | SequenceViewer/run.py | 4 | ||||
-rw-r--r-- | SequenceViewer/uploads/.gitkeep | 0 | ||||
-rw-r--r-- | pyproject.toml | 2 |
11 files changed, 142 insertions, 0 deletions
@@ -27,5 +27,10 @@ env.bak/ venv.bak/ .venv/ +# Ignore specific file types in sequenceviewer/upload +SequenceViewer/uploads/*.fasta +SequenceViewer/uploads/*.fastq +SequenceViewer/uploads/*.gb + # mac .DS_Store
\ No newline at end of file diff --git a/SequenceViewer/README.md b/SequenceViewer/README.md new file mode 100644 index 0000000..85af1a3 --- /dev/null +++ b/SequenceViewer/README.md @@ -0,0 +1 @@ +# View FASTA, FASTQ, and GenBank files. (temporarily)
\ No newline at end of file diff --git a/SequenceViewer/app/__init__.py b/SequenceViewer/app/__init__.py new file mode 100644 index 0000000..ab29b8d --- /dev/null +++ b/SequenceViewer/app/__init__.py @@ -0,0 +1,4 @@ +from flask import Flask +app = Flask(__name__) +app.config['UPLOAD_FOLDER'] = './uploads' +from . import routes
\ No newline at end of file diff --git a/SequenceViewer/app/routes.py b/SequenceViewer/app/routes.py new file mode 100644 index 0000000..0e39f74 --- /dev/null +++ b/SequenceViewer/app/routes.py @@ -0,0 +1,48 @@ +from flask import request, render_template, redirect, url_for +from Bio import SeqIO +import os +from . import app + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/upload', methods=['POST']) +def upload_file(): + if 'file' not in request.files: + return redirect(request.url) + file = request.files['file'] + if file.filename == '': + return redirect(request.url) + if file: + filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) + file.save(filepath) + return redirect(url_for('view_file', filename=file.filename)) + return redirect(request.url) + +@app.route('/view/<filename>') +def view_file(filename): + filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) + file_type = filename.split('.')[-1].lower() + sequences = [] + + with open(filepath, "r") as handle: + if file_type in ['fasta', 'fa']: + for record in SeqIO.parse(handle, "fasta"): + sequences.append(record) + elif file_type in ['fastq']: + for record in SeqIO.parse(handle, "fastq"): + sequences.append(record) + elif file_type in ['gb', 'genbank']: + for record in SeqIO.parse(handle, "genbank"): + sequences.append(record) + + # Convert sequences to a JSON-serializable format + sequences_data = [{ + 'id': str(record.id), + 'description': str(record.description), + 'sequence': str(record.seq), + 'features': [feature.qualifiers for feature in record.features] if file_type in ['gb', 'genbank'] else [] + } for record in sequences] + + return render_template('view.html', sequences=sequences_data, filename=filename)
\ No newline at end of file diff --git a/SequenceViewer/app/static/genview.css b/SequenceViewer/app/static/genview.css new file mode 100644 index 0000000..75eaf2b --- /dev/null +++ b/SequenceViewer/app/static/genview.css @@ -0,0 +1,23 @@ +body { + font-family: Arial, sans-serif; + margin: 20px; +} + +h1 { + color: #333; +} + +form { + margin-bottom: 20px; +} + +pre { + background-color: #f4f4f4; + padding: 10px; + border: 1px solid #ddd; + overflow: auto; +} + +li { + margin-bottom: 20px; +} diff --git a/SequenceViewer/app/templates/index.html b/SequenceViewer/app/templates/index.html new file mode 100644 index 0000000..7aaef10 --- /dev/null +++ b/SequenceViewer/app/templates/index.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <title>Linear Fox - Sequence Viewer</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="{{ url_for('static', filename='genview.css') }}"> +</head> +<body> + <h1>Select a file to view</h1> + <form action="{{ url_for('upload_file') }}" method="post" enctype="multipart/form-data"> + <input type="file" name="file" accept=".fasta, .fa, .fastq, .gb, .genbank"> + <button type="submit">Upload</button> + </form> +</body> +</html> diff --git a/SequenceViewer/app/templates/view.html b/SequenceViewer/app/templates/view.html new file mode 100644 index 0000000..6b11721 --- /dev/null +++ b/SequenceViewer/app/templates/view.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>View Sequences - {{ filename }}</title> + <link rel="stylesheet" href="{{ url_for('static', filename='genview.css') }}"> +</head> +<body> + <h1>Viewing Sequences from {{ filename }}</h1> + <a href="{{ url_for('index') }}">Upload another file</a> + <ul> + {% for record in sequences %} + <li> + <strong>ID: {{ record.id }}</strong><br> + <pre>{{ record.sequence }}</pre> + {% if record.features %} + Features: + <ul> + {% for feature in record.features %} + <li>{{ feature }}</li> + {% endfor %} + </ul> + {% endif %} + </li> + {% endfor %} + </ul> +</body> +</html>
\ No newline at end of file diff --git a/SequenceViewer/example.fasta b/SequenceViewer/example.fasta new file mode 100644 index 0000000..3408631 --- /dev/null +++ b/SequenceViewer/example.fasta @@ -0,0 +1,10 @@ +>Sequence_1 +AGCTAGCTAGCTACGATCGATCGATCGTAGCTAGCTAGCTAGCTAGCGTAGCTAGCTAGCTAGCTA +>Sequence_2 +CGTAGCTAGCTAGCTAGCTGATCGTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTA +>Sequence_3 +TGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCA +>Sequence_4 +ATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGA +>Sequence_5 +GCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAG
\ No newline at end of file diff --git a/SequenceViewer/run.py b/SequenceViewer/run.py new file mode 100644 index 0000000..5751813 --- /dev/null +++ b/SequenceViewer/run.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == '__main__': + app.run(debug=True)
\ No newline at end of file diff --git a/SequenceViewer/uploads/.gitkeep b/SequenceViewer/uploads/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/SequenceViewer/uploads/.gitkeep diff --git a/pyproject.toml b/pyproject.toml index 2fab40e..f13a1fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ dependencies = [ 'pandas', 'regex', 'biopython', + 'pygad', 'numpy', 'scipy', 'scikit-learn', @@ -53,6 +54,7 @@ dependencies = [ 'tensorflow-macos <= 2.16.1 ; platform_system == "Darwin"', 'protobuf <= 5.27.0', 'silence_tensorflow', + 'flask', ] dynamic = ["version"]
\ No newline at end of file |