def test_retrieve_supplementary_alignment_from_primary(self): alignment_it = self.alignment_file.fetch(until_eof=True) alignments = list(alignment_it) for i in range(10, 30, 2): primary = alignments[i] supplementary = alignments[i + 1] retrieved_supplementary_alns = retrieve_other_alignments( primary, self.alignment_file) self.assertEqual(len(retrieved_supplementary_alns), 1) self.assertEqual(retrieved_supplementary_alns[0].cigarstring, supplementary.cigarstring.replace("H", "S")) self.assertEqual(retrieved_supplementary_alns[0].reference_id, supplementary.reference_id) self.assertEqual(retrieved_supplementary_alns[0].reference_start, supplementary.reference_start) self.assertEqual(retrieved_supplementary_alns[0].reference_end, supplementary.reference_end) self.assertEqual(retrieved_supplementary_alns[0].flag, supplementary.flag) self.assertEqual(retrieved_supplementary_alns[0].mapping_quality, supplementary.mapping_quality) self.assertEqual( retrieved_supplementary_alns[0].query_sequence[ retrieved_supplementary_alns[0].query_alignment_start: retrieved_supplementary_alns[0].query_alignment_end], supplementary.query_sequence) self.assertEqual(retrieved_supplementary_alns[0].query_name, supplementary.query_name)
def test_retrieve_primary_alignment_from_supplementary(self): alignment_it = self.alignment_file.fetch(until_eof=True) alignments = list(alignment_it) for i in range(10, 30, 2): primary = alignments[i] supplementary = alignments[i + 1] retrieved_primary_alns = retrieve_other_alignments( supplementary, self.alignment_file) self.assertEqual(len(retrieved_primary_alns), 0)
def test_satag_extraction_complete(self): primary = self.alignments[0] supplementary_alns = retrieve_other_alignments(primary, self.samfile) for index, aln in enumerate(supplementary_alns): self.assertEqual(aln.cigarstring, self.alignments[index + 1].cigarstring) self.assertEqual(aln.reference_id, self.alignments[index + 1].reference_id) self.assertEqual(aln.reference_start, self.alignments[index + 1].reference_start) self.assertEqual(aln.reference_end, self.alignments[index + 1].reference_end) self.assertEqual(aln.flag, self.alignments[index + 1].flag) self.assertEqual(aln.mapping_quality, self.alignments[index + 1].mapping_quality) self.assertEqual(aln.query_sequence, self.alignments[index + 1].query_sequence) self.assertEqual(aln.query_name, self.alignments[index + 1].query_name) self.assertEqual(aln.query_alignment_start, self.alignments[index + 1].query_alignment_start) self.assertEqual(aln.query_alignment_end, self.alignments[index + 1].query_alignment_end)
def test_satag_negative_mapq(self): primary = self.alignments[1] supplementary_alns = retrieve_other_alignments(primary, self.samfile) #negative mapping quality is interpreted as 0 self.assertEqual(len(supplementary_alns), 1) self.assertEqual(supplementary_alns[0].mapping_quality, 0)
def test_satag_too_many_fields(self): primary = self.alignments[0] supplementary_alns = retrieve_other_alignments(primary, self.samfile) #first SA entry has too many fields self.assertEqual(len(supplementary_alns), 2)
def test_satag_length(self): primary = self.alignments[0] supplementary_alns = retrieve_other_alignments(primary, self.samfile) self.assertEqual(len(supplementary_alns), 3)