def test_select_good_scoring_models_extract(self): """Test select_good with extract""" with IMP.test.temporary_directory() as tmpdir: mod_dir = os.path.join(tmpdir, 'modeling') shutil.copytree(self.get_input_file_name('modeling'), mod_dir) self.run_python_module( select_good, ['-rd', mod_dir, '-rp', 'run', '-sl', 'CrossLinkingMassSpectrometryRestraint_Distance_', '-pl', 'ConnectivityRestraint_Rpb1', 'CrossLinkingMassSpectrometryRestraint_Data_Score_Chen', 'ExcludedVolumeSphere_None', 'Total_Score', '-alt', '1.0', '-aut', '1.0', '-mlt', '0.0', '-mut', '12.0', '-e']) gsm_dir = os.path.join(mod_dir, 'good_scoring_models') for score, num in (('A', 5), ('B', 4)): score_file = os.path.join(gsm_dir, 'scores%s.txt' % score) with open(score_file) as fh: wc = len(fh.readlines()) self.assertEqual(wc, num) os.unlink(score_file) model_ids = os.path.join(gsm_dir, 'model_ids_scores.txt') with open(model_ids) as fh: wc = len(fh.readlines()) self.assertEqual(wc, 10) os.unlink(model_ids) model_ids = os.path.join(gsm_dir, 'model_sample_ids.txt') with open(model_ids) as fh: lines = fh.readlines() self.assertEqual(len(lines), 9) for line in lines: num, sample = line.rstrip('\r\n').split() rmf = os.path.join(gsm_dir, 'sample_%s' % sample, '%s.rmf3' % num) if hasattr(RMF.NodeHandle, 'replace_child'): r = RMF.open_rmf_file_read_only(rmf) cpf = RMF.CombineProvenanceConstFactory(r) fpf = RMF.FilterProvenanceConstFactory(r) rn = r.get_root_node().get_children()[0] # Should be one Provenance node prov, = [n for n in rn.get_children() if n.get_type() == RMF.PROVENANCE] # Top-level provenance should be FilterProvenance self.assertTrue(fpf.get_is(prov)) fp = fpf.get(prov) self.assertEqual(fp.get_method(), "Best scoring") self.assertEqual(fp.get_frames(), 9) # Next provenance should be CombineProvenance prov, = prov.get_children() self.assertTrue(cpf.get_is(prov)) cp = cpf.get(prov) self.assertEqual(cp.get_runs(), 2) self.assertEqual(cp.get_frames(), 100) os.unlink(rmf) os.unlink(model_ids) os.rmdir(os.path.join(gsm_dir, 'sample_A')) os.rmdir(os.path.join(gsm_dir, 'sample_B')) os.rmdir(gsm_dir)
def test_exhaust(self): """Test the master sampling exhaustiveness script""" try: import pyRMSD except ImportError: self.skipTest("this test requires the pyRMSD Python module") with IMP.test.temporary_working_directory() as tmpdir: self.make_models(tmpdir) gsm_dir = os.path.join(tmpdir, 'modeling', 'good_scoring_models') self.run_python_module(exhaust, [ '-n', 'test', '-p', gsm_dir, '-d', self.get_input_file_name('density_ranges.txt'), '-m', 'cpu_omp', '-c', '8', '-a', '-g', '0.5', '-gp' ]) if hasattr(RMF.NodeHandle, 'replace_child'): r = RMF.open_rmf_file_read_only( os.path.join(tmpdir, 'cluster.0', 'cluster_center_model.rmf3')) clpf = RMF.ClusterProvenanceConstFactory(r) cpf = RMF.CombineProvenanceConstFactory(r) fpf = RMF.FilterProvenanceConstFactory(r) rn = r.get_root_node().get_children()[0] # Should be one Provenance node prov, = [ n for n in rn.get_children() if n.get_type() == RMF.PROVENANCE ] # Top-level provenance should be ClusterProvenance self.assertTrue(clpf.get_is(prov)) cp = clpf.get(prov) self.assertEqual(cp.get_members(), 36) self.assertAlmostEqual(cp.get_precision(), 0.42, delta=0.01) self.assertEqual(cp.get_density(), os.path.abspath('cluster.0/LPD_TestAll.mrc')) # Next provenance should be filter, combine prov, = prov.get_children() self.assertTrue(fpf.get_is(prov)) prov, = prov.get_children() self.assertTrue(cpf.get_is(prov)) # Check for expected files expected = [ 'Distances_Matrix.data.npy', 'Identities_A.txt', 'Identities_B.txt', 'cluster.0.all.txt', 'cluster.0.sample_A.txt', 'cluster.0.sample_B.txt', 'test.ChiSquare.pdf', 'test.ChiSquare_Grid_Stats.txt', 'test.Cluster_Population.pdf', 'test.Cluster_Population.txt', 'test.Cluster_Precision.txt', 'test.KS_Test.txt', 'test.Sampling_Precision_Stats.txt', 'test.Score_Dist.pdf', 'test.Score_Hist_A.txt', 'test.Score_Hist_B.txt', 'test.Top_Score_Conv.pdf', 'test.Top_Score_Conv.txt', 'cluster.0/cluster_center_model.rmf3', 'cluster.0/LPD_TestAll.mrc', 'cluster.0/Sample_A/LPD_TestAll.mrc', 'cluster.0/Sample_B/LPD_TestAll.mrc' ] for e in expected: os.unlink(os.path.join(tmpdir, e)) os.rmdir(os.path.join(tmpdir, 'cluster.0', 'Sample_A')) os.rmdir(os.path.join(tmpdir, 'cluster.0', 'Sample_B')) os.rmdir(os.path.join(tmpdir, 'cluster.0'))