def test_format_mapping_html_data_non_location_error(self): """ Properly formats html string for mapping file errors/warnings """ header = ["SampleID", "BarcodeSequence", "LinkerPrimerSequence", "Description"] mapping_data = [["Sample1", "AACCGGTT", "ACATATT", "Desc_1"], ["Sample2", "CCAATTGG", "ACATATT", "Desc_2"]] errors = ["error1\t-1,-1"] warnings = [] # Should list errors with location -1,-1 outside of table actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_data_nonloc_error)
def test_format_mapping_html_data_warnings(self): """ Properly formats html string for mapping file errors/warnings """ header = ["SampleID", "BarcodeSequence", "LinkerPrimerSequence", "Description"] mapping_data = [["Sample1", "AACCGGTT", "ACATATT", "Desc_1"], ["Sample2", "CCAATTGG", "ACATATT", "Desc_2"]] errors = [] warnings = ["warning1\t2,2"] # Should create a an warning popup in the right location actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_warnings)
def test_format_mapping_html_data(self): """ Properly formats html string for mapping file errors/warnings """ header = ["SampleID", "BarcodeSequence", "LinkerPrimerSequence", "Description"] mapping_data = [["Sample1", "AACCGGTT", "ACATATT", "Desc_1"], ["Sample2", "CCAATTGG", "ACATATT", "Desc_2"]] errors = [] warnings = [] # no errors or warnings, shouldn't get any popup mouseover data actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_no_errors_warnings)
def test_format_mapping_html_data_errors(self): """ Properly formats html string for mapping file errors/warnings """ header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'Description'] mapping_data = [['Sample1','AACCGGTT','ACATATT','Desc_1'], ['Sample2','CCAATTGG','ACATATT','Desc_2'] ] errors = ['problem1\t1,2'] warnings = [] # Should create a an error popup in the right location actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_errors)
def test_format_mapping_html_data(self): """ Properly formats html string for mapping file errors/warnings """ header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'Description'] mapping_data = [['Sample1','AACCGGTT','ACATATT','Desc_1'], ['Sample2','CCAATTGG','ACATATT','Desc_2'] ] errors = [] warnings = [] # no errors or warnings, shouldn't get any popup mouseover data actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_no_errors_warnings)
def test_format_mapping_html_data_non_location_error(self): """ Properly formats html string for mapping file errors/warnings """ header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'Description'] mapping_data = [['Sample1', 'AACCGGTT', 'ACATATT', 'Desc_1'], ['Sample2', 'CCAATTGG', 'ACATATT', 'Desc_2'] ] errors = ['error1\t-1,-1'] warnings = [] # Should list errors with location -1,-1 outside of table actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_data_nonloc_error)
def test_format_mapping_html_data_warnings(self): """ Properly formats html string for mapping file errors/warnings """ header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'Description'] mapping_data = [['Sample1', 'AACCGGTT', 'ACATATT', 'Desc_1'], ['Sample2', 'CCAATTGG', 'ACATATT', 'Desc_2'] ] errors = [] warnings = ['warning1\t2,2'] # Should create a an warning popup in the right location actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_warnings)
def test_format_mapping_html_data(self): """ Properly formats html string for mapping file errors/warnings """ header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'Description'] mapping_data = [['Sample1', 'AACCGGTT', 'ACATATT', 'Desc_1'], ['Sample2', 'CCAATTGG', 'ACATATT', 'Desc_2'] ] errors = [] warnings = [] # no errors or warnings, shouldn't get any popup mouseover data actual_formatted_html_data = format_mapping_html_data(header, mapping_data, errors, warnings) self.assertEqual(actual_formatted_html_data, self.expected_formatted_html_no_errors_warnings)
def check_mapping_file(mapping_fp, output_dir=".", has_barcodes=True, char_replace="_", verbose=True, variable_len_barcodes=False, disable_primer_check=False, added_demultiplex_field=None, suppress_html=False): """ Main program function for checking mapping file Checks mapping file for errors, warnings, writes log file, html file, and corrected mapping file. mapping_fp: path to metadata mapping file output_dir: output directory for log, html, corrected mapping file. has_barcodes: If True, will test for perform barcodes test (presence, uniqueness, valid IUPAC DNA chars). char_replace: Character used to replace invalid characters in data fields. SampleIDs always use periods to be MIENS compliant. verbose: If True, a message about warnings and/or errors will be printed to stdout. variable_len_barcodes: If True, suppresses warnings about barcodes of varying length. disable_primer_check: If True, disables tests for valid primer sequences. added_demultiplex_field: If specified, references a field in the mapping file to use for demultiplexing. These are to be read from fasta labels during the actual demultiplexing step. All combinations of barcodes, primers, and the added_demultiplex_field must be unique.""" header, mapping_data, run_description, errors, warnings =\ process_id_map(open(mapping_fp, 'U'), disable_primer_check, has_barcodes, char_replace, variable_len_barcodes, added_demultiplex_field, strip_quotes=False, suppress_stripping=True) if not suppress_html: formatted_html = format_mapping_html_data(header, mapping_data, errors, warnings) output_html = join(output_dir + basename(mapping_fp).replace('.txt', '') + ".html") html_f = open(output_html, "w") html_f.write(formatted_html) # get QIIME directory qiime_dir = get_qiime_project_dir() # Write javascript file necessary for mouseover tooltips. # move javascript file to javascript output directory copyfile(join(qiime_dir, 'qiime', 'support_files', 'js/overlib.js'), join(output_dir, 'overlib.js')) corrected_mapping_data = correct_mapping_data(mapping_data, header, char_replace) output_corrected_fp = join(output_dir + basename(mapping_fp).replace('.txt', '') + "_corrected.txt") write_corrected_mapping(output_corrected_fp, header, run_description, corrected_mapping_data) output_log_fp = join(output_dir + basename(mapping_fp).replace('.txt', '') + ".log") write_log_file(output_log_fp, errors, warnings) if verbose: if errors or warnings: print "Errors and/or warnings detected in mapping file. Please " +\ "check the log and html file for details." else: print "No errors or warnings were found in mapping file."
def check_mapping_file(mapping_fp, output_dir=".", has_barcodes=True, char_replace="_", verbose=True, variable_len_barcodes=False, disable_primer_check=False, added_demultiplex_field=None): """ Main program function for checking mapping file Checks mapping file for errors, warnings, writes log file, html file, and corrected mapping file. mapping_fp: path to metadata mapping file output_dir: output directory for log, html, corrected mapping file. has_barcodes: If True, will test for perform barcodes test (presence, uniqueness, valid IUPAC DNA chars). char_replace: Character used to replace invalid characters in data fields. SampleIDs always use periods to be MIENS compliant. verbose: If True, a message about warnings and/or errors will be printed to stdout. variable_len_barcodes: If True, suppresses warnings about barcodes of varying length. disable_primer_check: If True, disables tests for valid primer sequences. added_demultiplex_field: If specified, references a field in the mapping file to use for demultiplexing. These are to be read from fasta labels during the actual demultiplexing step. All combinations of barcodes, primers, and the added_demultiplex_field must be unique.""" header, mapping_data, run_description, errors, warnings =\ process_id_map(open(mapping_fp, 'U'), disable_primer_check, has_barcodes, char_replace, variable_len_barcodes, added_demultiplex_field) formatted_html = format_mapping_html_data(header, mapping_data, errors, warnings) output_html = join(output_dir +\ basename(mapping_fp).replace('.txt', '') + ".html") html_f = open(output_html, "w") html_f.write(formatted_html) #get QIIME directory qiime_dir=get_qiime_project_dir() # Write javascript file necessary for mouseover tooltips. # move javascript file to javascript output directory copyfile(join(qiime_dir,'qiime','support_files',\ 'js/overlib.js'), join(output_dir,'overlib.js')) corrected_mapping_data = correct_mapping_data(mapping_data, header, char_replace) output_corrected_fp = join(output_dir +\ basename(mapping_fp).replace('.txt', '') + "_corrected.txt") write_corrected_mapping(output_corrected_fp, header, run_description, corrected_mapping_data) output_log_fp = join(output_dir +\ basename(mapping_fp).replace('.txt', '') + ".log") write_log_file(output_log_fp, errors, warnings) if verbose: if errors or warnings: print "Errors and/or warnings detected in mapping file. Please "+\ "check the log and html file for details." else: print "No errors or warnings were found in mapping file."