Skip to content

Commit d664ec6

Browse files
awolf-libArchina
authored andcommitted
fixed milts import
1 parent 6ed0e5e commit d664ec6

File tree

9 files changed

+92
-24
lines changed

9 files changed

+92
-24
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

flask-backend/src/Routes/db.py

+11
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,17 @@ def removeAnalysisByAnalysisID():
531531
return REQUESTMETHODERROR
532532

533533

534+
# FETCH MILTS PLOT BY PATH
535+
@db.route("/fetchMiltsPlotByPath", methods=["GET"])
536+
def fetchMiltsPlotByPath():
537+
if request.method == "GET":
538+
path = request.args.get("path")
539+
data = api.fetchMiltsPlotByPath(path)
540+
return data
541+
else:
542+
return REQUESTMETHODERROR
543+
544+
534545
# ================== BOOKMARK ================== #
535546
# ADD NEW BOOKMARK
536547
@db.route("/addNewBookmark", methods=["GET"])

flask-backend/src/Tools/DatabaseManager.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,13 @@ def fetchSpeciesProfilePictureTaxonID(self, taxonID):
560560
return {
561561
"label": "Error",
562562
"message": f"Error loading profile picture for species {taxonID}. No such file!",
563-
"type": "success",
563+
"type": "error",
564564
}
565565

566-
return send_file(f"{BASE_PATH_TO_STORAGE}taxa/images/" + taxonID + ".thumbnail.jpg", "image/jpg")
566+
return send_file(
567+
f"{BASE_PATH_TO_STORAGE}taxa/images/" + taxonID + ".thumbnail.jpg",
568+
"image/jpg",
569+
)
567570

568571
# ================== ASSEMBLY ================== #
569572
# FETCH ALL ASSEMBLIES
@@ -1694,7 +1697,7 @@ def addNewAnalysis(self, assemblyID, name, path, userID, additionalFilesPath="")
16941697

16951698
fileName = path.split("/")[-1]
16961699

1697-
if fileName == "3D_plot.html":
1700+
if "3D_plot.html" in fileName and fileName.endswith(".html"):
16981701
type = "milts"
16991702
elif "short_summary" in fileName and fileName.endswith(".txt"):
17001703
type = "busco"
@@ -1709,6 +1712,7 @@ def addNewAnalysis(self, assemblyID, name, path, userID, additionalFilesPath="")
17091712
"type": "error",
17101713
}
17111714

1715+
print(type, path, name, additionalFilesPath, assemblyName)
17121716
path, notification = fileManager.moveFileToStorage(
17131717
type, path, name, additionalFilesPath, assemblyName
17141718
)
@@ -1816,6 +1820,22 @@ def removeAnalysisByAnalysisID(self, id):
18161820
"type": "success",
18171821
}
18181822

1823+
# FETCH MILTS 3D PLOT
1824+
1825+
def fetchMiltsPlotByPath(self, path):
1826+
"""
1827+
send milts plot to frontend
1828+
"""
1829+
1830+
if not isfile(path):
1831+
return {
1832+
"label": "Error",
1833+
"message": f"Error loading MILTS 3D plot. No such file!",
1834+
"type": "error",
1835+
}
1836+
1837+
return send_file(path, "text/html")
1838+
18191839
def importBusco(self, analysisID, buscoData):
18201840
"""
18211841
Imports busco analysis results

flask-backend/src/Tools/FileManager.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from glob import glob
66
from PIL import Image
77
from subprocess import run
8+
from re import compile
89

910
# defaults
1011
BASE_PATH_TO_IMPORT = "/flask-backend/data/import/"
@@ -626,24 +627,37 @@ def moveFileToStorage(
626627
if type == "milts":
627628
try:
628629
with open(newPath, "r") as plotFile:
629-
lines = plotFile.readlines()
630+
plot_data = "".join(plotFile.readlines()).replace("\n", "")
631+
plot_data = plot_data.replace('"title":"taxonomic assignment"', f'"title":"{name}"')
630632
plotFile.close()
631633

632-
for index, line in enumerate(lines):
633-
if "3D_plot_files" in line:
634-
lines[index] = line.replace(
635-
"3D_plot_files",
636-
"../../../../../dependencies/3D_plot_files",
637-
)
638-
elif '"title":"taxonomic assignment",' in line:
639-
lines[index] = line.replace(
640-
'"title":"taxonomic assignment",', f'"title":"{name}",'
641-
)
634+
with open(
635+
"src/Tools/templates/milts_head_template.html", "r"
636+
) as milts_template_file:
637+
milts_template = milts_template_file.readlines()
638+
milts_template_file.close()
639+
640+
body_regex = compile(r"<body>.*</body>")
641+
body_match = body_regex.findall(plot_data)
642+
if len(body_match) != 1:
643+
return 0, {
644+
"label": "Error",
645+
"message": "Error using template html!",
646+
"type": "error",
647+
}
648+
649+
for i in range(len(milts_template)-1, len(milts_template)-5, -1):
650+
if ("<body>REPLACE_BODY</body>" in milts_template[i]):
651+
milts_template[i] = milts_template[i].replace("<body>REPLACE_BODY</body>", body_match[0])
652+
elif ("<title>REPLACE_TITLE</title>" in milts_template[i]):
653+
milts_template[i] = milts_template[i].replace("REPLACE_TITLE", name)
654+
break
642655

643656
with open(newPath, "w") as plotFile:
644-
lines = plotFile.writelines(lines)
657+
plotFile.writelines(milts_template)
645658
plotFile.close()
646-
except:
659+
except Exception as err:
660+
print(str(err))
647661
self.deleteDirectories(fullPathToAnalysis)
648662
return 0, STORAGEERROR
649663

flask-backend/src/Tools/templates/milts_head_template.html

+19
Large diffs are not rendered by default.

react-frontend/src/components/SpeciesProfilePictureViewer/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { useEffect, useState } from "react";
21
import "../../App.css";
32
import PropTypes from "prop-types";
43
import picPlacerholder from "../../images/blankProfilePicture.png";
5-
import { fetchSpeciesProfilePictureTaxonID } from "../../api";
64

75
const SpeciesProfilePictureViewer = ({ taxonID, imageStatus }) => {
86
return (
@@ -11,7 +9,8 @@ const SpeciesProfilePictureViewer = ({ taxonID, imageStatus }) => {
119
alt="Species profile"
1210
src={
1311
imageStatus
14-
? "http://localhost:3002/fetchSpeciesProfilePictureTaxonID?taxonID=" +
12+
? process.env.REACT_APP_API_ADRESS +
13+
"/fetchSpeciesProfilePictureTaxonID?taxonID=" +
1514
taxonID
1615
: picPlacerholder
1716
}

react-frontend/src/screens/MainRouter/components/AssemblyInformation/components/TaxonomicAssignmentViewer/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ const TaxonomicAssignmentViewer = ({
1414
onLoad={() => setTaxonomicAssignmentLoading(false)}
1515
title="MiltsPlot"
1616
className="w-full h-screen"
17-
src={process.env.REACT_APP_NEXTCLOUD_DOWNLOAD_ADRESS}
17+
src={
18+
process.env.REACT_APP_API_ADRESS +
19+
"/fetchMiltsPlotByPath?path=" +
20+
assemblyInformation.analyses.milts[index].path
21+
}
1822
/>
1923
</div>
2024
<div className="absolute bottom-0 right-0 z-10 opacity-50 flex items-center mx-4 my-1">
@@ -30,7 +34,7 @@ const TaxonomicAssignmentViewer = ({
3034
</a>
3135
</div>
3236
{assemblyInformation.analyses.milts.length > 1 && (
33-
<div className="absolute bottom-0 left-0 z-10 opacity-50 flex items-center mx-4 my-1">
37+
<div className="absolute bottom-0 left-0 opacity-50 flex items-center mx-4 my-1 z-10">
3438
<Button
3539
color="link"
3640
onClick={() =>

react-frontend/src/screens/MainRouter/components/AssemblyInformation/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const AssemblyInformation = () => {
211211
</div>
212212
)}
213213

214-
{/* {assemblyInformation.analyses &&
214+
{assemblyInformation.analyses &&
215215
assemblyInformation.analyses.milts &&
216216
assemblyInformation.analyses.milts.length > 0 && (
217217
<div>
@@ -245,7 +245,7 @@ const AssemblyInformation = () => {
245245
</div>
246246
<hr className="shadow my-8 mx-8" />
247247
</div>
248-
)} */}
248+
)}
249249

250250
{assemblyInformation.analyses &&
251251
assemblyInformation.analyses.busco &&

setup.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ docker build --no-cache -t gnom/reactapp .
9393
# start
9494
echo "Start ${REACTAPP_CONTAINER_NAME} container..."
9595
# docker run --name $REACTAPP_CONTAINER_NAME --network gnom_app -d -p 5000:5000 gnom/reactapp
96-
docker run --name $REACTAPP_CONTAINER_NAME -v /home/andywolf/workspace/g-nom/react-frontend/src:/react-frontend/src --network gnom_app -d -p 3000:5000 gnom/reactapp npm start
96+
docker run --name $REACTAPP_CONTAINER_NAME -v /home/andywolf/workspace/g-nom/react-frontend/src:/react-frontend/src --network gnom_app -d -p 3000:3000 gnom/reactapp npm start
9797
cd ..
9898

9999
# ============================================ #

0 commit comments

Comments
 (0)