Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
568 commits
Select commit Hold shift + click to select a range
47598a2
Addressing @ElDeveloper comments
josenavas Mar 12, 2016
5be562a
Merge branch 'artifact-study-pages-artifact-creation' into artifact-s…
josenavas Mar 12, 2016
e7591f4
Pep8ing
josenavas Mar 12, 2016
fa10ecc
Modifying database
josenavas Mar 13, 2016
4c05c38
Fixing type
josenavas Mar 13, 2016
d5aa103
Forking off the QiitaClient as it's own 'project' and update the targ…
josenavas Mar 13, 2016
d68049c
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 13, 2016
1279ed5
Fixing setup.py
josenavas Mar 13, 2016
7c3135b
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 13, 2016
ca52a5b
Adding type propery to software
josenavas Mar 14, 2016
0afb571
Adapting the job complete function to the type plugins
josenavas Mar 14, 2016
ccc1e8f
Cleaning env
josenavas Mar 14, 2016
ef83464
Merge pull request #1680 from josenavas/artifact-study-pages-artifact…
ElDeveloper Mar 14, 2016
990dc14
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 14, 2016
6347d21
initial commit
antgonza Mar 14, 2016
4d153e4
Limiting new user defined terms to alphanumeric + space
josenavas Mar 14, 2016
6f86470
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 14, 2016
1c4c347
Merge branch 'artifact-study-pages-prep-artifact-integration' into ar…
josenavas Mar 14, 2016
efe3415
Merge branch 'artifact-study-pages-prep-artifact-integration' into ar…
josenavas Mar 14, 2016
39c36ba
Merge branch 'artifact-study-page-qiita-client-package' into artifact…
josenavas Mar 14, 2016
4b3f9ce
Creating the biom type plugin and stubbing out the html summary gener…
josenavas Mar 14, 2016
2838e2e
Merge pull request #1684 from antgonza/fix-patch-37
ElDeveloper Mar 14, 2016
01a3ad3
Fixing typo
josenavas Mar 15, 2016
28bb3f9
Adding target gene type plugin
josenavas Mar 15, 2016
aefb908
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
8ea2653
Addressing @ElDeveloper's comments
josenavas Mar 15, 2016
4b2454d
Merge upstream/artifact-study-pages
josenavas Mar 15, 2016
f28f331
Merge pull request #1683 from josenavas/artifact-study-pages-prep-art…
ElDeveloper Mar 15, 2016
f35fcf0
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
4b22aa4
Fixing travis to install the qiita_client
josenavas Mar 15, 2016
d8bf07f
Fixing setup typo
josenavas Mar 15, 2016
fce4c30
Addressing @mortonjt's comment
josenavas Mar 15, 2016
9c97f59
Merge pull request #1685 from josenavas/artifact-study-page-qiita-cli…
antgonza Mar 15, 2016
8503746
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 15, 2016
8eaf5dd
Addressing @antgonza's comments
josenavas Mar 16, 2016
4c84a90
Merge branch 'artifact-study-pages-type-plugins-biom' of https://gith…
antgonza Mar 16, 2016
50a0eb3
Addressing @ElDeveloper's comments
josenavas Mar 16, 2016
2ee35d7
Adding patch method to the QiitaClient
josenavas Mar 16, 2016
6bfd6e2
Fixing docs
josenavas Mar 16, 2016
73cfbd4
Fixing tests due to nomenclature change
josenavas Mar 17, 2016
2379862
Merge pull request #1686 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 17, 2016
0b220dc
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
0bd7d0f
Modify retrieve_filepaths to add an extra parameter 'fp_type'
josenavas Mar 17, 2016
ff3e2fb
Adding artifact.html_summary_fp property
josenavas Mar 17, 2016
7bb82e0
Adding html summary setter
josenavas Mar 17, 2016
d73f43b
Merge pull request #1692 from josenavas/artifact-study-pages-qiita-cl…
antgonza Mar 17, 2016
48238d9
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
2cc5459
Adding html_summary_fp to filepath_type table
josenavas Mar 17, 2016
a55379f
Adding patch method to the ArtifactFilepathsHandler
josenavas Mar 17, 2016
c289715
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
302e0b5
Addressing @antgonza's comment and adding a test
josenavas Mar 17, 2016
221894b
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 17, 2016
7a18077
initial commit
antgonza Mar 17, 2016
3cdd107
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 17, 2016
d67a3ab
Addressing @wasade's comments
josenavas Mar 18, 2016
9c99068
Doing small modifications in the patch due to the method name change
josenavas Mar 18, 2016
78c7ea0
Merge pull request #1687 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 18, 2016
a6d9fed
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 18, 2016
72f863a
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 18, 2016
7d2b4c8
Fixing failing test
josenavas Mar 18, 2016
4f1d9fd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 18, 2016
02e3644
Adapting the plugin to the new nomenclature
josenavas Mar 18, 2016
4eb0221
Fixing bug and adding test
josenavas Mar 19, 2016
c9db473
Finishing up validation
josenavas Mar 19, 2016
69b1c66
Adding one more test
josenavas Mar 19, 2016
7ddb855
addressing @josenavas comments
antgonza Mar 19, 2016
447e5ef
fixing flake8
antgonza Mar 19, 2016
ee31795
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 19, 2016
61e159c
Merge branch 'artifact-study-pages-type-plugins-tgene' of https://git…
antgonza Mar 19, 2016
191da2c
initial commit
antgonza Mar 20, 2016
af371b0
Merge branch 'artifact-study-pages-adding-biom' into artifact-study-p…
josenavas Mar 20, 2016
3a0eb6e
Merge branch 'artifact-study-pages-type-plugins-tgene' into artifact-…
josenavas Mar 20, 2016
8b0d578
Merge branch 'artifact-study-pages-type-plugins-tgene-summaries' into…
josenavas Mar 20, 2016
4f61979
adding demux summary
antgonza Mar 20, 2016
7b19ea9
Addressing comments
josenavas Mar 21, 2016
2f6fa27
Merge pull request #1694 from josenavas/artifact-study-pages-patch-fi…
antgonza Mar 21, 2016
2823205
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 21, 2016
afc250b
adding get_html_generator classmethod to command
josenavas Mar 21, 2016
419cd21
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 21, 2016
1ba7fbc
Adding artifact_summary_get_request and tests
josenavas Mar 21, 2016
6aee0d5
addressing @ElDeveloper comments
antgonza Mar 21, 2016
903f2e0
Change scripts permissions
josenavas Mar 21, 2016
322c84c
Fixing bug on qiita-plugin-launcher that prevented to log an error on…
josenavas Mar 21, 2016
953e862
Adding artifact_summary_post_request and tests
josenavas Mar 21, 2016
9ba931f
Adding minimal Artifact summary interface
josenavas Mar 21, 2016
1147180
Merge pull request #1696 from antgonza/artifact-study-pages-adding-biom
ElDeveloper Mar 21, 2016
9c5516f
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 21, 2016
b2addd2
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
c119b16
Fixing returns to be the object payload
josenavas Mar 22, 2016
d818a8b
Making the call to generate the artifact
josenavas Mar 22, 2016
e04f478
Fixing return payload
josenavas Mar 22, 2016
b8817c6
doing something with the post output
josenavas Mar 22, 2016
1abf01e
Adding visibility
josenavas Mar 22, 2016
e783180
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
286fd7e
Addressing comments
josenavas Mar 22, 2016
b69fe48
Merge pull request #1697 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 22, 2016
c8c1fbd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 22, 2016
04e7769
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 22, 2016
96f36d4
addressing @josenavas and @ElDeveloper comments
antgonza Mar 22, 2016
19181de
adding labels, RE: @ElDeveloper
antgonza Mar 22, 2016
b957d4a
Connecting artifact summary with processing
josenavas Mar 22, 2016
47fc001
Merge pull request #1698 from antgonza/artifact-study-pages-type-plug…
josenavas Mar 22, 2016
fa73eb1
displaying processing graph
josenavas Mar 23, 2016
225d9b2
Adding classmethod to command to retrieve commands that process given…
josenavas Mar 23, 2016
4043e9a
Adding outputs property to commands
josenavas Mar 23, 2016
c83d40c
Retrieving correct commands
josenavas Mar 23, 2016
35ddff3
Solgin merge conflicts
josenavas Mar 23, 2016
14aff19
Changin button styles - thanks @ElDeveloper
josenavas Mar 23, 2016
05de2db
Adding comments
josenavas Mar 23, 2016
a81f6a0
changing to **res
josenavas Mar 23, 2016
ce8725c
Removing console.log calls
josenavas Mar 23, 2016
8984c28
Adding list_options_handler_get_req
josenavas Mar 23, 2016
964952a
Forgot to change __init__.py
josenavas Mar 23, 2016
37711a4
Merge branch 'artifact-study-pages-type-plugins-connections' into art…
josenavas Mar 23, 2016
6f42168
for to list comp
josenavas Mar 23, 2016
6015a8c
Adding better way to choose parameters
josenavas Mar 23, 2016
d8db841
Merge pull request #1702 from josenavas/artifact-study-pages-type-plu…
ElDeveloper Mar 23, 2016
a0cb72e
Finishing up load artifact type gui
josenavas Mar 23, 2016
30c578d
Adding workflow_handler_post_req
josenavas Mar 23, 2016
d82c901
Adding type information to the required parameters
josenavas Mar 23, 2016
555156b
Adding required options to the returne objs
josenavas Mar 24, 2016
8f62384
Adding handler for creating a workflow
josenavas Mar 24, 2016
542fe6d
Adding endpoint to create the workflow
josenavas Mar 24, 2016
e398d9c
Completing workflow creation
josenavas Mar 24, 2016
946aef3
Adding patch request to the workflow
josenavas Mar 24, 2016
c360729
Finishing up interface for adding commands
josenavas Mar 24, 2016
a9b8822
Fixing add function in workflow to be able to add a new root job
josenavas Mar 24, 2016
050c1f4
Fixing patch call
josenavas Mar 24, 2016
5725b2e
Fixing a test
josenavas Mar 24, 2016
0dff918
Update JS to successfully be able to add any job
josenavas Mar 24, 2016
ba7ba48
Initial hook-yp to retrieve job info
josenavas Mar 24, 2016
61e5950
Showing processing job information
josenavas Mar 24, 2016
30987c9
Adding test
josenavas Mar 24, 2016
50e1507
Improving documentation
josenavas Mar 24, 2016
14e39cd
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 24, 2016
5207d8c
Hooking up workflow submission
josenavas Mar 24, 2016
f01a357
Allowing cascade removal
josenavas Mar 24, 2016
5c238bc
Hooking up interface and backend
josenavas Mar 24, 2016
5e40cd8
Updating the GUI accordingly after removal
josenavas Mar 24, 2016
dd69406
Fix submission enabling/disabling
josenavas Mar 24, 2016
1119fd6
Addressing @antgonza's comments
josenavas Mar 24, 2016
936098c
Adding JS docs
josenavas Mar 24, 2016
0e0866b
Fixing small bug
josenavas Mar 24, 2016
7f148fe
Show running jobs in the artifact page
josenavas Mar 24, 2016
50504b4
Fixing test
josenavas Mar 24, 2016
3958298
Addressing @antgonza's comments
josenavas Mar 24, 2016
b5686b5
setting not null property later so we can apply the patch
josenavas Mar 24, 2016
80be11e
Fixing bug in patch - and adding test to catch the bug
josenavas Mar 24, 2016
9f53e01
Adding missing var
josenavas Mar 24, 2016
246f619
Adding more missing vars
josenavas Mar 24, 2016
2fd8740
Addressing @ElDeveloper's comments
josenavas Mar 24, 2016
447e7ba
Merge pull request #1707 from josenavas/artifact-study-pages-fix-patches
antgonza Mar 25, 2016
898ffab
Merge pull request #1705 from josenavas/artifact-study-pages-type-plu…
antgonza Mar 25, 2016
22c5743
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 25, 2016
b7aeaa1
Merge pull request #1706 from josenavas/artifact-study-pages-show-procs
antgonza Mar 25, 2016
a6067ee
Making lab person optional
josenavas Mar 25, 2016
0f6d37f
Updating job status at submission
josenavas Mar 25, 2016
e3673e5
Adding download buttons
josenavas Mar 25, 2016
cc70ae3
Fixing tests
josenavas Mar 25, 2016
dbfe1c9
Merge pull request #1708 from josenavas/artifact-study-pages-opt-lab-…
antgonza Mar 25, 2016
f175495
Limiting study edit access to admin, owner and shared users
josenavas Mar 25, 2016
fcde985
Solving merge conflicts - ouch
josenavas Mar 25, 2016
0298f10
Create can_edit function in study so we can re-use
josenavas Mar 25, 2016
00de78d
Limiting edit permissions in the prep template summary
josenavas Mar 25, 2016
2cacd69
Merge pull request #1710 from josenavas/artifact-study-pages-download…
antgonza Mar 25, 2016
07aabe2
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 25, 2016
853acab
Limiting edition privileges in the artifact summary
josenavas Mar 25, 2016
7b02f76
Limit pt visibility for public studies
josenavas Mar 25, 2016
fa9130d
Adding a test
josenavas Mar 25, 2016
017fd89
Propagating the visibility up the parents
josenavas Mar 26, 2016
835fd2a
Filtering graph for public only
josenavas Mar 26, 2016
037e567
Refactoring the sample summary page and limiting edition privileges
josenavas Mar 26, 2016
dc80314
Fixing graph generation
josenavas Mar 26, 2016
61d1e2b
Merge pull request #1711 from josenavas/artifact-study-pages-limit-ac…
antgonza Mar 26, 2016
fac9d70
Addig the data type on the prep template summary
josenavas Mar 26, 2016
a5f6702
Changing default name in the artifact
josenavas Mar 26, 2016
21706e0
Moving edit and delete study to the study information page
josenavas Mar 26, 2016
6f5cdfb
Asking for the title instead of the alias when deleting and improving…
josenavas Mar 26, 2016
c179b68
Adding message when no prep templates has been added, instead of the …
josenavas Mar 26, 2016
23bf2ef
Redirecting to the study listing page when deleting a study
josenavas Mar 26, 2016
1587098
Showing the sample summary link only if there is a sample template fo…
josenavas Mar 26, 2016
fc57793
Fixing bug in default value
josenavas Mar 26, 2016
28554d8
Fix bug preventing to upload a qiime mapping file
josenavas Mar 26, 2016
6798c1e
Disable button if file is not selected
josenavas Mar 26, 2016
49f858f
In the edit page, it was assume that lab person existed
josenavas Mar 26, 2016
6effa7c
Redirecting once the workflow is submitted
josenavas Mar 26, 2016
e1173e2
Merge pull request #1712 from josenavas/artifact-study-pages-misc
antgonza Mar 26, 2016
f9aa2a7
Asking for confirmation before deleting a sample template
josenavas Mar 26, 2016
5820b44
Removing boostrap alert timeout
josenavas Mar 26, 2016
6467a4d
Fixing interface to show/hide the sample summary button accordingly
josenavas Mar 26, 2016
fb569bb
Not showing jobs completed succesfully and showing the error message …
josenavas Mar 26, 2016
0f76906
Merge pull request #1713 from josenavas/artifact-study-pages-misc2
antgonza Mar 26, 2016
f2aa041
Fixing artifact tests
josenavas Mar 26, 2016
4e054f1
Fixing prep template tests
josenavas Mar 26, 2016
6ee1f68
Fixing test processing
josenavas Mar 26, 2016
4a6dd5e
Fixing handler tests
josenavas Mar 26, 2016
1f9dccc
fixing prep template handlers tests
josenavas Mar 26, 2016
6dd28b0
Fixing search tests
josenavas Mar 26, 2016
bed50a4
Fixing software tests
josenavas Mar 26, 2016
6be4450
Fixing test study
josenavas Mar 26, 2016
ce64620
Adding patch operation to the artifact handler
josenavas Mar 26, 2016
4150efc
fixing API
josenavas Mar 26, 2016
9351dbb
Enabling user to change the artifact name
josenavas Mar 27, 2016
203b8ba
Changing buttons color
josenavas Mar 27, 2016
d724dfd
Show the add prep menu item only if there is a sample template added
josenavas Mar 27, 2016
dcb4a51
Merge pull request #1714 from josenavas/artifact-study-pages-assert-i…
antgonza Mar 27, 2016
3277917
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 27, 2016
25891f8
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 27, 2016
9cec1f2
Addressing @antgonza
josenavas Mar 28, 2016
7014f68
Merge branch 'artifact-study-pages-rename-artifacts' into artifact-st…
josenavas Mar 28, 2016
df9ddec
Merge pull request #1715 from josenavas/artifact-study-pages-rename-a…
antgonza Mar 28, 2016
6aed1f3
Adding user artifacts method to the user object
josenavas Mar 28, 2016
d92f4ba
Allow importing artifacts from other studies
josenavas Mar 28, 2016
8365dce
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 28, 2016
9325676
Addressing @ElDeveloper's and @antgonza's comments
josenavas Mar 29, 2016
94017de
initial commit
antgonza Mar 29, 2016
00d110a
Addressing failing test
josenavas Mar 29, 2016
588f63c
Merge pull request #1716 from josenavas/artifact-study-pages-import-a…
antgonza Mar 29, 2016
8664d43
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 29, 2016
2d21661
adding code to tgz
antgonza Mar 29, 2016
684c503
fix #1132, fix #877, fix #16
antgonza Mar 29, 2016
2797a55
Adding safe_submit
josenavas Mar 29, 2016
5175cf7
Offloading sample template processing from the server
josenavas Mar 29, 2016
1057a5e
fixing error
antgonza Mar 30, 2016
3f08333
Offloading prep template update
josenavas Mar 30, 2016
a94d35f
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
josenavas Mar 30, 2016
eb34439
Fixing sample template tests
josenavas Mar 30, 2016
5906c98
Fixin prep template tests
josenavas Mar 30, 2016
f017c03
Adding qiita ware tests
josenavas Mar 30, 2016
ddd16ae
Fixing race condition errors
josenavas Mar 30, 2016
873624a
Addressing @antgonza's comments
josenavas Mar 30, 2016
0ce37cc
Adding missing comment
josenavas Mar 30, 2016
6d8674a
addressing @josenavas comments
antgonza Mar 30, 2016
249e402
initial commit
antgonza Mar 30, 2016
a630f33
fixing error
antgonza Mar 30, 2016
ace249a
addressing @ElDeveloper comments
antgonza Mar 30, 2016
6dcbd5b
fixing conflicts
antgonza Mar 30, 2016
5cc2d7a
Addressing @ElDeveloper's comments
josenavas Mar 30, 2016
0ea7c56
Merge pull request #1718 from antgonza/downlaod-tgz
josenavas Mar 30, 2016
2ca44cc
Merge pull request #1720 from josenavas/artifact-study-pages-offload-…
antgonza Mar 30, 2016
1ee4399
Merge branch 'artifact-study-pages' of https://github.com/biocore/qii…
antgonza Mar 30, 2016
df9e788
Merge pull request #1721 from antgonza/reducing-patches
josenavas Mar 30, 2016
0a38725
rm 40.py
antgonza Mar 30, 2016
26642f5
Merge pull request #1722 from antgonza/removing-40
josenavas Mar 30, 2016
5a23f64
Limit download of raw data
josenavas Mar 30, 2016
16dfc37
Removing directory form the list of files to download
josenavas Mar 30, 2016
b751301
Addressing @ElDeveloper's comments
josenavas Mar 31, 2016
ebfad82
Merge pull request #1725 from josenavas/download-raw-only-owner
antgonza Mar 31, 2016
2edca30
Disabling sorting and reducing font
josenavas Mar 31, 2016
486a63f
Merge pull request #1726 from josenavas/artifact-study-pages-summary
antgonza Mar 31, 2016
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
Prev Previous commit
Next Next commit
Offloading sample template processing from the server
  • Loading branch information
josenavas committed Mar 29, 2016
commit 5175cf7f302de5f193133995a3ee86e041404cc6
131 changes: 67 additions & 64 deletions qiita_pet/handlers/api_proxy/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
from __future__ import division
import warnings

from os import remove
from json import loads

from natsort import natsorted
from moi import r_client

from qiita_db.metadata_template.sample_template import SampleTemplate
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_db.study import Study
from qiita_core.util import execute_as_transaction
from qiita_db.metadata_template.util import (load_template_to_dataframe,
looks_like_qiime_mapping_file)
from qiita_db.metadata_template.util import looks_like_qiime_mapping_file
from qiita_db.exceptions import QiitaDBColumnError
from qiita_db.user import User

from qiita_ware.metadata_pipeline import (
create_templates_from_qiime_mapping_file)
from qiita_pet.util import convert_text_html
from qiita_ware.dispatchable import (
create_sample_template, update_sample_template, delete_sample_template)
from qiita_ware.context import safe_submit
from qiita_pet.handlers.api_proxy.util import check_access, check_fp

SAMPLE_TEMPLATE_KEY_FORMAT = 'sample_template_%s'


def _check_sample_template_exists(samp_id):
"""Make sure a sample template exists in the system
Expand Down Expand Up @@ -214,38 +214,64 @@ def sample_template_summary_get_req(samp_id, user_id):
Format {num_samples: value,
category: [(val1, count1), (val2, count2), ...], ...}
"""
exists = _check_sample_template_exists(int(samp_id))
if exists['status'] != 'success':
return exists
access_error = check_access(samp_id, user_id)
if access_error:
return access_error
try:
template = SampleTemplate(int(samp_id))
except QiitaDBUnknownIDError as e:
return {'status': 'error',
'message': str(e)}

job_id = r_client.get(SAMPLE_TEMPLATE_KEY_FORMAT % samp_id)
if job_id:
redis_info = loads(r_client.get(job_id))
processing = redis_info['status_msg'] == 'Running'
if processing:
alert_type = 'info'
alert_msg = 'This sample template is currently being processed'
else:
alert_type = redis_info['return']['status']
alert_msg = redis_info['return']['message']
else:
processing = False
alert_type = ''
alert_msg = ''
alert_msg = alert_msg.replace('\n', '</br>')

exists = _check_sample_template_exists(int(samp_id))
if exists['status'] != 'success':
return {'status': 'success',
'message': '',
'num_samples': 0,
'num_columns': 0,
'editable': not processing,
'alert_type': alert_type,
'alert_message': alert_msg,
'stats': {}}

template = SampleTemplate(int(samp_id))

df = template.to_dataframe()

editable = (Study(template.study_id).can_edit(User(user_id)) and not
processing)

out = {'status': 'success',
'message': '',
'num_samples': df.shape[0],
'num_columns': df.shape[1],
'editable': Study(template.study_id).can_edit(User(user_id)),
'summary': {}}
'editable': editable,
'alert_type': alert_type,
'alert_message': alert_msg,
'stats': {}}

# drop the samp_id column if it exists
if 'study_id' in df.columns:
df.drop('study_id', axis=1, inplace=True)
for column in df.columns:
counts = df[column].value_counts()
out['summary'][str(column)] = [(str(key), counts[key])
for key in natsorted(counts.index)]
out['stats'][str(column)] = [(str(key), counts[key])
for key in natsorted(counts.index)]

return out


@execute_as_transaction
def sample_template_post_req(study_id, user_id, data_type,
sample_template):
"""Creates the sample template from the given file
Expand Down Expand Up @@ -293,27 +319,13 @@ def sample_template_post_req(study_id, user_id, data_type,
'file': sample_template}

study = Study(int(study_id))
try:
with warnings.catch_warnings(record=True) as warns:
if is_mapping_file:
create_templates_from_qiime_mapping_file(fp_rsp, study,
data_type)
else:
SampleTemplate.create(load_template_to_dataframe(fp_rsp),
study)
remove(fp_rsp)

# join all the warning messages into one. Note that this
# info will be ignored if an exception is raised
if warns:
msg = '; '.join([convert_text_html(str(w.message))
for w in warns])
status = 'warning'
except Exception as e:
# Some error occurred while processing the sample template
# Show the error to the user so they can fix the template
status = 'error'
msg = str(e)

# Offload the creation of the sample template to the cluster
job_id = safe_submit(user_id, create_sample_template, fp_rsp, study,
is_mapping_file, data_type)
# Store the job id attaching it to the sample template id
r_client.set(SAMPLE_TEMPLATE_KEY_FORMAT % study.id, job_id)

return {'status': status,
'message': msg,
'file': sample_template}
Expand Down Expand Up @@ -358,23 +370,13 @@ def sample_template_put_req(study_id, user_id, sample_template):

msg = ''
status = 'success'
try:
with warnings.catch_warnings(record=True) as warns:
# deleting previous uploads and inserting new one
st = SampleTemplate(study_id)
df = load_template_to_dataframe(fp_rsp)
st.extend(df)
st.update(df)
remove(fp_rsp)

# join all the warning messages into one. Note that this info
# will be ignored if an exception is raised
if warns:
msg = '\n'.join(set(str(w.message) for w in warns))
status = 'warning'
except Exception as e:
status = 'error'
msg = str(e)

# Offload the update of the sample template to the cluster
job_id = safe_submit(user_id, update_sample_template, int(study_id),
fp_rsp)
# Store the job id attaching it to the sample template id
r_client.set(SAMPLE_TEMPLATE_KEY_FORMAT % study_id, job_id)

return {'status': status,
'message': msg,
'file': sample_template}
Expand Down Expand Up @@ -408,10 +410,11 @@ def sample_template_delete_req(study_id, user_id):
if access_error:
return access_error

try:
SampleTemplate.delete(int(study_id))
except Exception as e:
return {'status': 'error', 'message': str(e)}
# Offload the deletion of the sample template to the cluster
job_id = safe_submit(user_id, delete_sample_template, int(study_id))
# Store the job id attaching it to the sample template id
r_client.set(SAMPLE_TEMPLATE_KEY_FORMAT % study_id, job_id)

return {'status': 'success'}


Expand Down
20 changes: 12 additions & 8 deletions qiita_pet/handlers/study_handlers/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ def get(self):
if download['status'] == 'success' else None)

stats = sample_template_summary_get_req(study_id, self.current_user.id)
summary = stats['summary'] if 'summary' in stats else {}
num_samples = stats['num_samples'] if 'num_samples' in stats else 0
num_columns = stats['num_columns'] if 'num_columns' in stats else 0
editable = stats['editable'] if 'editable' in stats else True
self.render('study_ajax/sample_summary.html', stats=summary,
num_samples=num_samples, num_columns=num_columns,
download_id=download_id, files=files, study_id=study_id,
data_types=data_types, editable=editable)
if stats['status'] != 'success':
if 'does not exist' in stats['message']:
raise HTTPError(404, stats['message'])
if 'User does not have access to study' in stats['message']:
raise HTTPError(403, stats['message'])

stats['download_id'] = download_id
stats['files'] = files
stats['study_id'] = study_id
stats['data_types'] = data_types

self.render('study_ajax/sample_summary.html', **stats)

@authenticated
def post(self):
Expand Down
6 changes: 6 additions & 0 deletions qiita_pet/templates/study_ajax/sample_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
$('#file-btn').prop('disabled', false);
}
});

{% if alert_type != 'success' and alert_message != '' %}
bootstrapAlert("{% raw alert_message %}", "{{alert_type}}");
{% else %}
$('#bootstrap-alert').alert('close');
{% end %}
});
</script>

Expand Down
125 changes: 125 additions & 0 deletions qiita_ware/dispatchable.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,128 @@ def create_raw_data(filetype, prep_template, filepaths):
def copy_raw_data(prep_template, artifact_id):
"""Creates a new raw data by copying from artifact_id"""
Artifact.copy(Artifact(artifact_id), prep_template)


def create_sample_template(fp, study, is_mapping_file, data_type):
"""Creates a sample template

Parameters
----------
fp : str
The file path to the template file
study : qiita_db.study.Study
The study to add the sample template to
is_mapping_file : bool
Whether `fp` contains a mapping file or a sample template
data_type : str
If `is_mapping_file` is True, the data type of the prep template to be
created

Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
# The imports need to be in here because this code is executed in
# the ipython workers
import warnings
from os import remove
from qiita_db.metadata_template.sample_template import SampleTemplate
from qiita_db.metadata_template.util import load_template_to_dataframe
from qiita_ware.metadata_pipeline import (
create_templates_from_qiime_mapping_file)

status = 'success'
msg = ''
try:
with warnings.catch_warnings(record=True) as warns:
if is_mapping_file:
create_templates_from_qiime_mapping_file(fp, study,
data_type)
else:
SampleTemplate.create(load_template_to_dataframe(fp),
study)
remove(fp)

# join all the warning messages into one. Note that this
# info will be ignored if an exception is raised
if warns:
msg = '\n'.join(set(str(w.message) for w in warns))
status = 'warning'
except Exception as e:
# Some error occurred while processing the sample template
# Show the error to the user so they can fix the template
status = 'danger'
msg = str(e)

return {'status': status, 'message': msg}


def update_sample_template(study_id, fp):
"""Updates a sample template

Parameters
----------
study_id : int
Study id whose template is going to be updated
fp : str
The file path to the template file

Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
import warnings
from os import remove
from qiita_db.metadata_template.util import load_template_to_dataframe
from qiita_db.metadata_template.sample_template import SampleTemplate

msg = ''
status = 'success'

try:
with warnings.catch_warnings(record=True) as warns:
# deleting previous uploads and inserting new one
st = SampleTemplate(study_id)
df = load_template_to_dataframe(fp)
st.extend(df)
st.update(df)
remove(fp)

# join all the warning messages into one. Note that this info
# will be ignored if an exception is raised
if warns:
msg = '\n'.join(set(str(w.message) for w in warns))
status = 'warning'
except Exception as e:
status = 'danger'
msg = str(e)

return {'status': status, 'message': msg}


def delete_sample_template(study_id):
"""Delete a sample template

Parameters
----------
study_id : int
Study id whose template is going to be deleted

Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
from qiita_db.metadata_template.sample_template import SampleTemplate

msg = ''
status = 'success'
try:
SampleTemplate.delete(study_id)
except Exception as e:
status = 'danger'
msg = str(e)

return {'status': status, 'message': msg}