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

Fix name of samples + improve status

parent 4eccc871
......@@ -6,14 +6,15 @@ Short desc: Prepare the PAF file from minimap output to be loaded by the program
Details: change coordinates of matches to be bounded one to another
Usage:
prepare_paf.py -i IN -q FASTA1 -t FASTA2 -o OUT [ -r NAME1 -s NAME2]
prepare_paf.py -i IN -q FASTA1 -t FASTA2 -o OUT [-r NAME1] [-u NAME2]
prepare_paf.py -v | --version
Options:
-i --input=IN Input PAF file generated by minimap
-q --query=FASTA1 Query fasta file compared with minimap
-t --target=FASTA2 Target fasta file compared with minimap
-s --query-name=NAME1 Query name
-r --query-name=NAME1 Query name
-u --target-name=NAME2 Target name
-o --output=OUT Output PAF file
-h --help Show this screen
-v --version Show version
......@@ -28,10 +29,10 @@ from collections import OrderedDict
class Fasta:
def __init__(self, fasta):
def __init__(self, fasta, name=None):
self.fasta = fasta
self.fai = fasta + ".fai"
self.name = os.path.splitext(os.path.basename(fasta))[0]
self.name = os.path.splitext(os.path.basename(fasta))[0] if name is None else name
self.contigs = OrderedDict()
self.total_length = 0
self.__load()
......@@ -87,8 +88,8 @@ if __name__ == '__main__':
raise Exception("Fasta file %s is not indexed!" % args["--query"])
if not os.path.exists(args["--target"] + ".fai"):
raise Exception("Fasta file %s is not indexed!" % args["--target"])
query = Fasta(args["--query"])
target = Fasta(args["--target"])
query = Fasta(args["--query"], args["--query-name"])
target = Fasta(args["--target"], args["--target-name"])
build_new_paf_file(args["--input"], args["--output"], query, target)
basedir = os.path.dirname(args["--output"])
i = 0
......
......@@ -7,8 +7,10 @@ samtools_exec=$2
nb_threads=$3
fasta_t=$4
fasta_q=$5
paf_raw=$6
paf=$7
query=$6
target=$7
paf_raw=$8
paf=$9
# Index fasta files:
${samtools_exec} faidx ${fasta_t}
......@@ -18,7 +20,7 @@ ${samtools_exec} faidx ${fasta_q}
${minimap_exec} -t ${nb_threads} ${fasta_t} ${fasta_q} > ${paf_raw}
# Parse paf raw file:
prepare_paf.py -i ${paf_raw} -q ${fasta_q} -t ${fasta_t} -o ${paf}
prepare_paf.py -i ${paf_raw} -q ${fasta_q} -t ${fasta_t} -o ${paf} -r ${query} -u ${target}
# Remove raw file:
#rm -f ${paf_raw}
\ No newline at end of file
rm -f ${paf_raw}
\ No newline at end of file
......@@ -9,11 +9,13 @@ from database import db, Job
class JobManager:
def __init__(self, id_job, email=None, fasta_q=None, fasta_t=None):
def __init__(self, id_job, email=None, fasta_q=None, fasta_t=None, query_name=None, target_name=None):
self.id_job = id_job
self.email = email
self.fasta_q = fasta_q
self.fasta_t = fasta_t
self.query = query_name
self.target = target_name
config_reader = AppConfigReader()
# Get configs:
self.batch_system_type = config_reader.get_batch_system_type()
......@@ -27,7 +29,7 @@ class JobManager:
self.paf = os.path.join(self.output_dir, "map.paf")
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.logs = os.path.join(self.output_dir, "logs.txt")
def __check_job_success_local(self):
if os.path.exists(self.paf):
......@@ -41,20 +43,24 @@ class JobManager:
@db_session
def __launch_local(self):
cmd = ["run_minimap2.sh", self.minimap2, self.samtools, self.threads, self.fasta_t, self.fasta_q, self.paf_raw,
self.paf]
cmd = ["run_minimap2.sh", self.minimap2, self.samtools, self.threads, self.fasta_t, self.fasta_q, self.query,
self.target, self.paf_raw, self.paf]
with open(self.logs, "w") as logs:
p = subprocess.Popen(cmd, stdout=logs, stderr=logs)
pid = p.pid
job = Job(id_job=self.id_job, email=self.email, id_process=pid, batch_type="local",
date_created=datetime.datetime.now())
job = Job.get(id_job=self.id_job)
job.id_process = p.pid
job.status = "started"
db.commit()
p.wait()
status = self.check_job_success()
job.status = status
db.commit()
@db_session
def launch(self):
job = Job(id_job=self.id_job, email=self.email, batch_type=self.batch_system_type,
date_created=datetime.datetime.now())
db.commit()
if not os.path.exists(self.output_dir):
os.mkdir(self.output_dir)
if self.batch_system_type == "local":
......@@ -67,4 +73,4 @@ class JobManager:
if job is not None:
return job.status
else:
return "not started"
return "unknown"
import datetime
from config_reader import AppConfigReader
from pony.orm import Database, Required
from pony.orm import Database, Required, Optional
config_reader = AppConfigReader()
file_path = config_reader.get_database()
......@@ -12,9 +12,9 @@ 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)
id_process = Optional(int)
batch_type = Required(str)
status = Required(str, default="started")
status = Required(str, default="submitted")
date_created = Required(datetime.datetime)
......
......@@ -81,7 +81,9 @@ def launch_analysis():
form_pass = False
if form_pass:
# Save files:
query_name = os.path.splitext(os.path.basename(file_query.filename))[0]
filename_query = get_valid_uploaded_filename(secure_filename(file_query.filename), app.config["UPLOAD_FOLDER"])
target_name = os.path.splitext(os.path.basename(file_target.filename))[0]
query_path = os.path.join(app.config["UPLOAD_FOLDER"], filename_query)
file_query.save(query_path)
filename_target = get_valid_uploaded_filename(secure_filename(file_target.filename), app.config["UPLOAD_FOLDER"])
......@@ -94,7 +96,7 @@ def launch_analysis():
id_job = id_job_orig + "_2"
# Launch job:
job = JobManager(id_job, email, query_path, target_path)
job = JobManager(id_job, email, query_path, target_path, query_name, target_name)
job.launch()
return redirect(url_for(".status", id_job=id_job))
else:
......
......@@ -3,11 +3,11 @@
{{ super() }}
<h2 class="status">Job name: {{ id_job }}</h2>
{% if status == "started" %}
<p>Your job is started.<br/>
<p>Your job has started.<br/>
You will receive an email when it will be finished.<br/>
Alternatively, you can refresh this page to update status.</p>
{% elif status == "not started" %}
<p>Your job has been submited.<br/>
{% elif status == "submitted" %}
<p>Your job has been submitted.<br/>
You will receive an email when it will be finished.<br/>
Alternatively, you can refresh this page to update status.</p>
{% elif status == "success" %}
......@@ -16,5 +16,7 @@
{% elif status == "error" %}
<p>Your job has failed. Please try again.<br/>
If the problem persists, please contact the support.</p>
{% else %}
<p>This job does not exists!</p>
{% endif %}
{% 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