-
Couldn't load subscription status.
- Fork 79
Refactoring the refactor (II): Add artifact creation page #1680
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
Changes from all commits
de47dfc
983449e
6d2d58e
12003b9
8297ebe
e43c9b8
e079cc7
8f746e3
fd43d3e
86cd64a
0fc34de
ee5edb9
47598a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ | |
| from __future__ import division | ||
|
|
||
| from qiita_db.study import Study | ||
| from qiita_db.metadata_template.prep_template import PrepTemplate | ||
| from qiita_db.util import (supported_filepath_types, | ||
| get_files_from_uploads_folders) | ||
| from qiita_pet.handlers.api_proxy.util import check_access | ||
|
|
||
|
|
||
|
|
@@ -168,3 +171,72 @@ def study_prep_get_req(study_id, user_id): | |
| return {'status': 'success', | ||
| 'message': '', | ||
| 'info': prep_info} | ||
|
|
||
|
|
||
| def study_files_get_req(study_id, prep_template_id, artifact_type): | ||
| """Returns the uploaded files for the study id categorized by artifact_type | ||
|
|
||
| It retrieves the files uploaded for the given study and tries to do a | ||
| guess on how those files should be added to the artifact of the given | ||
| type. Uses information on the prep template to try to do a better guess. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| study_id : int | ||
| The study id | ||
| prep_template_id : int | ||
| The prep template id | ||
| artifact_type : str | ||
| The artifact type | ||
|
|
||
| Returns | ||
| ------- | ||
| dict of {str: object} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {str: object} doesn't really match the below description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The returned dictionary is keyed by strings, but the values to those keys can be either strings, int, or lists. In order to englobe all these types in the type description, I used the common base class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about: "see below"? No hard feelings so fine to leave it as is. |
||
| A dict of the form {'status': str, | ||
| 'message': str, | ||
| 'remaining': list of str, | ||
| 'file_types': list of (str, bool, list of str), | ||
| 'num_prefixes': int} | ||
| where 'status' is a string specifying whether the query is successfull, | ||
| 'message' is a human-readable description of the error (optional), | ||
| 'remaining' is the list of files that could not be categorized, | ||
| 'file_types' is a list of the available filetypes, if it is required | ||
| or not and the list of categorized files for the given artifact type | ||
| and 'num_prefixes' is the number of different run prefix values in | ||
| the given prep template. | ||
| """ | ||
| supp_file_types = supported_filepath_types(artifact_type) | ||
| selected = [] | ||
| remaining = [] | ||
|
|
||
| uploaded = get_files_from_uploads_folders(study_id) | ||
| pt = PrepTemplate(prep_template_id).to_dataframe() | ||
|
|
||
| if (any(ft.startswith('raw_') for ft, _ in supp_file_types) and | ||
| 'run_prefix' in pt.columns): | ||
| prep_prefixes = tuple(set(pt['run_prefix'])) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pandas is ~2X slower so leaving as it is: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 ⏳ |
||
| num_prefixes = len(prep_prefixes) | ||
| for _, filename in uploaded: | ||
| if filename.startswith(prep_prefixes): | ||
| selected.append(filename) | ||
| else: | ||
| remaining.append(filename) | ||
| else: | ||
| num_prefixes = 0 | ||
| remaining = [f for _, f in uploaded] | ||
|
|
||
| # At this point we can't do anything smart about selecting by default | ||
| # the files for each type. The only thing that we can do is assume that | ||
| # the first in the supp_file_types list is the default one where files | ||
| # should be added in case of 'run_prefix' being present | ||
| file_types = [(fp_type, req, []) for fp_type, req in supp_file_types[1:]] | ||
| first = supp_file_types[0] | ||
| # Note that this works even if `run_prefix` is not in the prep template | ||
| # because selected is initialized to the empty list | ||
| file_types.insert(0, (first[0], first[1], selected)) | ||
|
|
||
| return {'status': 'success', | ||
| 'message': '', | ||
| 'remaining': remaining, | ||
| 'file_types': file_types, | ||
| 'num_prefixes': num_prefixes} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the description here, very useful. Just to check, there's no possible way to get commas in these filenames right? I'm wondering if what we should be getting should be a JSON object, but that I guess gets more in the topic of the REST API etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The serialization of that object happens in the HTML serialization of the form. I'm unsure why javascript (or HTML) is not serializing that list as a JSON object and self.argument is not unwrapping it like that, but that is why I'm receiving in the handler. Agree that we should totally revisit for a REST API