diff --git a/qiita_db/commands.py b/qiita_db/commands.py index a9a6906e3..1526ce332 100644 --- a/qiita_db/commands.py +++ b/qiita_db/commands.py @@ -6,6 +6,7 @@ # The full license is in the file LICENSE, distributed with this software. # ----------------------------------------------------------------------------- +from dateutil.parser import parse import pandas as pd from functools import partial try: @@ -18,7 +19,7 @@ from .study import Study, StudyPerson from .user import User from .util import get_filetypes, get_filepath_types -from .data import RawData +from .data import RawData, PreprocessedData, ProcessedData from .metadata_template import SampleTemplate @@ -108,3 +109,50 @@ def load_raw_data_cmd(filepaths, filepath_types, filetype, study_ids): return RawData.create(filetype_id, list(zip(filepaths, filepath_types)), studies) + + +def load_processed_data_cmd(fps, fp_types, processed_params_table_name, + processed_params_id, preprocessed_data_id=None, + processed_date=None): + """Add a new processed data entry + + Parameters + ---------- + fps : list of str + Paths to the processed data files to associate with the ProcessedData + object + fp_types: list of str + The types of files, one per fp + processed_params_table_name : str + The name of the processed_params_ table to use + processed_params_id : int + The ID of the row in the processed_params_ table + preprocessed_data_id : int, optional + Defaults to ``None``. The ID of the row in the preprocessed_data table. + processed_date : str, optional + Defaults to ``None``. The date and time to use as the processing date. + Must be interpretable as a datetime object + + Returns + ------- + qiita_db.ProcessedData + The newly created `qiita_db.ProcessedData` object + """ + if len(fps) != len(fp_types): + raise ValueError("Please pass exactly one fp_type for each " + "and every fp") + + fp_types_dict = get_filepath_types() + fp_types = [fp_types_dict[x] for x in fp_types] + + if preprocessed_data_id is not None: + preprocessed_data = PreprocessedData(preprocessed_data_id) + else: + preprocessed_data = None + + if processed_date is not None: + processed_date = parse(processed_date) + + return ProcessedData.create(processed_params_table_name, + processed_params_id, list(zip(fps, fp_types)), + preprocessed_data, processed_date) diff --git a/qiita_db/support_files/qiita-db.dbs b/qiita_db/support_files/qiita-db.dbs index a0bbac529..2c16de96c 100644 --- a/qiita_db/support_files/qiita-db.dbs +++ b/qiita_db/support_files/qiita-db.dbs @@ -635,10 +635,8 @@ Linked by y being raw_data_id from raw data table.