-
Notifications
You must be signed in to change notification settings - Fork 0
Notes Architecture Code
## Benutzerschnitstellen
1. Web Front-end
```
Enter Variant [chr9:1234A>C] [SUBMIT]
=>
Ja, Variante gefunden/Nein Variante nicht gefunden.
```
2. REST API
```
GET /api/<variant> HTTP/1.1
=>
200 OK
{"message": "Yes, variant found"}
```
3. Command line interface (CLI)
```
host:~$ beacon-query
Bitte Variante eingeben> chr9:1234A>C
Ja, deine Variante wurde gefunden
```
4. Administrations/Wartungsinterface
- Datenbank anlegen
```
host:~$ beacon-admin setup-database path/to/db.sqlite3
...
host:~$ ls path/to/db.sqlite3
path/to/db.sqlite3
```
- VCF Importieren mit Ersetzen
```
host:~$ beacon-admin vcf-import --method=replace path/to/db.sqlite3 path/to/input.vcf
...
2345 records successfully imported, replaced previous 123 ones
```
- VCF Importieren mit Hinzufuegen
```
host:~$ beacon-admin vcf-import --method=add path/to/db.sqlite3 path/to/input.vcf
...
2300 records successfully imported, updated, 45 updated, left 78 untouched
```
- Nach Duplikaten Suchen
```
host:~$ beacon-admin search-dupalictes path/to/db.sqlite3
...
20 duplicates found, remove with beacon-admin fix-duplicates path/to/db.sqlite3
```
## Design
flask_app user_cli database admin_cli
"""Provides the front-end for both web UI and REST API."""
flask = ....
db_connectioin = ...
@route("/"): def render_form(): pass
@route("/query"): def handle_form_submission(): pass
@route("/api/query/<var_str>"): def api_query(var_str): # var = ... parse ... var_str # db_connection.run_query(var) pass
"""Provide the user query command line interface."""
import argparse
def main(): parser = argparse.ArgumentParser() # ... args = parser.parse_args() # var_str = args.variant var_str = input("Enter variant please") # ...
"""Provides administrative commands."""
class CreateDbCommand: pass
class ImportVcfCommand: replace = True/False
class SearchDuplicatesCommand: pass
def main(): parser = argparse.ArgumentParser() # ... args = parser.parse_args()
if args.command == "create-db":
CreateDbCommand().run()
elif args.command == "import-vcf":
ImportVcfCommand().run()
# ....
"""Provides common data structures and operations."""
class Variant: pass
class AnnotatedVariant: pass
class VariantStringParser: def parse_var(var_str): # -> Variant pass
"""Provides internal API to database."""
class DatabaseConnection: def run_query(var): # => [AnnotatedVariant] pass
```bash
## file beacon/settings.py
PATH_DATABASE = None
## file beacon/flask_app.py
from . import settings
app = Flask(__name__)
db_connection = DatabaseConnection(settings.PATH_DATABASE)
## beacon/flask_app.py
from . import settings
def run():
# ...
args = parser.parse_args() # ...
settings.PATH_DATABASE = args.path_database
from . flask_app import app
app.run_server() # ...
if __name__ == "__main__":
run()