-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98e8012
commit 492664d
Showing
7 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,63 @@ | ||
def check_rnaseq(df): | ||
status=True | ||
msg=None | ||
import pandas as pd | ||
import io | ||
from werkzeug.utils import secure_filename | ||
import re | ||
|
||
|
||
def check_rnaseq(EXC): | ||
if "samples" not in EXC.sheet_names: | ||
status=False | ||
msg="Could not find sample information - 'samples' sheet - in the submission file." | ||
return status, msg | ||
metadata=EXC.parse("RNAseq") | ||
email=metadata[ metadata["Field"] == "email"][ "Value" ].values[0] | ||
email=str(email).rstrip().lstrip() | ||
email=email.split(",") | ||
email=[ re.search("([^@|\s]+@[^@]+\.[^@|\s]+)",e,re.I) for e in email ] | ||
email=[ e.group(1) for e in email if e ] | ||
if not email : | ||
status=False | ||
msg="Contact email is not a valid email. Please provide a valid email in the 'email' field of your submission file." | ||
return status, msg | ||
nas=metadata[metadata["Value"].isna()]["Field"].tolist() | ||
if nas: | ||
status=False | ||
msg="The following fields require a valid value: {fields} ".format(fields=", ".join(nas) ) | ||
return status, msg | ||
|
||
status="RNAseq" | ||
msg="Submission successuful. Please check for email confirmation." | ||
return status, msg | ||
|
||
def submission_check(df, submission_type="RNAseq"): | ||
if submission_type=="RNAseq": | ||
status, msg=check_rnaseq(df) | ||
def submission_check(inputfile): | ||
valid_submissions=["RNAseq"] | ||
|
||
filename = secure_filename(inputfile.filename) | ||
fileread = inputfile.read() | ||
filestream=io.BytesIO(fileread) | ||
extension=filename.rsplit('.', 1)[1].lower() | ||
if extension != "xlsx": | ||
status=False | ||
msg="Wrong file extension detected." | ||
return status, msg | ||
|
||
EXC=pd.ExcelFile(filestream) | ||
sheets=EXC.sheet_names | ||
submission_type=[ s for s in sheets if s in valid_submissions ] | ||
if len(submission_type) > 1 : | ||
status=False | ||
msg="More than one submission type detected." | ||
return status, msg | ||
|
||
elif len(submission_type) == 0 : | ||
status=False | ||
msg="This submission file did not contain a valid submission sheet. Make sure you do not change the sheet names when editing the submission file." | ||
return status, msg | ||
|
||
if submission_type[0]=="RNAseq": | ||
status, msg=check_rnaseq(EXC) | ||
else: | ||
status=False | ||
msg="Submission failed." | ||
|
||
return status, msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,23 @@ | |
from flaski import app | ||
from flask_mail import Message | ||
from flaski import mail | ||
from werkzeug.utils import secure_filename | ||
|
||
|
||
def send_async_email(app, msg): | ||
with app.app_context(): | ||
mail.send(msg) | ||
|
||
def send_email(subject, sender, recipients, text_body, html_body, reply_to): | ||
def send_email(subject, sender, recipients, text_body, html_body, reply_to, attatchment=None): | ||
msg = Message(subject, sender=sender, recipients=recipients, reply_to = reply_to) | ||
msg.body = text_body | ||
msg.html = html_body | ||
if attatchment: | ||
msg.attach( | ||
secure_filename(attatchment.filename), | ||
'application/octect-stream', | ||
attatchment.read()) | ||
|
||
Thread(target=send_async_email, args=(app, msg)).start() | ||
|
||
def send_password_reset_email(user): | ||
|
@@ -80,3 +88,15 @@ def send_help_email(user,eapp,emsg,etime,session_file): | |
html_body=render_template('email/app_help.html', | ||
user=user, eapp=eapp, emsg=emsg_html, etime=etime, session_file=session_file),\ | ||
reply_to=user.email ) | ||
|
||
def send_submission_email(user,submission_type,submission_file): | ||
with app.app_context(): | ||
send_email('[Flaski][Automation][{submission_type}] Files have been submited for analysis.'.format(submission_type=submission_type), | ||
sender=app.config['MAIL_USERNAME'], | ||
recipients=[user.email,"[email protected]"], | ||
text_body=render_template('email/submissions.txt', | ||
user=user, submission_type=submission_type), | ||
html_body=render_template('email/submissions.html', | ||
user=user, submission_type=submission_type),\ | ||
reply_to='[email protected]',\ | ||
attatchment=submission_file ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<p>Files have been submitted by {{ user.firstname }} for {{ submission_type }} analysis.</p> | ||
<p>Submission form attached.</p> | ||
|
||
<br> | ||
<p>Cheers!</p> | ||
<p>Flaski</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Files have been submitted by {{ user.firstname }} for {{ submission_type }} analysis. | ||
|
||
Submission form attached. | ||
|
||
Cheers! | ||
|
||
Flaski |