Initial commit
Browse files- app.py +52 -0
- raxml-ng-v1.1.0-linux-64.bz2 +3 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import bz2
|
2 |
+
import shutil
|
3 |
+
import tempfile
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
import pypythia.msa
|
8 |
+
import pypythia.prediction
|
9 |
+
import pypythia.predictor
|
10 |
+
import pypythia.raxmlng
|
11 |
+
|
12 |
+
|
13 |
+
def get_default_raxmlng():
|
14 |
+
version = "1.1.0"
|
15 |
+
uncompressed_raxmlng = Path.home() / f"raxml-ng-v{version}-linux-64"
|
16 |
+
if not uncompressed_raxmlng.exists():
|
17 |
+
compressed_raxmlng = Path(__file__).parent / f"raxml-ng-v{version}-linux-64.bz2"
|
18 |
+
with bz2.BZ2File(compressed_raxmlng) as bz, uncompressed_raxmlng.open(
|
19 |
+
"wb"
|
20 |
+
) as rax:
|
21 |
+
shutil.copyfileobj(bz, rax)
|
22 |
+
return uncompressed_raxmlng
|
23 |
+
|
24 |
+
|
25 |
+
def predict_difficulty(uploaded_file):
|
26 |
+
predictor_file = (
|
27 |
+
Path(pypythia.__file__).parent / "predictors" / "predictor_lgb_v1.0.0.pckl"
|
28 |
+
)
|
29 |
+
predictor = pypythia.predictor.DifficultyPredictor(predictor_file.open("rb"))
|
30 |
+
raxmlng = pypythia.raxmlng.RAxMLNG(
|
31 |
+
shutil.which("raxml-ng") or get_default_raxmlng()
|
32 |
+
)
|
33 |
+
with tempfile.NamedTemporaryFile() as msa_file:
|
34 |
+
uploaded_file.seek(0)
|
35 |
+
shutil.copyfileobj(uploaded_file, msa_file)
|
36 |
+
msa_file.flush()
|
37 |
+
msa = pypythia.msa.MSA(msa_file.name)
|
38 |
+
msa_features = pypythia.prediction.get_all_features(raxmlng, msa)
|
39 |
+
difficulty = predictor.predict(msa_features)
|
40 |
+
|
41 |
+
return difficulty, msa_features
|
42 |
+
|
43 |
+
|
44 |
+
pythia_demo = gr.Interface(
|
45 |
+
predict_difficulty,
|
46 |
+
gr.File(label="MSA file (.phy or .msa)"),
|
47 |
+
[
|
48 |
+
gr.Number(label="Difficulty", precision=5),
|
49 |
+
gr.JSON(label="Features used for prediction"),
|
50 |
+
],
|
51 |
+
)
|
52 |
+
pythia_demo.launch()
|
raxml-ng-v1.1.0-linux-64.bz2
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2c246fec86cbc1820b8f9f240adf372c03a39779203821e9e23d8579e2c7ec6a
|
3 |
+
size 2287022
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
git+https://github.com/tschuelia/PyPythia
|