Beispiel #1
0
    def test_data_source_creation(self):
        # Test creation
        source_1 = DataSource("lol.pdb")
        self.assertDictEqual({"source": "lol.pdb"}, source_1.source)

        source_2 = DataSource({"source": "lol.pdb", "another_kw": 3})
        self.assertDictEqual({
            "source": "lol.pdb",
            "another_kw": 3
        }, source_2.source)
Beispiel #2
0
    def test_data_source_comparison(self):
        m_source = DataSource("mini")
        n_source = DataSource("normal")
        another_n_source = DataSource("normal")
        b_source = DataSource("zobig")

        # Test lexicographical comparison
        self.assertTrue(m_source < n_source)
        self.assertTrue(n_source == another_n_source)
        self.assertTrue(b_source > n_source)
Beispiel #3
0
 def test_load(self):
     loader = FeatureArrayDataLoader(None)
     source = DataSource(
         os.path.join(TestFeatArrDataLoader.data_path,
                      "numerical_features_1.txt"))
     self.compare_loaded_results(data.expected_1,
                                 loader.load_data_from_source(source))
     source.add_info("labels", ["uno", "dos", "tres", "cuatro", "cinco"])
     self.compare_loaded_results(data.expected_2,
                                 loader.load_data_from_source(source))
 def setup_loader(self):
     """
     Builds a loader with 2 preloaded pdbs from the data folder.
     """
     loader = ProteinEnsembleDataLoader(ProtocolParameters({"matrix":{}}))
     source1 = DataSource(os.path.join(test_data.__path__[0], "pdb1.pdb"))
     loader.load(source1)
     source2 = DataSource({
                           "source":os.path.join(test_data.__path__[0], "pdb2.dcd"),
                           "atoms_source": os.path.join(test_data.__path__[0], "pdb2.pdb")
     })
     loader.load(source2)
     return loader
 def test_load(self):
     """
     If we already loaded 2 pdbs of 2 conformations, the elements corresponfding to 
     the next loaded pdb of 2 confs, 2 atoms will be [4,5] (elements start in 0).
     It indirectly tests the dcd loading (which would be a responsabilit of the
     data test indeed).
     """
     loader = self.setup_loader()
     source3 = DataSource(os.path.join(test_data.__path__[0], "pdb3.pdb"))
     final_range = loader.load(source3)
     self.assertEqual([4,5], list(final_range))
     self.assertEqual(source3.source['number_of_conformations'], 2)
     self.assertEqual(source3.source['number_of_atoms'], 2)
 def test_load_with_base_selection(self):
     """
     Fine grain case of test_load using base_selection in the file descriptor.
     """
     loader = self.setup_loader()
     source3 = DataSource({
                           "source": os.path.join(test_data.__path__[0], "pdb3.pdb"),
                           "base_selection": "resnum 3"
     })
     final_range = loader.load(source3)
     self.assertSequenceEqual([4,5], list(final_range))
     self.assertEqual(source3.source['number_of_conformations'], 2)
     self.assertEqual(source3.source['number_of_atoms'], 1)
     self.assertEqual(loader.loaded_data[-1].getResnames(), ['ILE'])
     
     # Closing this loader must raise a prody exception (different number of atoms
     # for some conformations)
     self.assertRaises(ValueError, loader.close)
 def test_close_with_model_remark(self):
     """
     Tests that model number and remark info was acquired
     """
     loader = self.setup_loader()
     source3 = DataSource(os.path.join(test_data.__path__[0], "pdb3.pdb"))
     loader.load(source3)
     loader.close()
     expected_models = [1,2,1,2,8,9] #[1,2,5,6,8,9] -> this if whe have a pdb
     expected_remarks = [
                         ["REMARK 400 HELLO\n"], 
                         ["REMARK 400 WORLD\n"],
                         [],
                         [],
                         [],
                         ["REMARKS NINETH MODEL\n"]
                        ]
     self.assertSequenceEqual(expected_remarks, loader.model_remarks)
     self.assertSequenceEqual(expected_models, loader.model_numbers)
 def test_load_one_row(self):
     loader = FeatureArrayDataLoader(None)
     source = DataSource(os.path.join(TestFeatArrDataLoader.data_path, "numerical_features_1.txt"))
     source.add_info("labels", ["uno", "dos", "tres", "cuatro", "cinco"])
     source.add_info("load_only", [2, 3])
     self.compare_loaded_results(data.expected_3, loader.load_data_from_source(source))
Beispiel #9
0
 def get_elements_with_source(self, source_str):
     """
     """
     return [i for i in self.elements[DataSource(source_str)]]
Beispiel #10
0
 def __init__(self, source_list):
     self.source_list = [
         DataSource(source)
         for source in SourceGenerator.inflate_source_list(source_list)
     ]