1515from future import standard_library
1616from functools import partial
1717
18+ import pandas as pd
19+
1820from qiita_db .commands import (load_study_from_cmd , load_raw_data_cmd ,
1921 load_sample_template_from_cmd ,
2022 load_prep_template_from_cmd ,
2527from qiita_db .environment_manager import patch
2628from qiita_db .study import Study , StudyPerson
2729from qiita_db .user import User
28- from qiita_db .data import RawData , PreprocessedData
30+ from qiita_db .data import PreprocessedData
2931from qiita_db .util import (get_count , check_count , get_db_files_base_dir ,
3032 get_mountpoint )
33+ from qiita_db .metadata_template import PrepTemplate
3134from qiita_core .util import qiita_test_checker
3235from qiita_ware .processing_pipeline import generate_demux_file
3336
@@ -154,36 +157,12 @@ def test_load_sample_template_from_cmd(self):
154157@qiita_test_checker ()
155158class TestLoadPrepTemplateFromCmd (TestCase ):
156159 def setUp (self ):
157- # Create a sample template file
158- fd , seqs_fp = mkstemp (suffix = '_seqs.fastq' )
159- close (fd )
160- fd , barcodes_fp = mkstemp (suffix = '_barcodes.fastq' )
161- close (fd )
162-
163- with open (seqs_fp , "w" ) as f :
164- f .write ("\n " )
165- with open (barcodes_fp , "w" ) as f :
166- f .write ("\n " )
167-
168160 self .pt_contents = PREP_TEMPLATE
169161
170- self .raw_data = RawData .create (
171- 2 , [Study (1 )], filepaths = [(seqs_fp , 1 ), (barcodes_fp , 2 )])
172-
173- join_f = partial (join , join (get_db_files_base_dir (), 'raw_data' ))
174- self .files_to_remove = [
175- join_f ("%s_%s" % (self .raw_data .id , basename (seqs_fp ))),
176- join_f ("%s_%s" % (self .raw_data .id , basename (barcodes_fp )))]
177-
178- def tearDown (self ):
179- for fp in self .files_to_remove :
180- if exists (fp ):
181- remove (fp )
182-
183162 def test_load_prep_template_from_cmd (self ):
184163 """Correctly adds a prep template to the DB"""
185164 fh = StringIO (self .pt_contents )
186- st = load_prep_template_from_cmd (fh , self . raw_data . id , 1 , '18S' )
165+ st = load_prep_template_from_cmd (fh , 1 , '18S' )
187166 self .assertEqual (st .id , 2 )
188167
189168
@@ -222,14 +201,24 @@ def test_load_data_from_cmd(self):
222201 'raw_barcodes' ]
223202
224203 filetype = 'FASTQ'
225- study_ids = [1 ]
204+ metadata_dict = {
205+ 'SKB8.640193' : {'center_name' : 'ANL' ,
206+ 'primer' : 'GTGCCAGCMGCCGCGGTAA' ,
207+ 'barcode' : 'GTCCGCAAGTTA' ,
208+ 'run_prefix' : "s_G1_L001_sequences" ,
209+ 'platform' : 'ILLUMINA' ,
210+ 'library_construction_protocol' : 'AAAA' ,
211+ 'experiment_design_description' : 'BBBB' }}
212+ metadata = pd .DataFrame .from_dict (metadata_dict , orient = 'index' )
213+ pt1 = PrepTemplate .create (metadata , Study (1 ), "16S" )
214+ prep_templates = [pt1 .id ]
226215
227216 initial_raw_count = get_count ('qiita.raw_data' )
228217 initial_fp_count = get_count ('qiita.filepath' )
229218 initial_raw_fp_count = get_count ('qiita.raw_filepath' )
230219
231220 new = load_raw_data_cmd (filepaths , filepath_types , filetype ,
232- study_ids )
221+ prep_templates )
233222 raw_data_id = new .id
234223 self .files_to_remove .append (
235224 join (self .db_test_raw_dir ,
@@ -246,14 +235,12 @@ def test_load_data_from_cmd(self):
246235 initial_fp_count + 3 ))
247236 self .assertTrue (check_count ('qiita.raw_filepath' ,
248237 initial_raw_fp_count + 3 ))
249- self .assertTrue (check_count ('qiita.study_raw_data' ,
250- initial_raw_count + 1 ))
251238
252239 # Ensure that the ValueError is raised when a filepath_type is not
253240 # provided for each and every filepath
254241 with self .assertRaises (ValueError ):
255242 load_raw_data_cmd (filepaths , filepath_types [:- 1 ], filetype ,
256- study_ids )
243+ prep_templates )
257244
258245
259246@qiita_test_checker ()
0 commit comments