Beispiel #1
0
    def test_extract_value_should_fail_with_map_name_mismatch(self):
        mapper = mapping.PeakMapper("test", n_peaks=10, atom_names=["N", "H"])
        m = mapping.PeakMapping(map_name="fail", peak_id=0, atom_name="H")
        state = mapper.get_initial_state()

        with self.assertRaises(KeyError):
            mapper.extract_value(m, state)
Beispiel #2
0
    def test_extract_value_should_raise_with_illegal_peak_id(self):
        mapper = mapping.PeakMapper("test", n_peaks=1, atom_names=["N", "H"])
        mapper.add_atom_group(N=AtomIndex(0), H=AtomIndex(1))
        mapper.add_atom_group(N=AtomIndex(2), H=AtomIndex(3))
        mapper.add_atom_group(N=AtomIndex(4), H=AtomIndex(5))
        state = mapper.get_initial_state()

        with self.assertRaises(KeyError):
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=1, atom_name="H"),
                state)
Beispiel #3
0
    def test_extract_value_should_return_not_mapped(self):
        mapper = mapping.PeakMapper("test", n_peaks=3, atom_names=["N", "H"])
        mapper.add_atom_group(N=AtomIndex(0), H=AtomIndex(1))
        state = mapper.get_initial_state()

        val1 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=0, atom_name="N"),
            state)
        val2 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=0, atom_name="H"),
            state)
        val3 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=1, atom_name="N"),
            state)

        val4 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=1, atom_name="H"),
            state)
        val5 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=2, atom_name="N"),
            state)

        val6 = mapper.extract_value(
            mapping.PeakMapping(map_name="test", peak_id=2, atom_name="H"),
            state)

        # We have 3 peaks, but only one atom group, so only one peak will
        # map to something. With the default initialization, this will be
        # the first peak.
        self.assertEqual(val1, 0)
        self.assertEqual(val2, 1)
        self.assertIsInstance(val3, mapping.NotMapped)
        self.assertIsInstance(val4, mapping.NotMapped)
        self.assertIsInstance(val5, mapping.NotMapped)
        self.assertIsInstance(val6, mapping.NotMapped)
Beispiel #4
0
    def test_extract_value_should_return_correct_values(self):
        manager = mapping.PeakMapManager()

        # map1 has 2 pekas, 2 atom_groups
        map1 = manager.add_map("map1", 2, atom_names=["N", "H"])
        map1.add_atom_group(N=AtomIndex(0), H=AtomIndex(1))
        map1.add_atom_group(N=AtomIndex(2), H=AtomIndex(3))

        # map2 has 2 peaks, but only 1 atom_group -> 1 peak will be NotMapped
        map2 = manager.add_map("map2", 2, atom_names=["N", "H"])
        map2.add_atom_group(N=AtomIndex(4), H=AtomIndex(5))

        state = manager.get_initial_state()

        ind1 = manager.extract_value(mapping.PeakMapping("map1", 0, "N"),
                                     state)
        ind2 = manager.extract_value(mapping.PeakMapping("map1", 0, "H"),
                                     state)
        ind3 = manager.extract_value(mapping.PeakMapping("map1", 1, "N"),
                                     state)
        ind4 = manager.extract_value(mapping.PeakMapping("map1", 1, "H"),
                                     state)
        ind5 = manager.extract_value(mapping.PeakMapping("map2", 0, "N"),
                                     state)
        ind6 = manager.extract_value(mapping.PeakMapping("map2", 0, "H"),
                                     state)
        ind7 = manager.extract_value(mapping.PeakMapping("map2", 1, "N"),
                                     state)
        ind8 = manager.extract_value(mapping.PeakMapping("map2", 1, "H"),
                                     state)

        self.assertEqual(ind1, 0)
        self.assertEqual(ind2, 1)
        self.assertEqual(ind3, 2)
        self.assertEqual(ind4, 3)
        self.assertEqual(ind5, 4)
        self.assertEqual(ind6, 5)
        self.assertIsInstance(ind7, mapping.NotMapped)
        self.assertIsInstance(ind8, mapping.NotMapped)
Beispiel #5
0
    def test_extract_value_should_give_correct_indices_with_equal_length(self):
        mapper = mapping.PeakMapper("test", n_peaks=3, atom_names=["N", "H"])
        mapper.add_atom_group(N=AtomIndex(0), H=AtomIndex(1))
        mapper.add_atom_group(N=AtomIndex(2), H=AtomIndex(3))
        mapper.add_atom_group(N=AtomIndex(4), H=AtomIndex(5))
        state = mapper.get_initial_state()

        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=0, atom_name="N"),
                state),
            0,
        )
        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=0, atom_name="H"),
                state),
            1,
        )
        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=1, atom_name="N"),
                state),
            2,
        )
        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=1, atom_name="H"),
                state),
            3,
        )
        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=2, atom_name="N"),
                state),
            4,
        )
        self.assertEqual(
            mapper.extract_value(
                mapping.PeakMapping(map_name="test", peak_id=2, atom_name="H"),
                state),
            5,
        )