-
Couldn't load subscription status.
- Fork 79
Refactoring the refactor (I): Fix prep info creation #1679
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 9 commits
58f9acb
da0028e
851caca
cfa0b88
ed6907c
171f49a
8f3c699
decbce0
bc47b24
5166631
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 |
|---|---|---|
|
|
@@ -14,12 +14,45 @@ | |
| from qiita_core.util import execute_as_transaction | ||
| from qiita_pet.handlers.api_proxy.util import check_access, check_fp | ||
| from qiita_db.metadata_template.util import load_template_to_dataframe | ||
| from qiita_db.util import convert_to_id | ||
| from qiita_db.util import convert_to_id, get_files_from_uploads_folders | ||
| from qiita_db.study import Study | ||
| from qiita_db.ontology import Ontology | ||
| from qiita_db.metadata_template.prep_template import PrepTemplate | ||
|
|
||
|
|
||
| def new_prep_template_get_req(study_id): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| study_id : int | ||
| The study id | ||
|
|
||
| Returns | ||
| ------- | ||
| (list of str, list of str, dict of {str: list of str}) | ||
| The list of txt,csv files in the upload dir for the given study | ||
|
||
| The list of available data types | ||
| The investigation type ontology information | ||
| """ | ||
| prep_files = [f for _, f in get_files_from_uploads_folders(study_id) | ||
| if f.endswith(('txt', 'tsv'))] | ||
|
||
| data_types = sorted(Study.all_data_types()) | ||
|
|
||
| # Get all the ENA terms for the investigation type | ||
| ontology = Ontology(convert_to_id('ENA', 'ontology')) | ||
| ena_terms = sorted(ontology.terms) | ||
| # make "Other" last on the list | ||
| ena_terms.remove('Other') | ||
| ena_terms.append('Other') | ||
|
|
||
| ontology_info = {'ENA': ena_terms, | ||
| 'User': sorted(ontology.user_defined_terms)} | ||
| return {'status': 'success', | ||
| 'prep_files': prep_files, | ||
| 'data_types': data_types, | ||
| 'ontology': ontology_info} | ||
|
|
||
|
|
||
| @execute_as_transaction | ||
| def _process_investigation_type(inv_type, user_def_type, new_type): | ||
| """Return the investigation_type and add it to the ontology if needed | ||
|
|
@@ -197,11 +230,10 @@ def prep_template_post_req(study_id, user_id, prep_template, data_type, | |
| prep = None | ||
| try: | ||
| with warnings.catch_warnings(record=True) as warns: | ||
| data_type_id = convert_to_id(data_type, 'data_type') | ||
| # deleting previous uploads and inserting new one | ||
| prep = PrepTemplate.create(load_template_to_dataframe(fp_rpt), | ||
| Study(int(study_id)), int(data_type_id), | ||
| investigation_type=investigation_type) | ||
| prep = PrepTemplate.create( | ||
| load_template_to_dataframe(fp_rpt), Study(study_id), data_type, | ||
| investigation_type=investigation_type) | ||
| remove(fp_rpt) | ||
|
|
||
| # join all the warning messages into one. Note that this info | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # Copyright (c) 2014--, The Qiita Development Team. | ||
| # | ||
| # Distributed under the terms of the BSD 3-clause License. | ||
| # | ||
| # The full license is in the file LICENSE, distributed with this software. | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| from tornado.web import authenticated | ||
|
|
||
| from qiita_pet.handlers.base_handlers import BaseHandler | ||
| from qiita_pet.handlers.api_proxy import prep_template_post_req | ||
|
|
||
|
|
||
| class PrepTemplateHandler(BaseHandler): | ||
| @authenticated | ||
| def post(self): | ||
| """Creates a prep template""" | ||
| study_id = self.get_argument('study_id') | ||
| data_type = self.get_argument('data-type') | ||
| ena_ontology = self.get_argument('ena-ontology', None) | ||
| user_ontology = self.get_argument('user-ontology', None) | ||
| new_ontology = self.get_argument('new-ontology', None) | ||
| prep_fp = self.get_argument('prep-file') | ||
|
|
||
| response = prep_template_post_req( | ||
| study_id, self.get_current_user().id, prep_fp, data_type, | ||
| ena_ontology, user_ontology, new_ontology) | ||
|
|
||
| self.write(response) |
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.
Can you add a description to this function?
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.
Done