@@ -642,10 +642,11 @@ def data_types(self):
642642 list of str
643643 """
644644 conn_handler = SQLConnectionHandler ()
645- sql = ("SELECT DISTINCT DT.data_type FROM qiita.study_raw_data SRD "
646- "JOIN qiita.prep_template PT ON SRD.raw_data_id = "
647- "PT.raw_data_id JOIN qiita.data_type DT ON PT.data_type_id = "
648- "DT.data_type_id WHERE SRD.study_id = %s" )
645+ sql = """SELECT DISTINCT data_type
646+ FROM qiita.study_prep_template
647+ JOIN qiita.prep_template USING (prep_template_id)
648+ JOIN qiita.data_type USING (data_type_id)
649+ WHERE study_id = %s"""
649650 return [x [0 ] for x in conn_handler .execute_fetchall (sql , (self ._id ,))]
650651
651652 @property
@@ -759,36 +760,30 @@ def raw_data(self, data_type=None):
759760
760761 return [x [0 ] for x in conn_handler .execute_fetchall (sql , (self ._id ,))]
761762
762- def add_raw_data (self , raw_data ):
763- """ Adds raw_data to the current study
763+ def prep_templates (self , data_type = None ):
764+ """Return list of prep template ids
764765
765766 Parameters
766767 ----------
767- raw_data : list of RawData
768- The RawData objects to be added to the study
768+ data_type : str, optional
769+ If given, retrieve only prep templates for given datatype.
770+ Default None.
769771
770- Raises
771- ------
772- QiitaDBError
773- If the raw_data is already linked to the current study
772+ Returns
773+ -------
774+ list of PrepTemplate ids
774775 """
775- conn_handler = SQLConnectionHandler ()
776- self ._lock_non_sandbox (conn_handler )
777- queue = "%d_add_raw_data" % self .id
778- sql = ("SELECT EXISTS(SELECT * FROM qiita.study_raw_data WHERE "
779- "study_id=%s AND raw_data_id=%s)" )
780- conn_handler .create_queue (queue )
781- sql_args = [(self .id , rd .id ) for rd in raw_data ]
782- conn_handler .add_to_queue (queue , sql , sql_args , many = True )
783- linked = conn_handler .execute_queue (queue )
784-
785- if any (linked ):
786- raise QiitaDBError ("Some of the passed raw datas have been already"
787- " linked to the study %s" % self .id )
776+ spec_data = ""
777+ if data_type :
778+ spec_data = " AND data_type_id = %s" % convert_to_id (data_type ,
779+ "data_type" )
788780
789- conn_handler .executemany (
790- "INSERT INTO qiita.study_raw_data (study_id, raw_data_id) "
791- "VALUES (%s, %s)" , sql_args )
781+ conn_handler = SQLConnectionHandler ()
782+ sql = """SELECT prep_template_id
783+ FROM qiita.study_prep_template
784+ JOIN qiita.prep_template USING (prep_template_id)
785+ WHERE study_id = %s{0}""" .format (spec_data )
786+ return [x [0 ] for x in conn_handler .execute_fetchall (sql , (self ._id ,))]
792787
793788 def preprocessed_data (self , data_type = None ):
794789 """ Returns list of data ids for preprocessed data info
0 commit comments