コード例 #1
0
 def test_UserDataSourceEntryCreator(self):
     datasource = SimpleDataSource()
     for key in DATASOURCE_OBJECT_FACTORIES:
         creator = UserDataSourceEntryCreator(
             datasource=datasource, datasource_key=key
         )
         self.assertCreatorValid(creator, key)
コード例 #2
0
    def setUp(self):
        GuiTestAssistant.setUp(self)

        register_all_data_views()
        datasource = SimpleDataSource()
        product = datasource.get_object_of_type("products", 'Prod001')
        ds = InStudyDataSource()
        buf = Buffer(**BUFFER_ELUTION)
        ds.set_object_of_type("buffers", buf)
        self.study = Study(name="test",
                           product=product,
                           datasource=datasource,
                           study_datasource=ds)
        ds = InStudyDataSource()
        self.study2 = Study(name="test2",
                            datasource=datasource,
                            study_datasource=ds)
コード例 #3
0
 def test_read_input_files_with_release_ds(self):
     ds = SimpleDataSource.from_data_catalog(DATA_CATALOG)
     # Make sure that's the external datasource
     self.assertEqual(len(ds.products), 3)
     study = load_study_from_excel(self.tutorial_file,
                                   datasource=ds,
                                   allow_gui=False)
     self.assert_valid_tutorial_study(study)
コード例 #4
0
 def test_read_input_files_with_internal_ds(self):
     ds = SimpleDataSource()
     # Make sure that's the internal datasource
     self.assertGreater(len(ds.products), 5)
     study = load_study_from_excel(self.tutorial_file,
                                   datasource=ds,
                                   allow_gui=False)
     self.assert_valid_tutorial_study(study)
コード例 #5
0
class TestProductChooser(TestCase):
    def setUp(self):
        self.ds = SimpleDataSource()
        self.prod_chooser = ProductChooser(datasource=self.ds)

    def test_create_ui(self):
        ui = self.prod_chooser.edit_traits()
        ui.dispose()

    def test_selection(self):
        target_prod = self.ds.get_object_names_by_type("products")[0]
        self.prod_chooser.selected_product_name = target_prod

        expected = self.ds.get_object_of_type("products", target_prod)
        assert_has_traits_almost_equal(self.prod_chooser.selected_product,
                                       expected)
        assert (self.prod_chooser.selected_product is not expected)
コード例 #6
0
    def setUp(self):
        super(TestKromatographyTaskRunRequest, self).setUp()
        self.datasource = SimpleDataSource()
        self.task = KromatographyTask()

        self.study2 = make_sample_study(num_exp=1)
        project_data = dict(study=self.study2, datasource=self.datasource,
                            job_manager=self.job_manager)
        project = KromatographyProject(**project_data)
        self.task2 = KromatographyTask(project=project)
コード例 #7
0
    def setUp(self):
        self.datasource = SimpleDataSource()
        proj_data = dict(study=make_blank_study(), datasource=self.datasource)
        project = KromatographyProject(**proj_data)
        self.task = KromatographyTask(project=project)

        self.study2 = make_sample_study(num_exp=1)
        proj_data = dict(study=self.study2, datasource=self.datasource)
        project = KromatographyProject(**proj_data)
        self.task2 = KromatographyTask(project=project)
コード例 #8
0
class TestHighLevelFileStorageDataSource(TestCaseWithTempFile):
    """ Test of high level functions save_object and load_object on
    SimpleDatasource instances.
    """
    def setUp(self):
        super(TestHighLevelFileStorageDataSource, self).setUp()
        self.ds = SimpleDataSource()

    def test_default_simple_datasource(self):
        assert_file_roundtrip_identical(self.ds)

    def test_modified_simple_datasource_via_list(self):
        # FIXME: adding to the datasource currently means adding to the
        # object_catalog, to the data catalog and the corresponding list
        new_comp = Component(name="New Component",
                             charge=UnitScalar(0.0, units='1'),
                             pKa=UnitScalar(0.0, units='1'))
        self.ds.set_object_of_type("components", new_comp)
        self.ds.make_clean()
        assert_file_roundtrip_identical(self.ds)
コード例 #9
0
def make_sample_user_ds(with_bind_trans=False, num_comp=4):
    """ Make a sample User datasource, optionally adding a sample binding and
    transport models to the data catalog content.
    """
    user_ds = SimpleDataSource()
    if with_bind_trans:
        # Add a sample binding and transport models to test their adaptation
        sample_bind_model = make_sample_binding_model(num_comp)
        user_ds.binding_models.append(sample_bind_model)
        sample_transp_model = make_sample_transport_model(num_comp)
        user_ds.transport_models.append(sample_transp_model)
    return user_ds
コード例 #10
0
def load_default_user_datasource():
    """ Load or build the default user datasource.

    If a datasource was stored in the default, location, load the newest one.
    Otherwise, build a new SimpleDataSource.

    Returns
    -------
    tuple with a SimpleDatasource instance and the file if any that it was
    loaded from.
    """
    from kromatography.model.data_source import SimpleDataSource
    from kromatography.io.reader_writer import load_object

    # Logger defined here so that the logger can be defined after the
    # initialize_logging is called.
    logger = logging.getLogger(__name__)

    last_stored_ds_file = get_newest_app_file(extension=DS_EXT)
    if last_stored_ds_file is not None:
        try:
            ds, legacy_file = load_object(last_stored_ds_file)
            msg = "Loaded datasource from {}".format(last_stored_ds_file)
            logger.info(msg)
            if legacy_file:
                msg = "Datasource storage {} is a legacy file."
                logger.info(msg)

        except Exception as e:
            msg = ("Failed to load the last datasource file {}. The file "
                   "might be corrupted, and mights need to be removed. Error "
                   "was {}.").format(last_stored_ds_file, e)
            logger.error(msg)
            last_stored_ds_file = None

    # Not doing an else, so that this is executed when exception raised:
    if last_stored_ds_file is None:
        msg = "No valid datasource file found. Loading a default one."
        logger.debug(msg)
        ds = SimpleDataSource(name="User DataSource")
        last_stored_ds_file = ""

    return ds, last_stored_ds_file
コード例 #11
0
 def test_prepare_datasource_catalog(self):
     datasource = SimpleDataSource()
     prepare_datasource_catalog(datasource)
     self.assertCreatorOnAllEntries(datasource)
コード例 #12
0
    def setUp(self):
        # Regist the views
        BaseModelViewTestCase.setUp(self)

        s = SimpleDataSource()
        self.model = s.get_object_of_type('chemicals', 'Sodium_Acetate')
コード例 #13
0
class TestSimulationBuilderDialog(TestCase):
    def setUp(self):
        self.datasource = SimpleDataSource()
        self.study = make_sample_study2(add_transp_bind_models=True)
        self.study_ds = self.study.study_datasource
        self.sim_builder = SimulationFromDatasourceBuilder(
            datasource=self.datasource, study_datasource=self.study_ds)

    def test_bring_up(self):
        ui = self.sim_builder.edit_traits()
        ui.dispose()

    def test_product_selection(self):
        target_prod = self.datasource.get_object_names_by_type("products")[0]
        self.sim_builder.product_name = target_prod
        exp = self.datasource.get_object_of_type("products", target_prod)
        assert_has_traits_almost_equal(self.sim_builder.product, exp)

    def test_build_simulation(self):
        # Setup
        self.sim_builder.column_name = 'CP_001'
        self.sim_builder.method_name = 'Run_1'
        self.sim_builder.first_simulated_step_name = 'Load'
        self.sim_builder.last_simulated_step_name = 'Strip'
        self.sim_builder.transport_model_name = DEFAULT_TRANSPORT_MODEL_NAME
        self.sim_builder.binding_model_name = DEFAULT_BINDING_MODEL_NAME
        sim = self.sim_builder.to_simulation()
        self.assertIsInstance(sim, Simulation)

        # init buffer:
        self.assertEqual(self.sim_builder.initial_buffer_name, '')

        exp1 = self.study.search_experiment_by_name("Run_1")
        equil_buffer = exp1.method.method_steps[1].solutions[0].name
        self.assertEqual(sim.method.initial_buffer.name, equil_buffer)
        # the simulation has to be valid enough that it can be converted to a
        # CADET input...
        cadet_input = build_cadet_input(sim)
        self.assertIsInstance(cadet_input, CADETInput)

    def test_build_simulation_force_init_buffer(self):
        # Setup
        self.sim_builder.column_name = 'CP_001'
        self.sim_builder.method_name = 'Run_1'
        self.sim_builder.first_simulated_step_name = 'Load'
        self.sim_builder.last_simulated_step_name = 'Strip'
        self.sim_builder.initial_buffer_name = 'Elution_1'
        self.sim_builder.transport_model_name = DEFAULT_TRANSPORT_MODEL_NAME
        self.sim_builder.binding_model_name = DEFAULT_BINDING_MODEL_NAME
        sim = self.sim_builder.to_simulation()
        self.assertIsInstance(sim, Simulation)
        self.assertEqual(sim.method.initial_buffer.name, 'Elution_1')

    def test_change_method_name_changes_first_last_guesses(self):
        self.assertIsNone(self.sim_builder.first_simulated_step_name)
        self.assertIsNone(self.sim_builder.last_simulated_step_name)
        self.sim_builder.method_name = 'Run_1'
        self.assertEqual(self.sim_builder.first_simulated_step_name,
                         'Pre-Equilibration')
        self.assertEqual(self.sim_builder.last_simulated_step_name, 'Strip')

    def test_change_method_changes_solution_list(self):
        self.sim_builder.method_name = 'Run_1'
        all_solutions = []
        for step in self.sim_builder.method.method_steps:
            all_solutions += [
                sol.name for sol in step.solutions if isinstance(sol, Buffer)
            ]

        # Sim builder also allows the init_buffer to be blank so that it is
        # looked up in the source experiment:
        all_solutions += [""]
        self.assertEqual(set(all_solutions), set(self.sim_builder.all_buffers))
コード例 #14
0
 def setUp(self):
     self.datasource = SimpleDataSource()
     self.study = make_sample_study2(add_transp_bind_models=True)
     self.study_ds = self.study.study_datasource
     self.sim_builder = SimulationFromDatasourceBuilder(
         datasource=self.datasource, study_datasource=self.study_ds)
コード例 #15
0
    def setUp(self):
        # Regist the views
        BaseModelViewTestCase.setUp(self)

        s = SimpleDataSource()
        self.model = s.get_object_of_type('components', 'Acetate')
コード例 #16
0
        )
        return view

    # -------------------------------------------------------------------------
    # Traits listeners
    # -------------------------------------------------------------------------

    @on_trait_change("model.product_component_assays[]")
    def get_product_component_assays(self):
        assay_names = self.model.product_component_assays
        self.product_component_assays = assay_instances_from_names(assay_names)

    @on_trait_change("product_component_assays, product_component_assays.name,"
                     "product_component_assays[]")
    def update_model_product_component_assays(self):
        self.model.product_component_assays = assay_names_from_instances(
            self.product_component_assays)


if __name__ == '__main__':
    from kromatography.model.data_source import SimpleDataSource
    from kromatography.utils.app_utils import initialize_unit_parser
    initialize_unit_parser()

    s = SimpleDataSource()

    product = s.get_object_of_type('products', 'Prod001')
    product_view = ProductView(model=product)
    product_view.configure_traits()
    product.print_traits()
コード例 #17
0
 def setUp(self):
     self.ds = SimpleDataSource()
     self.builder = ProductBuilder(datasource=self.ds)
コード例 #18
0
def build_chemical_component_table_editor(known_component_names):
    """ Build an editor for a list of chemical components.
    """
    default_count = 1

    component_editor = TableEditor(
        columns=[
            ObjectColumn(name='name',
                         editor=EnumEditor(values=known_component_names)),
            ObjectColumn(name='component_atom_count')
        ],
        editable=True,
        sortable=False,
        deletable=True,
        row_factory=ChemicalComponent,
        row_factory_kw={
            "name": known_component_names[0],
            "component_atom_count": default_count
        },
    )
    return component_editor


if __name__ == '__main__':
    # setting up model
    from kromatography.model.data_source import SimpleDataSource
    s = SimpleDataSource()
    model = s.build_chemical_from_data("Sodium_Chloride")
    model_view = ChemicalView(model=model)
    model_view.configure_traits()
コード例 #19
0
            solution.chemical_component_concentrations = UnitArray(
                [comp.concentration[()] for comp in chem_comps],
                units=comp.concentration.units
            )
        else:
            solution.chemical_component_concentrations = UnitArray([])

    # Traits property getters/setters -----------------------------------------

    def _get__has_strip(self):
        return STRIP_COMP_NAME in self.model.product.product_component_assays

    def __strip_desc_default(self):
        strip_desc = r"The strip fraction describes the percentage of total " \
                     r"absorbance to assign to the strip component. (Use " \
                     r"the dedicated tool to modify: <i>Tools > {}</i>.)"
        strip_desc = strip_desc.format(STRIP_TOOL_NAME)
        return strip_desc


if __name__ == '__main__':
    # setting up model
    from kromatography.model.tests.example_model_data import SOLUTIONWITHPRODUCT_LOAD  # noqa
    from kromatography.model.data_source import SimpleDataSource

    ds = SimpleDataSource()
    solution = SolutionWithProduct(**SOLUTIONWITHPRODUCT_LOAD)
    solution.print_traits()
    solution_view = SolutionWithProductView(model=solution, datasource=ds)
    solution_view.configure_traits()
コード例 #20
0
class TestProductBuilder(TestCase):
    def setUp(self):
        self.ds = SimpleDataSource()
        self.builder = ProductBuilder(datasource=self.ds)

    def test_bring_up(self):
        self.builder.expert_mode = False
        with temp_bringup_ui_for(self.builder):
            pass

        self.builder.expert_mode = True
        with temp_bringup_ui_for(self.builder):
            pass

    def test_default_attributes(self):
        self.assertFalse(self.builder.expert_mode)
        # Default target product not known in default datasource
        known_products = {comp.target_product for comp in
                          self.ds.get_objects_by_type("product_components")}
        self.assertNotIn(self.builder.name, known_products)
        # Therefore, there are no candidate components:
        self.assertEqual(self.builder._component_candidates_names, [])

    def test_build_product_fail_no_type(self):
        prod = self.builder.build_product(allow_ui=False)
        self.assertIsNone(prod)

    def test_build_product_empty_default(self):
        self.builder.product_type = "Globular"
        prod = self.builder.build_product(allow_ui=False)
        self.assertIsInstance(prod, Product)
        self.assertEqual(len(prod.product_components), 1)
        comp = prod.product_components[0]
        self.assertEqual(comp.name, STRIP_COMP_NAME)
        self.assertEqual(comp.target_product, prod.name)

    def test_build_product_empty_no_strip(self):
        self.builder.product_type = "Globular"
        self.builder.add_strip = False
        prod = self.builder.build_product(allow_ui=False)
        self.assertIsInstance(prod, Product)
        self.assertEqual(prod.product_components, [])

    def test_build_product_empty_expert_mode(self):
        self.builder.product_type = "Globular"
        self.builder.expert_mode = True
        prod = self.builder.build_product(allow_ui=False)
        self.assertIsInstance(prod, Product)
        self.assertEqual(prod.product_components, [])

    def test_build_product_with_comp_expert_mode(self):
        """ Test that builder in expert mode can rebuild PROD000.
        """
        original_prod0 = self.ds.get_objects_by_type("products",
                                                     {"name": "Prod000"})[0]
        comp_names = [c.name for c in original_prod0.product_components]

        self.builder.name = "Prod000"
        self.builder.product_type = "Globular"
        self.builder.pI = UnitScalar(7.52, units='1')
        self.builder.expert_mode = True

        # In expert mode, we set the list of assay names and component names
        # and expressions:
        for name in comp_names:
            assay_name = "CEX_{}".format(name)
            exp = "product_concentration * {} / 100".format(assay_name)
            comp_desc = ComponentDescription(name=name,
                                             concentration_exps=exp)
            self.builder.component_descs.append(comp_desc)
            assay = ProductComponentAssay(name=assay_name)
            self.builder.component_assay_names.append(assay)

        prod = self.builder.build_product(allow_ui=False)
        ignore = ["amino_acids", "amino_acid_numbers"]
        assert_has_traits_almost_equal(prod, original_prod0,
                                       ignore=ignore)

        # In expert mode, add_strip is ignored:
        self.builder.add_strip = True
        prod = self.builder.build_product(allow_ui=False)
        ignore = ["amino_acids", "amino_acid_numbers"]
        assert_has_traits_almost_equal(prod, original_prod0,
                                       ignore=ignore)

    def test_build_product_with_comp_simplified_mode(self):
        """ Modify PROD000 and make sure builder can rebuild it (no strip).

        Simplify its component and assay names, and make sure the simplified
        builder with add_strip=False can rebuild it.
        """
        orig_prod0 = self.ds.get_objects_by_type("products",
                                                 {"name": "Prod000"})[0]
        comp_names = [c.name for c in orig_prod0.product_components]
        # Change the assays to be named like the components since the
        # simplified mode only supports that:
        orig_assays = ['CEX_Acidic_2', 'CEX_Acidic_1', 'CEX_Native']
        self.assertEqual(orig_prod0.product_component_assays, orig_assays)
        orig_prod0.product_component_assays = comp_names
        exps = ["product_concentration * CEX_{} / 100".format(name)
                for name in comp_names]
        orig_conc_exps = Series(exps, index=comp_names)
        assert_series_equal(orig_prod0.product_component_concentration_exps,
                            orig_conc_exps)
        new_exps = ["product_concentration * {} / 100".format(name)
                    for name in comp_names]
        orig_prod0.product_component_concentration_exps = \
            Series(new_exps, index=comp_names)

        self.builder.name = "Prod000"
        self.builder.product_type = "Globular"
        self.builder.pI = UnitScalar(7.52, units='1')
        self.builder.expert_mode = False
        self.builder.add_strip = False

        # In simplified mode, we just set a list of component names:
        for name in comp_names:
            comp_desc = ComponentDescription(name=name)
            self.builder.component_descs.append(comp_desc)

        prod = self.builder.build_product(allow_ui=False)
        ignore = ["amino_acids", "amino_acid_numbers"]
        assert_has_traits_almost_equal(prod, orig_prod0,
                                       ignore=ignore)

    def test_build_product_with_comp_simplified_mode_with_strip(self):
        """ Modify PROD000 and make sure builder can rebuild it (with strip).

        Add a strip to it, and change its component and assay names, and make
        sure the simplified building with the add_strip=True.
        """
        orig_prod0 = self.ds.get_objects_by_type("products",
                                                 {"name": "Prod000"})[0]
        comp_names = [c.name for c in orig_prod0.product_components]
        # Change the assays to be named like the components since the
        # simplified mode only supports that:
        orig_prod0.product_component_assays = comp_names
        new_exps = ["product_concentration * {} / 100".format(name)
                    for name in comp_names]
        orig_prod0.product_component_concentration_exps = \
            Series(new_exps, index=comp_names)

        # Modify the prod to add a strip
        new_prod, strip_comp = add_strip_to_product(orig_prod0)

        # Rebuild prod0 with the builder:
        self.builder.name = new_prod.name
        self.builder.product_type = "Globular"
        self.builder.pI = UnitScalar(7.52, units='1')
        self.builder.expert_mode = False
        self.builder.add_strip = True

        for comp in new_prod.product_components:
            name = comp.name
            if name != STRIP_COMP_NAME:
                self.ds.set_object_of_type("product_components", comp)
                comp_desc = ComponentDescription(name=name)
                self.builder.component_descs.append(comp_desc)

        prod = self.builder.build_product(allow_ui=False)
        ignore = ["amino_acids", "amino_acid_numbers", "name"]
        assert_has_traits_almost_equal(prod, new_prod, ignore=ignore)
コード例 #21
0
 def setUp(self):
     super(TestHighLevelFileStorageDataSource, self).setUp()
     self.ds = SimpleDataSource()
 def setUp(self):
     self.ds = SimpleDataSource.from_data_catalog(data_catalog=DATA_CATALOG)
コード例 #23
0
    """
    columns = [ObjectColumn(name='name', style="readonly",
                            label="Component name",
                            tooltip="Name of component to build product with. "
                                    "Must exist in user data.")]
    if expert_mode:
        tooltip = ("Enter the expression to compute the component's "
                   "concentration, as a function of the total product "
                   "concentration ('product_concentration') and the component "
                   "assay names.")

        columns += [ObjectColumn(name='concentration_exps',
                                 label="Component concentration expression",
                                 tooltip=tooltip)]

    editor = TableEditor(
        columns=columns,
        editable=True,
        sortable=False,
        deletable=True,
    )

    return editor


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    builder = ProductBuilder(datasource=SimpleDataSource())
    builder.configure_traits()
    builder.build_product()
コード例 #24
0
 def _datasource_default(self):
     return SimpleDataSource()
コード例 #25
0
 def setUp(self):
     self.ds = SimpleDataSource()
     self.prod_chooser = ProductChooser(datasource=self.ds)
コード例 #26
0
 def setUp(self):
     self.datasource = SimpleDataSource()
     self.task = KromatographyTask()
    def _get_column(self):
        return self._get_object_clone_from_name("columns", self.column_name)

    def _get_product(self):
        return self._get_object_clone_from_name("products", self.product_name)

    def _get_method(self):
        if self.method_name:
            method = self._get_object_clone_from_name("methods",
                                                      self.method_name)
            method.initial_buffer = self.initial_buffer
            return method

    def _get_step_names(self):
        if self.method_name:
            return [step.name for step in self.method.method_steps]
        else:
            return []


if __name__ == "__main__":
    from kromatography.model.data_source import SimpleDataSource
    from kromatography.model.tests.sample_data_factories import \
        make_sample_study

    study = make_sample_study()
    sim_builder = SimulationFromDatasourceBuilder(
        datasource=SimpleDataSource(), study_datasource=study.study_datasource
    )
    sim_builder.configure_traits()