Skip to content

Commit df108b9

Browse files
committed
Adding check for missing QIIME mapping columns plus specially handle ReverseLinkerPrimer
1 parent d9b9bc4 commit df108b9

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

qiita_pet/handlers/study_handlers/description_handlers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def process_sample_template(self, study, user, callback):
179179
raise HTTPError(404, "This file doesn't exist: %s" % fp_rsp)
180180

181181
# Define here the message and message level in case of success
182+
msg = "The sample template '%s' has been added" % sample_template
183+
msg_level = "success"
182184
is_mapping_file = looks_like_qiime_mapping_file(fp_rsp)
183185

184186
try:

qiita_ware/metadata_pipeline.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
CONTROLLED_COLS,
1616
TARGET_GENE_DATA_TYPES)
1717
from qiita_db.util import convert_from_id
18+
from qiita_ware.exceptions import QiitaWareError
1819

1920

2021
def create_templates_from_qiime_mapping_file(fp, study, data_type):
@@ -41,9 +42,18 @@ def create_templates_from_qiime_mapping_file(fp, study, data_type):
4142
rename_cols = {
4243
'BarcodeSequence': 'barcode',
4344
'LinkerPrimerSequence': 'primer',
44-
'ReverseLinkerPrimer': 'reverselinkerprimer',
4545
'Description': 'description',
4646
}
47+
48+
if 'ReverseLinkerPrimer' in qiime_map:
49+
rename_cols['ReverseLinkerPrimer'] = 'reverselinkerprimer'
50+
51+
missing = set(rename_cols).difference(qiime_map.columns)
52+
if missing:
53+
raise QiitaWareError(
54+
"Error generating the templates from the QIIME mapping file. "
55+
"Missing QIIME mapping file columns: %s" % ', '.join(missing))
56+
4757
qiime_map.rename(columns=rename_cols, inplace=True)
4858

4959
# Fix the casing in the columns that we control
@@ -64,6 +74,7 @@ def _col_iterator(restriction_set):
6474
if data_type_str in TARGET_GENE_DATA_TYPES:
6575
pt_cols.update(
6676
col for col in _col_iterator(PREP_TEMPLATE_COLUMNS_TARGET_GENE))
77+
pt_cols.add('reverselinkerprimer')
6778

6879
qiime_cols = set(qiime_map.columns)
6980
pt_cols = qiime_cols.intersection(pt_cols)

qiita_ware/test/test_metadata_pipeline.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from os.path import exists
1313

1414
from qiita_core.util import qiita_test_checker
15+
from qiita_ware.exceptions import QiitaWareError
1516
from qiita_db.study import Study, StudyPerson
1617
from qiita_db.user import User
1718
from 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

76108
QIIME_MAP = (
77109
"#SampleID\tBarcodeSequence\tLinkerPrimerSequence\t"
@@ -90,6 +122,39 @@ def test_create_templates_from_qiime_mapping_file(self):
90122
"NotIdentified\t4.3\t4.3\t9606\thomo sapiens\tANL\trp_2\tILLUMINA\t"
91123
"protocol_1\tedd_1\t05/28/15 11:00\tDescription S3\n")
92124

125+
QIIME_MAP_WITH_REVERSE_LINKER_PRIMER = (
126+
"#SampleID\tBarcodeSequence\tLinkerPrimerSequence\tReverseLinkerPrimer\t"
127+
"physical_specimen_location\tphysical_specimen_remaining\tdna_extracted\t"
128+
"sample_type\thost_subject_id\tlatitude\tlongitude\ttaxon_id\t"
129+
"scientific_name\tcenter_name\trun_prefix\tplatform\t"
130+
"library_construction_protocol\texperiment_design_description\t"
131+
"collection_timestamp\tDescription\n"
132+
"Sample1\tGTCCGCAAGTTA\tGTGCCAGCMGCCGCGGTAA\tGTGCCAGCMGCCGCGGTAA\tUCSD\t"
133+
"TRUE\tTRUE\ttype1\tNotIdentified\t4.1\t4.1\t9606\thomo sapiens\tANL\t"
134+
"rp_1\tILLUMINA\tprotocol_1\tedd_1\t05/28/15 11:00\tDescription S1\n"
135+
"Sample2\tCGTAGAGCTCTC\tGTGCCAGCMGCCGCGGTAA\tGTGCCAGCMGCCGCGGTAA\tUCSD\t"
136+
"TRUE\tTRUE\ttype2\tNotIdentified\t4.2\t4.2\t9606\thomo sapiens\tANL\t"
137+
"rp_1\tILLUMINA\tprotocol_1\tedd_1\t05/28/15 11:00\tDescription S2\n"
138+
"Sample3\tCCTCTGAGAGCT\tGTGCCAGCMGCCGCGGTAA\tGTGCCAGCMGCCGCGGTAA\tUCSD\t"
139+
"TRUE\tTRUE\ttype3\tNotIdentified\t4.3\t4.3\t9606\thomo sapiens\tANL\t"
140+
"rp_2\tILLUMINA\tprotocol_1\tedd_1\t05/28/15 11:00\tDescription S3\n")
141+
142+
QIIME_MAP_ERROR = (
143+
"#SampleID\tBarcodeSequence\tphysical_specimen_location\t"
144+
"physical_specimen_remaining\tdna_extracted\tsample_type\t"
145+
"host_subject_id\tlatitude\tlongitude\ttaxon_id\tscientific_name\t"
146+
"center_name\trun_prefix\tplatform\tlibrary_construction_protocol\t"
147+
"experiment_design_description\tcollection_timestamp\tDescription\n"
148+
"Sample1\tGTCCGCAAGTTA\tUCSD\tTRUE\tTRUE\ttype1\tNotIdentified\t4.1\t4.1\t"
149+
"9606\thomo sapiens\tANL\trp_1\tILLUMINA\tprotocol_1\tedd_1\t"
150+
"05/28/15 11:00\tDescription S1\n"
151+
"Sample2\tCGTAGAGCTCTC\tUCSD\tTRUE\tTRUE\ttype2\tNotIdentified\t4.2\t4.2\t"
152+
"9606\thomo sapiens\tANL\trp_1\tILLUMINA\tprotocol_1\tedd_1\t"
153+
"05/28/15 11:00\tDescription S2\n"
154+
"Sample3\tCCTCTGAGAGCT\tUCSD\tTRUE\tTRUE\ttype3\tNotIdentified\t4.3\t4.3\t"
155+
"9606\thomo sapiens\tANL\trp_2\tILLUMINA\tprotocol_1\tedd_1\t"
156+
"05/28/15 11:00\tDescription S3\n")
157+
93158

94159
if __name__ == "__main__":
95160
main()

0 commit comments

Comments
 (0)