1212from os .path import exists
1313
1414from qiita_core .util import qiita_test_checker
15+ from qiita_ware .exceptions import QiitaWareError
1516from qiita_db .study import Study , StudyPerson
1617from qiita_db .user import User
1718from qiita_db .util import get_count
@@ -72,6 +73,37 @@ def test_create_templates_from_qiime_mapping_file(self):
7273 "experiment_design_description" }
7374 self .assertEqual (set (obs_pt .categories ()), exp )
7475
76+ def test_create_templates_from_qiime_mapping_file_reverse_linker (self ):
77+ new_pt_id = get_count ('qiita.prep_template' ) + 1
78+ obs_st , obs_pt = create_templates_from_qiime_mapping_file (
79+ StringIO (QIIME_MAP_WITH_REVERSE_LINKER_PRIMER ),
80+ self .new_study , "16S" )
81+
82+ # Be green: clean the environment
83+ for template in [obs_st , obs_pt ]:
84+ for _ , fp in template .get_filepaths ():
85+ self ._clean_up_files .append (fp )
86+
87+ self .assertEqual (obs_st .id , self .new_study .id )
88+ self .assertEqual (obs_pt .id , new_pt_id )
89+
90+ # Check that each template has the correct columns
91+ exp = {"physical_specimen_location" , "physical_specimen_remaining" ,
92+ "dna_extracted" , "sample_type" , "host_subject_id" , "latitude" ,
93+ "longitude" , "taxon_id" , "scientific_name" ,
94+ "collection_timestamp" , "description" }
95+ self .assertEqual (set (obs_st .categories ()), exp )
96+
97+ exp = {"barcode" , "primer" , "center_name" , "run_prefix" , "platform" ,
98+ "library_construction_protocol" ,
99+ "experiment_design_description" , "reverselinkerprimer" }
100+ self .assertEqual (set (obs_pt .categories ()), exp )
101+
102+ def test_create_templates_from_qiime_mapping_file_error (self ):
103+ with self .assertRaises (QiitaWareError ):
104+ create_templates_from_qiime_mapping_file (
105+ StringIO (QIIME_MAP_ERROR ), self .new_study , "16S" )
106+
75107
76108QIIME_MAP = (
77109 "#SampleID\t BarcodeSequence\t LinkerPrimerSequence\t "
@@ -90,6 +122,39 @@ def test_create_templates_from_qiime_mapping_file(self):
90122 "NotIdentified\t 4.3\t 4.3\t 9606\t homo sapiens\t ANL\t rp_2\t ILLUMINA\t "
91123 "protocol_1\t edd_1\t 05/28/15 11:00\t Description S3\n " )
92124
125+ QIIME_MAP_WITH_REVERSE_LINKER_PRIMER = (
126+ "#SampleID\t BarcodeSequence\t LinkerPrimerSequence\t ReverseLinkerPrimer\t "
127+ "physical_specimen_location\t physical_specimen_remaining\t dna_extracted\t "
128+ "sample_type\t host_subject_id\t latitude\t longitude\t taxon_id\t "
129+ "scientific_name\t center_name\t run_prefix\t platform\t "
130+ "library_construction_protocol\t experiment_design_description\t "
131+ "collection_timestamp\t Description\n "
132+ "Sample1\t GTCCGCAAGTTA\t GTGCCAGCMGCCGCGGTAA\t GTGCCAGCMGCCGCGGTAA\t UCSD\t "
133+ "TRUE\t TRUE\t type1\t NotIdentified\t 4.1\t 4.1\t 9606\t homo sapiens\t ANL\t "
134+ "rp_1\t ILLUMINA\t protocol_1\t edd_1\t 05/28/15 11:00\t Description S1\n "
135+ "Sample2\t CGTAGAGCTCTC\t GTGCCAGCMGCCGCGGTAA\t GTGCCAGCMGCCGCGGTAA\t UCSD\t "
136+ "TRUE\t TRUE\t type2\t NotIdentified\t 4.2\t 4.2\t 9606\t homo sapiens\t ANL\t "
137+ "rp_1\t ILLUMINA\t protocol_1\t edd_1\t 05/28/15 11:00\t Description S2\n "
138+ "Sample3\t CCTCTGAGAGCT\t GTGCCAGCMGCCGCGGTAA\t GTGCCAGCMGCCGCGGTAA\t UCSD\t "
139+ "TRUE\t TRUE\t type3\t NotIdentified\t 4.3\t 4.3\t 9606\t homo sapiens\t ANL\t "
140+ "rp_2\t ILLUMINA\t protocol_1\t edd_1\t 05/28/15 11:00\t Description S3\n " )
141+
142+ QIIME_MAP_ERROR = (
143+ "#SampleID\t BarcodeSequence\t physical_specimen_location\t "
144+ "physical_specimen_remaining\t dna_extracted\t sample_type\t "
145+ "host_subject_id\t latitude\t longitude\t taxon_id\t scientific_name\t "
146+ "center_name\t run_prefix\t platform\t library_construction_protocol\t "
147+ "experiment_design_description\t collection_timestamp\t Description\n "
148+ "Sample1\t GTCCGCAAGTTA\t UCSD\t TRUE\t TRUE\t type1\t NotIdentified\t 4.1\t 4.1\t "
149+ "9606\t homo sapiens\t ANL\t rp_1\t ILLUMINA\t protocol_1\t edd_1\t "
150+ "05/28/15 11:00\t Description S1\n "
151+ "Sample2\t CGTAGAGCTCTC\t UCSD\t TRUE\t TRUE\t type2\t NotIdentified\t 4.2\t 4.2\t "
152+ "9606\t homo sapiens\t ANL\t rp_1\t ILLUMINA\t protocol_1\t edd_1\t "
153+ "05/28/15 11:00\t Description S2\n "
154+ "Sample3\t CCTCTGAGAGCT\t UCSD\t TRUE\t TRUE\t type3\t NotIdentified\t 4.3\t 4.3\t "
155+ "9606\t homo sapiens\t ANL\t rp_2\t ILLUMINA\t protocol_1\t edd_1\t "
156+ "05/28/15 11:00\t Description S3\n " )
157+
93158
94159if __name__ == "__main__" :
95160 main ()
0 commit comments