Skip to content

Commit

Permalink
Merge a6a3dd2 into f32864a
Browse files Browse the repository at this point in the history
  • Loading branch information
josenavas committed Jun 20, 2014
2 parents f32864a + a6a3dd2 commit ff3a9fc
Show file tree
Hide file tree
Showing 7 changed files with 1,983 additions and 1,682 deletions.
9 changes: 7 additions & 2 deletions qiita_db/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def load_raw_data_cmd(filepaths, filepath_types, filetype, study_ids):

def load_processed_data_cmd(fps, fp_types, processed_params_table_name,
processed_params_id, preprocessed_data_id=None,
processed_date=None):
study_id=None, processed_date=None):
"""Add a new processed data entry
Parameters
Expand Down Expand Up @@ -202,9 +202,14 @@ def load_processed_data_cmd(fps, fp_types, processed_params_table_name,
else:
preprocessed_data = None

if study_id is not None:
study = Study(study_id)
else:
study = 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)
preprocessed_data, study, processed_date)
28 changes: 27 additions & 1 deletion qiita_db/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,12 @@ class ProcessedData(BaseData):
_table = "processed_data"
_data_filepath_table = "processed_filepath"
_data_filepath_column = "processed_data_id"
_study_processed_table = "study_processed_data"
_preprocessed_processed_table = "preprocessed_processed_data"

@classmethod
def create(cls, processed_params_table, processed_params_id, filepaths,
preprocessed_data=None, processed_date=None):
preprocessed_data=None, study=None, processed_date=None):
r"""
Parameters
----------
Expand All @@ -414,14 +415,29 @@ def create(cls, processed_params_table, processed_params_id, filepaths,
identifier
preprocessed_data : PreprocessedData, optional
The PreprocessedData object used as base to this processed data
study : Study, optional
If preprocessed_data is not provided, the study the processed data
belongs to
processed_date : datetime, optional
Date in which the data have been processed. Default: now
Raises
------
IncompetentQiitaDeveloperError
If the table `processed_params_table` does not exists
If `preprocessed_data` and `study` are provided at the same time
If `preprocessed_data` and `study` are not provided
"""
if preprocessed_data is not None:
if study is not None:
raise IncompetentQiitaDeveloperError(
"You should provide either preprocessed_data or study, "
"but not both")
else:
if study is None:
raise IncompetentQiitaDeveloperError(
"You should provide either a preprocessed_data or a study")

conn_handler = SQLConnectionHandler()
# We first check that the processed_params_table exists
if not exists_dynamic_table(processed_params_table,
Expand Down Expand Up @@ -453,6 +469,16 @@ def create(cls, processed_params_table, processed_params_id, filepaths,
"processed_data_id) VALUES "
"(%s, %s)".format(cls._preprocessed_processed_table),
(preprocessed_data.id, pd_id))
study_id = preprocessed_data.study
else:
study_id = study.id

# Connect the processed data with the study
conn_handler.execute(
"INSERT INTO qiita.{0} (study_id, processed_data_id) VALUES "
"(%s, %s)".format(cls._study_processed_table),
(study_id, pd_id))

pd._add_filepaths(filepaths, conn_handler)
return cls(pd_id)

Expand Down
34 changes: 28 additions & 6 deletions qiita_db/support_files/qiita-db.dbs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,26 @@ Controlled Vocabulary]]></comment>
<fk_column name="preprocessed_data_id" pk="preprocessed_data_id" />
</fk>
</table>
<table name="study_processed_data" >
<column name="study_id" type="bigint" jt="-5" mandatory="y" />
<column name="processed_data_id" type="bigint" jt="-5" mandatory="y" />
<index name="idx_study_processed_data" unique="PRIMARY_KEY" >
<column name="study_id" />
<column name="processed_data_id" />
</index>
<index name="idx_study_processed_data_0" unique="NORMAL" >
<column name="study_id" />
</index>
<index name="pk_study_processed_data" unique="UNIQUE" >
<column name="processed_data_id" />
</index>
<fk name="fk_study_processed_data" to_schema="qiita" to_table="study" >
<fk_column name="study_id" pk="study_id" />
</fk>
<fk name="fk_study_processed_data_0" to_schema="qiita" to_table="processed_data" >
<fk_column name="processed_data_id" pk="processed_data_id" />
</fk>
</table>
<table name="study_raw_data" >
<comment>links study to its raw data</comment>
<column name="study_id" type="bigint" jt="-5" mandatory="y" />
Expand Down Expand Up @@ -1234,7 +1254,6 @@ Controlled Vocabulary]]></comment>
<entity schema="qiita" name="checksum_algorithm" color="b2cdf7" x="750" y="885" />
<entity schema="qiita" name="data_type" color="d0def5" x="690" y="1005" />
<entity schema="qiita" name="filepath" color="c0d4f3" x="660" y="675" />
<entity schema="qiita" name="processed_data" color="d0def5" x="1215" y="930" />
<entity schema="qiita" name="study_preprocessed_data" color="c0d4f3" x="1485" y="705" />
<entity schema="qiita" name="study" color="d0def5" x="1755" y="45" />
<entity schema="qiita" name="study_users" color="d0def5" x="1005" y="45" />
Expand All @@ -1250,18 +1269,20 @@ Controlled Vocabulary]]></comment>
<entity schema="qiita" name="raw_filepath" color="c0d4f3" x="1020" y="480" />
<entity schema="qiita" name="preprocessed_processed_data" color="b2cdf7" x="1215" y="825" />
<entity schema="qiita" name="study_raw_data" color="d0def5" x="1515" y="495" />
<entity schema="qiita" name="processed_params_uclust" color="d0def5" x="1395" y="930" />
<entity schema="qiita" name="reference" color="c0d4f3" x="1635" y="930" />
<entity schema="qiita" name="preprocessed_sequence_illumina_params" color="d0def5" x="1455" y="795" />
<entity schema="qiita" name="preprocessed_spectra_params" color="d0def5" x="1725" y="840" />
<entity schema="qiita" name="preprocessed_sequence_454_params" color="c0d4f3" x="1920" y="840" />
<entity schema="qiita" name="timeseries_type" color="c0d4f3" x="1620" y="600" />
<entity schema="qiita" name="portal_type" color="c0d4f3" x="1845" y="720" />
<entity schema="qiita" name="raw_data" color="d0def5" x="1230" y="480" />
<entity schema="qiita" name="raw_preprocessed_data" color="b2cdf7" x="1230" y="585" />
<entity schema="qiita" name="preprocessed_filepath" color="c0d4f3" x="990" y="705" />
<entity schema="qiita" name="preprocessed_data" color="c0d4f3" x="1200" y="690" />
<entity schema="qiita" name="processed_filepath" color="c0d4f3" x="1005" y="930" />
<entity schema="qiita" name="processed_params_uclust" color="d0def5" x="2025" y="795" />
<entity schema="qiita" name="reference" color="c0d4f3" x="2070" y="945" />
<entity schema="qiita" name="preprocessed_spectra_params" color="d0def5" x="1830" y="825" />
<entity schema="qiita" name="preprocessed_sequence_454_params" color="c0d4f3" x="1815" y="915" />
<entity schema="qiita" name="preprocessed_sequence_illumina_params" color="d0def5" x="1800" y="1005" />
<entity schema="qiita" name="processed_data" color="d0def5" x="1215" y="930" />
<entity schema="qiita" name="study_processed_data" color="b2cdf7" x="1455" y="930" />
<group name="Group_analyses" color="c4e0f9" >
<comment>analysis tables</comment>
<entity schema="qiita" name="analysis" />
Expand Down Expand Up @@ -1314,6 +1335,7 @@ Controlled Vocabulary]]></comment>
<entity schema="qiita" name="reference" />
<entity schema="qiita" name="raw_preprocessed_data" />
<entity schema="qiita" name="preprocessed_processed_data" />
<entity schema="qiita" name="study_processed_data" />
</group>
<group name="Group_vocabularies" color="00ffcc" >
<entity schema="qiita" name="controlled_vocabularies" />
Expand Down
Loading

0 comments on commit ff3a9fc

Please sign in to comment.