Skip to content

Analysis refactor misc #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion qiita_pet/handlers/analysis_handlers/base_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

class CreateAnalysisHandler(BaseHandler):
@authenticated
@execute_as_transaction
def post(self):
name = self.get_argument('name')
desc = self.get_argument('description')
Expand Down
6 changes: 2 additions & 4 deletions qiita_pet/handlers/api_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
study_tags_request)
from .artifact import (artifact_graph_get_req, artifact_types_get_req,
artifact_post_req, artifact_get_req,
artifact_status_put_req,
artifact_summary_get_request, artifact_get_prep_req,
artifact_summary_post_request, artifact_patch_request)
artifact_status_put_req, artifact_get_prep_req,
artifact_patch_request)
from .ontology import ontology_patch_handler
from .processing import (
list_commands_handler_get_req, process_artifact_handler_get_req,
Expand Down Expand Up @@ -62,7 +61,6 @@
'study_tags_request', 'study_tags_patch_request',
'study_get_tags_request',
'prep_template_patch_req', 'ontology_patch_handler',
'artifact_summary_get_request', 'artifact_summary_post_request',
'list_commands_handler_get_req', 'process_artifact_handler_get_req',
'list_options_handler_get_req', 'workflow_handler_post_req',
'workflow_handler_patch_req', 'workflow_run_post_req',
Expand Down
190 changes: 1 addition & 189 deletions qiita_pet/handlers/api_proxy/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from os.path import join, basename
from os.path import join
from functools import partial
from json import dumps

Expand All @@ -28,194 +28,6 @@
PREP_TEMPLATE_KEY_FORMAT = 'prep_template_%s'


def artifact_summary_get_request(user_id, artifact_id):
"""Returns the information for the artifact summary page

Parameters
----------
user_id : str
The user making the request
artifact_id : int or str
The artifact id

Returns
-------
dict of objects
A dictionary containing the artifact summary information
{'status': str,
'message': str,
'name': str,
'summary': str,
'job': list of [str, str, str]}
"""
artifact_id = int(artifact_id)
artifact = Artifact(artifact_id)

access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error

user = User(user_id)
visibility = artifact.visibility
summary = artifact.html_summary_fp
job_info = None
errored_jobs = []
processing_jobs = []
for j in artifact.jobs():
if j.command.software.type == "artifact transformation":
status = j.status
if status == 'success':
continue
j_msg = j.log.msg if status == 'error' else None
processing_jobs.append(
[j.id, j.command.name, j.status, j.step, j_msg])

# Check if the HTML summary exists
if summary:
with open(summary[1]) as f:
summary = f.read()
else:
# Check if the summary is being generated
command = Command.get_html_generator(artifact.artifact_type)
all_jobs = set(artifact.jobs(cmd=command))
jobs = [j for j in all_jobs if j.status in ['queued', 'running']]
errored_jobs = [(j.id, j.log.msg)
for j in all_jobs if j.status in ['error']]
if jobs:
# There is already a job generating the HTML. Also, there should be
# at most one job, because we are not allowing here to start more
# than one
job = jobs[0]
job_info = [job.id, job.status, job.step]

buttons = []
btn_base = (
'<button onclick="if (confirm(\'Are you sure you want to %s '
'artifact id: {0}?\')) {{ set_artifact_visibility(\'%s\', {0}) }}" '
'class="btn btn-primary btn-sm">%s</button>').format(artifact_id)

if qiita_config.require_approval:
if visibility == 'sandbox':
# The request approval button only appears if the artifact is
# sandboxed and the qiita_config specifies that the approval should
# be requested
buttons.append(
btn_base % ('request approval for', 'awaiting_approval',
'Request approval'))

elif user.level == 'admin' and visibility == 'awaiting_approval':
# The approve artifact button only appears if the user is an admin
# the artifact is waiting to be approvaed and the qiita config
# requires artifact approval
buttons.append(btn_base % ('approve', 'private',
'Approve artifact'))

if visibility == 'private':
# The make public button only appears if the artifact is private
buttons.append(btn_base % ('make public', 'public', 'Make public'))

# The revert to sandbox button only appears if the artifact is not
# sandboxed nor public
if visibility not in {'sandbox', 'public'}:
buttons.append(btn_base % ('revert to sandbox', 'sandbox',
'Revert to sandbox'))

if user.level == 'admin':
if artifact.can_be_submitted_to_ebi:
if not artifact.is_submitted_to_ebi:
buttons.append(
'<a class="btn btn-primary btn-sm" '
'href="/ebi_submission/%d">'
'<span class="glyphicon glyphicon-export"></span>'
' Submit to EBI</a>' % artifact_id)
if artifact.can_be_submitted_to_vamps:
if not artifact.is_submitted_to_vamps:
buttons.append(
'<a class="btn btn-primary btn-sm" href="/vamps/%d">'
'<span class="glyphicon glyphicon-export"></span>'
' Submit to VAMPS</a>' % artifact_id)

files = [(f_id, "%s (%s)" % (basename(fp), f_type.replace('_', ' ')))
for f_id, fp, f_type in artifact.filepaths
if f_type != 'directory']

# TODO: https://github.com/biocore/qiita/issues/1724 Remove this hardcoded
# values to actually get the information from the database once it stores
# the information
if artifact.artifact_type in ['SFF', 'FASTQ', 'FASTA', 'FASTA_Sanger',
'per_sample_FASTQ']:
# If the artifact is one of the "raw" types, only the owner of the
# study and users that has been shared with can see the files
if not artifact.study.has_access(user, no_public=True):
files = []

processing_parameters = (artifact.processing_parameters.values
if artifact.processing_parameters is not None
else {})

return {'status': 'success',
'message': '',
'name': artifact.name,
'summary': summary,
'job': job_info,
'errored_jobs': errored_jobs,
'processing_jobs': processing_jobs,
'visibility': visibility,
'buttons': ' '.join(buttons),
'files': files,
'editable': artifact.study.can_edit(user),
'study_id': artifact.study.id,
'prep_id': artifact.prep_templates[0].id,
'processing_parameters': processing_parameters}


def artifact_summary_post_request(user_id, artifact_id):
"""Launches the HTML summary generation and returns the job information

Parameters
----------
user_id : str
The user making the request
artifact_id : int or str
The artifact id

Returns
-------
dict of objects
A dictionary containing the artifact summary information
{'status': str,
'message': str,
'job': list of [str, str, str]}
"""
artifact_id = int(artifact_id)
artifact = Artifact(artifact_id)

access_error = check_access(artifact.study.id, user_id)
if access_error:
return access_error

# Check if the summary is being generated or has been already generated
command = Command.get_html_generator(artifact.artifact_type)
jobs = artifact.jobs(cmd=command)
jobs = [j for j in jobs if j.status in ['queued', 'running', 'success']]
if jobs:
# The HTML summary is either being generated or already generated.
# Return the information of that job so we only generate the HTML
# once
job = jobs[0]
else:
# Create a new job to generate the HTML summary and return the newly
# created job information
job = ProcessingJob.create(
User(user_id),
Parameters.load(command, values_dict={'input_data': artifact_id}))
job.submit()

return {'status': 'success',
'message': '',
'job': [job.id, job.status, job.step]}


def artifact_get_req(user_id, artifact_id):
"""Returns all base information about an artifact

Expand Down
Loading