@@ -103,7 +103,7 @@ class BaseData(QiitaObject):
103
103
--------
104
104
RawData
105
105
PreprocessedData
106
- PreprocessedData
106
+ ProcessedData
107
107
"""
108
108
_filepath_table = "filepath"
109
109
@@ -807,6 +807,72 @@ def create(cls, study, preprocessed_params_table, preprocessed_params_id,
807
807
ppd .add_filepaths (filepaths , conn_handler )
808
808
return ppd
809
809
810
+ @classmethod
811
+ def delete (cls , ppd_id ):
812
+ """Removes the preprocessed data with id ppd_id
813
+
814
+ Parameters
815
+ ----------
816
+ ppd_id : int
817
+ The preprocessed data id
818
+
819
+ Raises
820
+ ------
821
+ QiitaDBStatusError
822
+ If the preprocessed data status is not sandbox or if the
823
+ preprocessed data EBI and VAMPS submission is not in a valid state
824
+ ['not submitted', 'failed']
825
+ QiitaDBError
826
+ If the preprocessed data has (meta)analyses
827
+ """
828
+ valid_submission_states = ['not submitted' , 'failed' ]
829
+ ppd = cls (ppd_id )
830
+ if ppd .status != 'sandbox' :
831
+ raise QiitaDBStatusError (
832
+ "Illegal operation on non sandbox preprocessed data" )
833
+ elif (ppd .submitted_to_vamps_status () not in valid_submission_states or
834
+ ppd .submitted_to_insdc_status () not in valid_submission_states ):
835
+ raise QiitaDBStatusError (
836
+ "Illegal operation due to EBI submission status ('%s') or "
837
+ "VAMPS submission status ('%s')" % (
838
+ ppd .submitted_to_insdc_status (),
839
+ ppd .submitted_to_vamps_status ()))
840
+
841
+ conn_handler = SQLConnectionHandler ()
842
+
843
+ processed_data = [str (n [0 ]) for n in conn_handler .execute_fetchall (
844
+ "SELECT processed_data_id FROM qiita.preprocessed_processed_data "
845
+ "WHERE preprocessed_data_id = {0} ORDER BY "
846
+ "processed_data_id" .format (ppd_id ))]
847
+
848
+ if processed_data :
849
+ raise QiitaDBError (
850
+ "Preprocessed data %d cannot be removed because it was used "
851
+ "to generate the following processed data: %s" % (
852
+ ppd_id , ', ' .join (processed_data )))
853
+
854
+ # delete
855
+ queue = "delete_preprocessed_data_%d" % ppd_id
856
+ conn_handler .create_queue (queue )
857
+
858
+ sql = ("DELETE FROM qiita.prep_template_preprocessed_data WHERE "
859
+ "preprocessed_data_id = {0}" .format (ppd_id ))
860
+ conn_handler .add_to_queue (queue , sql )
861
+
862
+ sql = ("DELETE FROM qiita.preprocessed_filepath WHERE "
863
+ "preprocessed_data_id = {0}" .format (ppd_id ))
864
+ conn_handler .add_to_queue (queue , sql )
865
+
866
+ sql = ("DELETE FROM qiita.study_preprocessed_data WHERE "
867
+ "preprocessed_data_id = {0}" .format (ppd_id ))
868
+ conn_handler .add_to_queue (queue , sql )
869
+
870
+ sql = ("DELETE FROM qiita.preprocessed_data WHERE "
871
+ "preprocessed_data_id = {0}" .format (ppd_id ))
872
+ conn_handler .add_to_queue (queue , sql )
873
+
874
+ conn_handler .execute_queue (queue )
875
+
810
876
@property
811
877
def processed_data (self ):
812
878
r"""The processed data list generated from this preprocessed data"""
0 commit comments