def test_get_length_annotation_multiple_annotations(self): """ Test the get_length_annotation function from an id with multiple annotations """ annotated_id = "UniRef50_ABC|A|C|100" expected_result = ("UniRef50_ABC|A|C", 100) result = utilities.get_length_annotation(annotated_id) self.assertEqual(result[0], expected_result[0]) self.assertEqual(result[1], expected_result[1])
def test_get_length_annotation(self): """ Test the get_length_annotation function """ annotated_id = "UniRef50_ABC|100" expected_result = ("UniRef50_ABC", 100) result = utilities.get_length_annotation(annotated_id) self.assertEqual(result[0], expected_result[0]) self.assertEqual(result[1], expected_result[1])
def test_get_length_annotation_non_int_length(self): """ Test the get_length_annotation function from an id without an int length """ annotated_id = "UniRef50_ABC|A" expected_result = ("UniRef50_ABC|A", 1) result = utilities.get_length_annotation(annotated_id) self.assertEqual(result[0], expected_result[0]) self.assertEqual(result[1], expected_result[1])
def test_translated_search_unaligned_reads_blastm8_coverage_filter(self): """ Test the unaligned reads and the store alignments Test with a blastm8-like output file Test with empty reads structure Test that function does not require gene lengths in reference id Test with the coverage filter Test with query length annotations Test that an alignment with query start larger than query end is not filtered """ # create a set of alignments alignments = store.Alignments() # set the coverage threshold to a small value so as to have some alignments pass current_coverage_threshold = config.translated_subject_coverage_threshold config.translated_subject_coverage_threshold = 0.50 # get the set of allowed proteins allowed_proteins = blastx_coverage.blastx_coverage( cfg.rapsearch2_output_file_without_header_coverage, config.translated_subject_coverage_threshold, alignments, True) # load the blastm8-like output file_handle = open(cfg.rapsearch2_output_file_without_header_coverage) for line in file_handle: if not re.search("^#", line): data = line.strip().split(config.blast_delimiter) referenceid = data[config.blast_reference_index] gene, length, bug = alignments.process_reference_annotation( referenceid) queryid, query_length = utilities.get_length_annotation( data[config.blast_query_index]) identity = float(data[config.blast_identity_index]) alignment_length = float( data[config.blast_aligned_length_index]) if gene in allowed_proteins: alignments.add(gene, length, queryid, identity / 100.0 * alignment_length, bug, alignment_length) file_handle.close() alignments_test = store.Alignments() unaligned_reads_store = store.Reads() # load the blastm8-like output with the unaligned reads function unaligned_file_fasta = translated.unaligned_reads( unaligned_reads_store, cfg.rapsearch2_output_file_without_header_coverage, alignments_test) # remove temp file utils.remove_temp_file(unaligned_file_fasta) # reset the coverage threshold config.translated_subject_coverage_threshold = current_coverage_threshold # check the values are unchanged self.assertEqual(sorted(alignments.get_hit_list()), sorted(alignments_test.get_hit_list()))