Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
D-GENIES
Commits
8dfcf5fc
Commit
8dfcf5fc
authored
Nov 16, 2017
by
Floreal Cabanettes
Browse files
Some fixes for export Fasta
parent
89551fe5
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/functions.py
View file @
8dfcf5fc
...
...
@@ -142,8 +142,9 @@ class Functions:
def
read_index
(
index_file
):
index
=
OrderedDict
()
with
open
(
index_file
,
"r"
)
as
index_f
:
lines
=
index_f
.
readlines
()
for
line
in
lines
[
1
:]:
# Sample name without special chars:
sample_name
=
re
.
sub
(
'[^A-Za-z0-9_\-.]+'
,
''
,
index_f
.
readline
().
strip
(
"
\n
"
).
replace
(
" "
,
"_"
))
for
line
in
index_f
:
if
line
!=
""
:
parts
=
line
.
strip
(
"
\n
"
).
split
(
"
\t
"
)
name
=
parts
[
0
]
...
...
@@ -153,7 +154,7 @@ class Functions:
"length"
:
lenght
,
"to_reverse"
:
to_reverse
}
return
index
return
index
,
sample_name
@
staticmethod
@
db_session
...
...
@@ -162,25 +163,26 @@ class Functions:
return
j1
.
email
@
staticmethod
def
send_fasta_ready
(
mailer
,
job_name
):
def
send_fasta_ready
(
mailer
,
job_name
,
sample_name
,
compressed
=
False
):
config_reader
=
AppConfigReader
()
web_url
=
config_reader
.
get_web_url
()
with
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"mail_templates"
,
"dl_fasta.html"
))
\
as
t_file
:
template
=
Template
(
t_file
.
read
())
message_html
=
template
.
render
(
job_name
=
job_name
,
status
=
"success"
,
url_base
=
web_url
)
message_html
=
template
.
render
(
job_name
=
job_name
,
status
=
"success"
,
url_base
=
web_url
,
sample_name
=
sample_name
,
compressed
=
compressed
)
message
=
"D-Genies
\n\n
"
\
"Job %s - Download fasta
\n\n
"
%
job_name
message
+=
"Query fasta file for job %s is ready to download."
%
job_name
message
+=
"Query fasta file for job %s
(query: %s)
is ready to download.
\n
"
%
(
job_name
,
sample_name
)
message
+=
"You can click on the link below to download it:
\n\n
"
message
+=
"%s/fasta-query/%s"
%
(
web_url
,
job_name
)
message
+=
"%s/fasta-query/%s
/%s
"
%
(
web_url
,
job_name
,
sample_name
+
".fasta"
+
(
".gz"
if
compressed
else
""
)
)
mailer
.
send_mail
([
Functions
.
get_mail_for_job
(
job_name
)],
"Job %s - Download fasta"
%
job_name
,
message
,
message_html
)
@
staticmethod
def
sort_fasta
(
job_name
,
fasta_file
,
index_file
,
lock_file
,
compress
=
False
,
mailer
=
None
):
print
(
"Loading index..."
)
index
=
Functions
.
read_index
(
index_file
)
index
,
sample_name
=
Functions
.
read_index
(
index_file
)
print
(
"Starting fasta sort..."
)
is_compressed
=
fasta_file
.
endswith
(
".gz"
)
if
is_compressed
:
...
...
@@ -200,5 +202,13 @@ class Functions:
Functions
.
compress
(
fasta_file_o
)
os
.
remove
(
lock_file
)
if
mailer
is
not
None
:
Functions
.
send_fasta_ready
(
mailer
,
job_name
)
Functions
.
send_fasta_ready
(
mailer
,
job_name
,
sample_name
,
compress
)
print
(
"Fasta sort done!"
)
@
staticmethod
def
compress_and_send_mail
(
job_name
,
fasta_file
,
index_file
,
compressed
,
mailer
):
print
(
"Compress!"
)
Functions
.
compress
(
fasta_file
)
index
,
sample_name
=
Functions
.
read_index
(
index_file
)
Functions
.
send_fasta_ready
(
mailer
,
job_name
,
sample_name
,
compressed
)
print
(
"DONE!"
)
\ No newline at end of file
lib/mail_templates/dl_fasta.html
View file @
8dfcf5fc
...
...
@@ -28,8 +28,8 @@
</h3>
<p>
Hi,
</p>
{% if status == "success" %}
<p>
Query fasta file for job {{ job_name }} is ready to download.
You can
<a
href=
"{{ url_base }}/fasta-query/{{ job_name }}"
>
click here
</a>
to download it.
</p>
<p>
Query fasta file for job {{ job_name }}
(query: {{ sample_name }})
is ready to download.
<br/>
You can
<a
href=
"{{ url_base }}/fasta-query/{{ job_name }}
/{{ sample_name }}.fasta{% if compressed %}.gz{% endif %}
"
>
click here
</a>
to download it.
</p>
{% else %}
<p>
Build of query fasta file for job {{ job_name }} has failed. You can try again. If the problem persists, please contact the support.
</p>
{% endif %}
...
...
srv/main.py
View file @
8dfcf5fc
...
...
@@ -207,6 +207,7 @@ def build_fasta(id_res):
res_dir
=
os
.
path
.
join
(
app_data
,
id_res
)
lock_query
=
os
.
path
.
join
(
res_dir
,
".query-fasta-build"
)
is_sorted
=
os
.
path
.
exists
(
os
.
path
.
join
(
res_dir
,
".sorted"
))
compressed
=
request
.
form
[
"gzip"
].
lower
()
==
"true"
query_fasta
=
Functions
.
get_fasta_file
(
res_dir
,
"query"
,
is_sorted
)
if
query_fasta
is
not
None
:
if
is_sorted
and
not
query_fasta
.
endswith
(
".sorted"
):
...
...
@@ -217,7 +218,7 @@ def build_fasta(id_res):
"fasta_file"
:
query_fasta
,
"index_file"
:
os
.
path
.
join
(
res_dir
,
"query.idx.sorted"
),
"lock_file"
:
lock_query
,
"compress"
:
request
.
form
[
"gzip"
]
,
"compress"
:
compressed
,
"mailer"
:
mailer
})
thread
.
start
()
...
...
@@ -227,6 +228,18 @@ def build_fasta(id_res):
return
jsonify
({
"success"
:
True
,
"status"
:
1
,
"status_message"
:
"In progress"
})
else
:
# No sort to do or sort done
if
compressed
and
not
query_fasta
.
endswith
(
".gz.fasta"
):
# If compressed file is asked, we must compress it now if not done before...
Path
(
lock_query
).
touch
()
thread
=
threading
.
Timer
(
1
,
Functions
.
compress_and_send_mail
,
kwargs
=
{
"job_name"
:
id_res
,
"fasta_file"
:
query_fasta
,
"index_file"
:
os
.
path
.
join
(
res_dir
,
"query.idx.sorted"
),
"compressed"
:
compressed
,
"mailer"
:
mailer
})
thread
.
start
()
return
jsonify
({
"success"
:
True
,
"status"
:
1
,
"status_message"
:
"In progress"
})
return
jsonify
({
"success"
:
True
,
"status"
:
2
,
"status_message"
:
"Done"
,
"gzip"
:
query_fasta
.
endswith
(
".gz"
)
or
query_fasta
.
endswith
(
".gz.sorted"
)})
else
:
...
...
@@ -234,8 +247,9 @@ def build_fasta(id_res):
"message"
:
"Unable to get fasta file for query. Please contact us to report the bug"
})
@
app
.
route
(
'/fasta-query/<id_res>'
,
methods
=
[
'GET'
])
def
dl_fasta
(
id_res
):
@
app
.
route
(
'/fasta-query/<id_res>'
,
defaults
=
{
'filename'
:
""
},
methods
=
[
'GET'
])
@
app
.
route
(
'/fasta-query/<id_res>/<filename>'
,
methods
=
[
'GET'
])
# Use fake URL in mail to set download file name
def
dl_fasta
(
id_res
,
filename
):
res_dir
=
os
.
path
.
join
(
app_data
,
id_res
)
lock_query
=
os
.
path
.
join
(
res_dir
,
".query-fasta-build"
)
is_sorted
=
os
.
path
.
exists
(
os
.
path
.
join
(
res_dir
,
".sorted"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment