Skip to content

Commit

Permalink
added api for predemult report upload
Browse files Browse the repository at this point in the history
  • Loading branch information
avikdatta committed May 30, 2023
1 parent 2b69a0d commit d4150a2
Show file tree
Hide file tree
Showing 14 changed files with 16,389 additions and 282 deletions.
59 changes: 50 additions & 9 deletions app/iframe_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,72 @@
from flask_appbuilder.baseviews import BaseView, expose
from flask_appbuilder.security.decorators import protect, has_access
from app import db
from .models import Project_analysis_info_file
from .models import Project_seqrun_info_file
from .models import Project_seqrun_info_data
from .models import Project_analysis_info_data
from .metadata_view import ProjectView
from .models import (
Project_analysis_info_file,
Project_seqrun_info_file,
Project_seqrun_info_data,
Project_analysis_info_data,
PreDeMultiplexingData)


log = logging.getLogger(__name__)

def get_path_for_project_seqrun_info_file(id):
try:
(file_path, project_id) = \
record = \
db.session.\
query(
Project_seqrun_info_file.file_path,
Project_seqrun_info_data.project_id).\
join(Project_seqrun_info_data, Project_seqrun_info_data.project_seqrun_info_data_id==Project_seqrun_info_file.project_seqrun_info_data_id).\
filter(Project_seqrun_info_file.project_seqrun_info_file_id==id).\
one_or_none()
if record is None:
log.warning(f"Missing data for id {id}")
return '', ''
(file_path, project_id) = record
return file_path, project_id
except Exception as e:
log.error(e)

def get_path_for_project_analysis_info_file(id):
try:
(file_path, project_id) = \
record = \
db.session.\
query(
Project_analysis_info_file.file_path,
Project_analysis_info_data.project_id).\
join(Project_analysis_info_data, Project_analysis_info_data.project_analysis_info_data_id==Project_analysis_info_file.project_analysis_info_data_id).\
filter(Project_analysis_info_file.project_analysis_info_file_id==id).\
one_or_none()
if record is None:
log.warning(f"Missing data for id {id}")
return '', ''
(file_path, project_id) = record
return file_path, project_id
except Exception as e:
log.error(e)


def get_path_for_predemult_report(id):
try:
record = \
db.session.\
query(PreDeMultiplexingData.file_path).\
filter(PreDeMultiplexingData.demult_id==id).\
one_or_none()
if record is None:
log.warning(
f"Missing pre-demult data for id {id}")
return ''
(file_path,) = \
record
return file_path
except Exception as e:
raise ValueError(
f"Failed to get report for predemult entry {id}, error: {e}")


class IFrameView(BaseView):
route_base = "/"

Expand All @@ -57,7 +86,7 @@ def view_seqrun_report(self, id):
# return self.render_template("iframe.html", url=file_path, project_url=project_url)
with open(file_path, 'r') as fp:
html_data = fp.read()
return self.render_template("iframe.html", html_data=html_data, project_url=project_url)
return self.render_template("iframe.html", html_data=html_data, url_link=project_url)

@expose("/static/analysis/<int:id>")
@has_access
Expand All @@ -70,4 +99,16 @@ def view_analysis_report(self, id):
# return self.render_template("iframe.html", url=file_path, project_url=project_url)
with open(file_path, 'r') as fp:
html_data = fp.read()
return self.render_template("iframe.html", html_data=html_data, project_url=project_url)
return self.render_template("iframe.html", html_data=html_data, url_link=project_url)

@expose("/static/predemult/<int:id>")
@has_access
@cache.cached(timeout=600)
def view_predemult_report(self, id):
file_path = \
get_path_for_predemult_report(id=id)
url_link = \
url_for('PreDeMultiplexingDataView.list')
with open(file_path, 'r') as fp:
html_data = fp.read()
return self.render_template("iframe.html", html_data=html_data, url_link=url_link)
7 changes: 5 additions & 2 deletions app/metadata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
from . import app, db, celery
from .metadata.metadata_util import cleanup_and_load_new_data_to_metadata_tables

log = logging.getLogger(__name__)

@celery.task(bind=True)
def async_cleanup_and_load_new_data_to_metadata_tables(
self, json_file: str) -> dict:
try:
cleanup_and_load_new_data_to_metadata_tables(json_file)
return {"message": "success"}
except Exception as e:
logging.error(
log.error(
"Failed to run celery job, error: {0}".\
format(e))

Expand Down Expand Up @@ -51,6 +53,7 @@ def submit_cleanup_job(self):
apply_async(args=[json_file])
return self.response(200, message='successfully submitted metadata update job')
except Exception as e:
logging.error(e)
log.error(e)
return self.response_500('failed to submit metadata update job')


17 changes: 5 additions & 12 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,18 @@ def __repr__(self):
class PreDeMultiplexingData(Model):
__tablename__ = 'pre_demultiplexing_data'
__table_args__ = (
UniqueConstraint('run_name', 'samplesheet_tag'),
UniqueConstraint('run_name', 'samplesheet_tag', 'date_stamp'),
{ 'mysql_engine':'InnoDB', 'mysql_charset':'utf8' })
demult_id = Column(INTEGER(unsigned=True), primary_key=True, nullable=False)
run_name = Column(String(50), nullable=False)
samplesheet_tag = Column(String(50), nullable=False)
flowcell_cluster_plot = Column(TEXT())
project_summary_table = Column(TEXT())
project_summary_plot = Column(TEXT())
sample_table = Column(TEXT())
sample_plot= Column(TEXT())
undetermined_table = Column(TEXT())
undetermined_plot = Column(TEXT())
file_path = Column(String(500), nullable=True)
status = Column(Enum("ACTIVE", "WITHDRAWN", "UNKNOWN"), nullable=False, server_default='UNKNOWN')
samplesheet_tag = Column(String(200), nullable=False)
file_path = Column(String(500), nullable=False)
status = Column(Enum("ACTIVE", "WITHDRAWN", "UNKNOWN"), nullable=False, server_default='ACTIVE')
date_stamp = Column(TIMESTAMP(), nullable=False, server_default=current_timestamp(), onupdate=datetime.datetime.now)
def __repr__(self):
return self.run_name
def report(self):
return Markup('<a href="'+url_for('PreDeMultiplexingDataView.get_report', id=self.demult_id)+'">report</a>')
return Markup('<a href="'+url_for('IFrameView.view_predemult_report', id=self.demult_id)+'">report</a>')

"""
Admin home view
Expand Down
Loading

0 comments on commit d4150a2

Please sign in to comment.