Esempio n. 1
0
    def test_binalign_object_method(self):
        from multicov.alignment import Alignment
        from multicov.alphabet import protein_alphabet, rna_alphabet
        from multicov.binary import BinaryAlignment
        align1 = Alignment(['ACA', 'GUA', '-A-'], alphabet=rna_alphabet)
        align2 = Alignment(['DF', 'YA', '-C'], alphabet=protein_alphabet)

        align = Alignment(align1).add(align2)
        bin_align = BinaryAlignment.from_alignment(align)

        self.assertSequenceEqual(bin_align.index_map(2), (8, 12))
        self.assertSequenceEqual(bin_align.index_map(3), (12, 32))
Esempio n. 2
0
 def test_empty(self):
     from multicov.alignment import Alignment, ReferenceMapping
     from multicov.binary import BinaryAlignment
     bin_align = BinaryAlignment.from_alignment(Alignment())
     self.assertTrue(hasattr(bin_align, 'data'))
     self.assertTrue(hasattr(bin_align, 'alphabets'))
     self.assertTrue(hasattr(bin_align, 'reference'))
     self.assertTrue(hasattr(bin_align, 'annotations'))
     self.assertEqual(np.size(bin_align.data), 0)
     self.assertEqual(np.size(bin_align.alphabets), 0)
     self.assertEqual(bin_align.annotations.size, 0)
     self.assertEqual(bin_align.reference, ReferenceMapping())
Esempio n. 3
0
    def test_include_gaps_from_binalign(self):
        from multicov.alignment import Alignment
        from multicov.alphabet import protein_alphabet, rna_alphabet
        from multicov.binary import BinaryAlignment
        align1 = Alignment(['ACA', 'GUA', '-A-'], alphabet=rna_alphabet)
        align2 = Alignment(['DF', 'YA', '-C'], alphabet=protein_alphabet)

        align = Alignment(align1).add(align2)
        bin_align = BinaryAlignment.from_alignment(align, include_gaps=True)
        full_map = bin_align.index_map()

        self.assertTrue(
            np.array_equal(full_map,
                           [[0, 5], [5, 10], [10, 15], [15, 36], [36, 57]]))
Esempio n. 4
0
    def test_binalign_object_method_full_map(self):
        from multicov.alignment import Alignment
        from multicov.alphabet import protein_alphabet, rna_alphabet
        from multicov.binary import BinaryAlignment
        align1 = Alignment(['ACA', 'GUA', '-A-'], alphabet=rna_alphabet)
        align2 = Alignment(['DF', 'YA', '-C'], alphabet=protein_alphabet)

        align = Alignment(align1).add(align2)
        bin_align = BinaryAlignment.from_alignment(align)
        full_map = bin_align.index_map()

        self.assertTrue(
            np.array_equal(full_map,
                           [[0, 4], [4, 8], [8, 12], [12, 32], [32, 52]]))
Esempio n. 5
0
    def test_multi_alpha_roundtrip(self):
        from multicov.alignment import Alignment, ReferenceMapping
        from multicov.alphabet import protein_alphabet, rna_alphabet
        from multicov.binary import BinaryAlignment
        align1 = Alignment(['ACA', 'GUA', '-A-'], alphabet=rna_alphabet)
        align2 = Alignment(['DF', 'YA', '-C'], alphabet=protein_alphabet)

        align = Alignment(align1).add(align2)
        align.reference = ReferenceMapping((list(range(1, 4)), list(range(2))))
        align.annotations['seqw'] = [0.5, 1.5, 0.2]

        bin_align = BinaryAlignment.from_alignment(align)
        align_again = bin_align.to_alignment()

        self.assertEqual(align, align_again)
Esempio n. 6
0
    def test_multi_alpha(self):
        from multicov.alignment import Alignment, ReferenceMapping
        from multicov.alphabet import protein_alphabet, rna_alphabet
        from multicov.binary import BinaryAlignment
        align1 = Alignment(['ACA', 'GUA', '-A-'], alphabet=rna_alphabet)
        align2 = Alignment(['DF', 'YA', '-C'], alphabet=protein_alphabet)

        align = Alignment(align1).add(align2)
        align.reference = ReferenceMapping((list(range(1, 4)), list(range(2))))
        align.annotations['seqw'] = [0.5, 1.5, 0.2]

        bin_align = BinaryAlignment.from_alignment(align)

        expected1 = np.asmatrix([[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0],
                                 [0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0],
                                 [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]])
        #                         A  C  D  E  F  G  H  I  K  L  M  N  P  Q  R  S  T  V  W  Y
        expected2 = np.asmatrix([[
            0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
        ],
                                 [
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                                 ],
                                 [
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                                 ]])

        self.assertSequenceEqual(bin_align.alphabets, [(rna_alphabet, 3),
                                                       (protein_alphabet, 2)])
        self.assertTrue(
            np.array_equal(bin_align.data.todense(),
                           np.hstack((expected1, expected2))))
        self.assertIs(bin_align.reference, align.reference)
        self.assertIs(bin_align.annotations, align.annotations)