Commit b7a25825 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Code refactoring + improve database + submit of local jobs now working

parent b4f720c4
......@@ -7,3 +7,6 @@ threads = 4
[softwares]
minimap2 = /home/fcabanettes/minimap2/minimap2
[database]
sqlite_file = /home/fcabanettes/public_html/algeco/srv/database.sqlite
......@@ -5,7 +5,8 @@ samtools_exec=$2
nb_threads=$3
fasta_t=$4
fasta_q=$5
paf_raw=$6
${minimap_exec} -t ${nb_threads} ${fasta_t} ${fasta_q}
${minimap_exec} -t ${nb_threads} ${fasta_t} ${fasta_q} > ${paf_raw}
${samtools_exec} faidx ${fasta_t}
${samtools_exec} faidx ${fasta_q}
import os
import random
import string
from pony.orm import Database, Required, commit
ALLOWED_EXTENSIONS = {'fa', 'fasta', 'fa.gz', "fasta.gz"}
......@@ -30,17 +29,3 @@ def get_valid_uploaded_filename(filename, folder):
file_query_s = os.path.join(folder, filename)
i += 1
return filename
def generate_database(file_path):
db = Database()
db.bind(provider='sqlite', filename=file_path, create_db=True)
class Job(db.Entity):
id_job = Required(str)
email = Required(str)
id_process = Required(int)
db.generate_mapping(create_tables=True)
commit()
return Job, db
import os
import subprocess
import datetime
import threading
from config_reader import AppConfigReader
from pony.orm import db_session
import threading
from database import db, Job
class JobManager:
def __init__(self, id_job, email, fasta_q, fasta_t, db, job_db):
def __init__(self, id_job, email, fasta_q, fasta_t):
self.id_job = id_job
self.email = email
self.fasta_q = fasta_q
......@@ -25,18 +27,17 @@ class JobManager:
self.idx_q = os.path.join(self.output_dir, "query.idx")
self.idx_t = os.path.join(self.output_dir, "target.idx")
self.logs = os.path.join(self.output_dir, "logs.err")
self.db = db
self.job_db = job_db
@db_session
def __launch_local(self):
cmd = ["run_minimap2.sh", self.minimap2, self.samtools, self.threads, self.fasta_t, self.fasta_q]
with open(self.paf_raw, "w") as paf, open(self.logs, "w") as logs:
p = subprocess.Popen(cmd)
cmd = ["run_minimap2.sh", self.minimap2, self.samtools, self.threads, self.fasta_t, self.fasta_q, self.paf_raw]
with open(self.logs, "w") as logs:
p = subprocess.Popen(cmd, stdout=logs, stderr=logs)
pid = p.pid
job = self.job_db(id_job=self.id_job, email=self.email, id_process=pid)
self.db.commit()
p.communicate()
job = Job(id_job=self.id_job, email=self.email, id_process=pid, batch_type="local",
date_created=datetime.datetime.now())
db.commit()
p.wait()
def launch(self):
if not os.path.exists(self.output_dir):
......
......@@ -49,4 +49,10 @@ class AppConfigReader(object):
try:
return self.reader.get("softwares", "samtools")
except NoOptionError:
return "samtools"
\ No newline at end of file
return "samtools"
def get_database(self):
try:
return self.reader.get("database", "sqlite_file")
except NoOptionError:
return ":memory:"
import datetime
from config_reader import AppConfigReader
from pony.orm import Database, Required
config_reader = AppConfigReader()
file_path = config_reader.get_database()
db = Database()
db.bind(provider='sqlite', filename=file_path, create_db=True)
class Job(db.Entity):
id_job = Required(str)
email = Required(str)
id_process = Required(int)
batch_type = Required(str)
status = Required(str, default="started")
date_created = Required(datetime.datetime)
db.generate_mapping(create_tables=True)
#!/usr/bin/env python3
import os
import json
import time
import datetime
......@@ -10,10 +9,6 @@ from lib.parse_paf import parse_paf
from config_reader import AppConfigReader
from lib.job_manager import JobManager
from lib.functions import *
# try:
# import _preamble
# except ImportError:
# pass
import sys
app_folder = os.path.dirname(os.path.realpath(__file__))
......@@ -21,7 +16,6 @@ sys.path.insert(0, app_folder)
os.environ["PATH"] = os.path.join(app_folder, "bin") + ":" + os.environ["PATH"]
sqlite_file = os.path.join(app_folder, "database.sqlite")
job_db, db = generate_database(sqlite_file)
# Init config reader:
......@@ -100,7 +94,7 @@ def launch_analysis():
id_job = id_job_orig + "_2"
# Launch job:
job = JobManager(id_job, email, query_path, target_path, db, job_db)
job = JobManager(id_job, email, query_path, target_path)
job.launch()
else:
return redirect(url_for(".main", id_job=id_job, email=email))
......
......@@ -15,4 +15,9 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}" type="text/css">
<link rel="shortcut icon" href="{{ url_for('static', filename='images/favicon.ico') }}">
</head>
\ No newline at end of file
</head>
<body onload="{% block onload %}{% endblock %}">
{% block body %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% include 'header.html' %}
<body>
{% extends 'base.html' %}
{% block body %}
<div id="main-bar-title">
<img src="{{ url_for('static', filename='images/logo.png') }}" height="40px" alt=""/><h1>{{ title }}</h1>
</div>
......@@ -55,5 +55,4 @@
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
\ No newline at end of file
{% endblock %}
\ No newline at end of file
{% include 'header.html' %}
<body onload="d3.boxplot.init('{{ id }}');">
{% extends 'base.html' %}
{% block onload %}d3.boxplot.init('{{ id }}');{% endblock %}
{% block body %}
<div id="main-bar-title">
<img src="{{ url_for('static', filename='images/logo.png') }}" height="40px" alt=""/><h1>{{ title }}</h1>
</div>
......@@ -31,5 +32,4 @@
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
{% endblock %}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment