Exemplo n.º 1
0
class TestSamFormatter(unittest.TestCase):

    def setUp(self):
        self.mapping = SimpleMapping()
        self.f = SamFormatter()

    def test_default(self):
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_name(self):
        self.mapping.set_name("my name")
        self.assertEqual("\t".join( map(str, ["my name", 0, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_flag(self):
        self.mapping.flag = 163
        self.assertEqual("\t".join( map(str, ['', 163, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_reference(self):
        self.mapping.tid = "chr21"
        self.assertEqual("\t".join( map(str, ['', 0, "chr21", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_mate_reference(self):
        self.mapping.mtid = "chr21"
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "chr21", 0, 0, "", "" ])), self.__do_format())
        self.mapping.mtid = "="
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "=", 0, 0, "", "" ])), self.__do_format())

    def test_pos(self):
        self.mapping.pos = 1234
        self.assertEqual("\t".join( map(str, ['', 0, "*", 1234, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_mate_pos(self):
        self.mapping.mpos = 1234
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 1234, 0, "", "" ])), self.__do_format())

    def test_mapq(self):
        self.mapping.qual = 55
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 55, "*", "*", 0, 0, "", "" ])), self.__do_format())

    def test_cigar(self):
        self.mapping.set_cigar([ (100, 'M') ])
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "100M", "*", 0, 0, "", "" ])), self.__do_format())
        self.mapping.set_cigar([ (80, 'M'), (20, 'S') ])
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "80M20S", "*", 0, 0, "", "" ])), self.__do_format())

    def test_isize(self):
        self.mapping.isize = 273
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 273, "", "" ])), self.__do_format())
        self.mapping.isize = -273
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, -273, "", "" ])), self.__do_format())

    def test_seq(self):
        self.mapping.set_seq_5("AGCTNN")
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "AGCTNN", "" ])), self.__do_format())

    def test_qual(self):
        bq = array.array('B', [22, 33, 45])
        self.mapping.set_base_qualities(bq)
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "7BN" ])), self.__do_format())

    def test_tags(self):
        self.mapping.add_tag( ("XC", 'i', 18) )
        self.mapping.add_tag( ("HI", 'Z', "llo") )
        self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "", "XC:i:18", "HI:Z:llo" ])), self.__do_format())

    def __do_format(self):
        return self.f.format(self.mapping)
Exemplo n.º 2
0
class TestProtobufSeqMapping(TestProtobufSerialization):

    def setUp(self):
        self.mapping = SimpleMapping()

    def test_simple(self):
        self.__try_and_compare_maps(self.mapping)

    def test_seq(self):
        small_seq = "AGCTNN"
        self.mapping.set_seq_5(small_seq)
        self.mapping.set_base_qualities(array.array("B", [ i + 25 for i in range(len(small_seq)) ]))
        self.__try_and_compare_maps(self.mapping)

    def test_cigar(self):
        self.mapping.set_cigar([ (100, "M") ])
        self.__try_and_compare_maps(self.mapping)
        self.mapping.set_cigar([ (80, "M"), (20, "S") ])
        self.__try_and_compare_maps(self.mapping)

    def test_flag(self):
        self.mapping.flag = 0x04
        self.__try_and_compare_maps(self.mapping)

    def test_name(self):
        self.mapping.set_name("CRESSIA_129:1:1:10029:122606#0/2")
        self.__try_and_compare_maps(self.mapping)

    def test_qual(self):
        self.mapping.qual = 60
        self.__try_and_compare_maps(self.mapping)

    def test_tags(self):
        self.mapping.add_tag( ("XC", 'i', 22) )
        self.mapping.add_tag( ("R2", 'Z', "bla") )
        self.__try_and_compare_maps(self.mapping)

    def test_pos(self):
        self.mapping.pos = 280781134
        self.__try_and_compare_maps(self.mapping)

    def test_tid(self):
        self.mapping.tid = "chr19"
        self.__try_and_compare_maps(self.mapping)

    def test_ref_id(self):
        self.mapping.ref_id = 12
        self.__try_and_compare_maps(self.mapping)
        self.mapping.ref_id = 0
        self.__try_and_compare_maps(self.mapping)

    def test_no_ref_id(self):
        self.mapping.ref_id = None
        self.__try_and_compare_maps(self.mapping)

    def __try_and_compare_maps(self, mapping):
        self.protected_compare_seq_maps(mapping, self.__pipe_map_through(mapping))

    def __pipe_map_through(self, mapping):
        message = io.serialize_seq(mapping)
        return io.unserialize_seq(message)
Exemplo n.º 3
0
class TestSamFormatter(unittest.TestCase):

	def setUp(self):
		self.mapping = SimpleMapping()
		self.f = SamFormatter()

	def test_default(self):
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_name(self):
		self.mapping.set_name("my name")
		self.assertEqual("\t".join( map(str, ["my name", 0, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_flag(self):
		self.mapping.flag = 163
		self.assertEqual("\t".join( map(str, ['', 163, "*", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_reference(self):
		self.mapping.tid = "chr21"
		self.assertEqual("\t".join( map(str, ['', 0, "chr21", 0, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_mate_reference(self):
		self.mapping.mtid = "chr21"
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "chr21", 0, 0, "", "" ])), self.__do_format())
		self.mapping.mtid = "="
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "=", 0, 0, "", "" ])), self.__do_format())

	def test_pos(self):
		self.mapping.pos = 1234
		self.assertEqual("\t".join( map(str, ['', 0, "*", 1234, 0, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_mate_pos(self):
		self.mapping.mpos = 1234
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 1234, 0, "", "" ])), self.__do_format())

	def test_mapq(self):
		self.mapping.qual = 55
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 55, "*", "*", 0, 0, "", "" ])), self.__do_format())

	def test_cigar(self):
		self.mapping.set_cigar([ (100, 'M') ])
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "100M", "*", 0, 0, "", "" ])), self.__do_format())
		self.mapping.set_cigar([ (80, 'M'), (20, 'S') ])
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "80M20S", "*", 0, 0, "", "" ])), self.__do_format())

	def test_isize(self):
		self.mapping.isize = 273
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 273, "", "" ])), self.__do_format())
		self.mapping.isize = -273
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, -273, "", "" ])), self.__do_format())

	def test_seq(self):
		self.mapping.set_seq_5("AGCTNN")
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "AGCTNN", "" ])), self.__do_format())

	def test_qual(self):
		bq = array.array('B', [22, 33, 45])
		self.mapping.set_base_qualities(bq)
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "7BN" ])), self.__do_format())

	def test_tags(self):
		self.mapping.add_tag( ("XC", 'i', 18) )
		self.mapping.add_tag( ("HI", 'Z', "llo") )
		self.assertEqual("\t".join( map(str, ['', 0, "*", 0, 0, "*", "*", 0, 0, "", "", "XC:i:18", "HI:Z:llo" ])), self.__do_format())

	def __do_format(self):
		return self.f.format(self.mapping)
Exemplo n.º 4
0
class TestProtobufSeqMapping(TestProtobufSerialization):
    def setUp(self):
        self.mapping = SimpleMapping()

    def test_simple(self):
        self.__try_and_compare_maps(self.mapping)

    def test_seq(self):
        small_seq = "AGCTNN"
        self.mapping.set_seq_5(small_seq)
        self.mapping.set_base_qualities(
            array.array("B", [i + 25 for i in range(len(small_seq))]))
        self.__try_and_compare_maps(self.mapping)

    def test_cigar(self):
        self.mapping.set_cigar([(100, "M")])
        self.__try_and_compare_maps(self.mapping)
        self.mapping.set_cigar([(80, "M"), (20, "S")])
        self.__try_and_compare_maps(self.mapping)

    def test_flag(self):
        self.mapping.flag = 0x04
        self.__try_and_compare_maps(self.mapping)

    def test_name(self):
        self.mapping.set_name("CRESSIA_129:1:1:10029:122606#0/2")
        self.__try_and_compare_maps(self.mapping)

    def test_qual(self):
        self.mapping.qual = 60
        self.__try_and_compare_maps(self.mapping)

    def test_tags(self):
        self.mapping.add_tag(("XC", 'i', 22))
        self.mapping.add_tag(("R2", 'Z', "bla"))
        self.__try_and_compare_maps(self.mapping)

    def test_pos(self):
        self.mapping.pos = 280781134
        self.__try_and_compare_maps(self.mapping)

    def test_tid(self):
        self.mapping.tid = "chr19"
        self.__try_and_compare_maps(self.mapping)

    def test_ref_id(self):
        self.mapping.ref_id = 12
        self.__try_and_compare_maps(self.mapping)
        self.mapping.ref_id = 0
        self.__try_and_compare_maps(self.mapping)

    def test_no_ref_id(self):
        self.mapping.ref_id = None
        self.__try_and_compare_maps(self.mapping)

    def __try_and_compare_maps(self, mapping):
        self.protected_compare_seq_maps(mapping,
                                        self.__pipe_map_through(mapping))

    def __pipe_map_through(self, mapping):
        message = io.serialize_seq(mapping)
        return io.unserialize_seq(message)