Esempio n. 1
0
 def convert_to_stock_sample(self):
     """
     Converts this instance into a stock sample by setting all the
     required attributes. The object class is ''not'' changed.
     """
     mols = [sm.molecule for sm in self.sample_molecules]
     if len(mols) == 0:
         raise ValueError('Stock samples must have at least one sample '
                          'molecule.')
     if len(
             set([(mol.supplier, mol.molecule_design.molecule_type,
                   self.sample_molecules[idx].concentration)
                  for (idx, mol) in enumerate(mols)])) > 1:
         raise ValueError('All molecule designs in a stock sample must '
                          'have the same supplier, the same molecule type '
                          'and the same concentration.')
     from thelma.entities.moleculedesign import MoleculeDesignPool
     mdp = MoleculeDesignPool.create_from_data(
         dict(molecule_designs=set([mol.molecule_design for mol in mols])))
     # Setting attributes outside __init__ pylint: disable=W0201
     concentration = 0
     for sm in self.sample_molecules:
         concentration += sm.concentration
     concentration = round(concentration, 10)  # one decimal place if in nM
     self.molecule_design_pool = mdp
     self.supplier = mols[0].supplier
     self.molecule_type = mols[0].molecule_design.molecule_type
     self.concentration = concentration
     self.sample_type = SAMPLE_TYPES.STOCK
     self.__class__ = StockSample
Esempio n. 2
0
 def __get_missing_molecule_design_pools(self):
     # Fetches or creates the molecule design pools for the rows in which
     # there are only molecule designs given
     # (invokes :func:`MoleculeDesignPool.create_from_data`).
     self.add_debug('Find pool IDs for molecule design sets ...')
     stock_conc = (get_default_stock_concentration(
                          molecule_type=self.__molecule_type,
                          number_designs=self.__number_molecule_designs)) \
                          / CONCENTRATION_CONVERSION_FACTOR
     for md_ids in self.__pools_to_find:
         mds = set([self.__md_map[md_id] for md_id in md_ids])
         mdp_data = dict(molecule_designs=mds,
                         default_stock_concentration=stock_conc)
         pool = MoleculeDesignPool.create_from_data(mdp_data)
         self.__pools.add(pool)
Esempio n. 3
0
 def __get_missing_molecule_design_pools(self):
     # Fetches or creates the molecule design pools for the rows in which
     # there are only molecule designs given
     # (invokes :func:`MoleculeDesignPool.create_from_data`).
     self.add_debug("Find pool IDs for molecule design sets ...")
     stock_conc = (
         get_default_stock_concentration(
             molecule_type=self.__molecule_type, number_designs=self.__number_molecule_designs
         )
     ) / CONCENTRATION_CONVERSION_FACTOR
     for md_ids in self.__pools_to_find:
         mds = set([self.__md_map[md_id] for md_id in md_ids])
         mdp_data = dict(molecule_designs=mds, default_stock_concentration=stock_conc)
         pool = MoleculeDesignPool.create_from_data(mdp_data)
         self.__pools.add(pool)
Esempio n. 4
0
    def convert_to_stock_sample(self):
        """
        Converts this instance into a stock sample by setting all the
        required attributes. The object class is ''not'' changed.
        """
        mols = [sm.molecule for sm in self.sample_molecules]
        if len(mols) == 0:
            raise ValueError("Stock samples must have at least one sample " "molecule.")
        if (
            len(
                set(
                    [
                        (mol.supplier, mol.molecule_design.molecule_type, self.sample_molecules[idx].concentration)
                        for (idx, mol) in enumerate(mols)
                    ]
                )
            )
            > 1
        ):
            raise ValueError(
                "All molecule designs in a stock sample must "
                "have the same supplier, the same molecule type "
                "and the same concentration."
            )
        from thelma.entities.moleculedesign import MoleculeDesignPool

        mdp = MoleculeDesignPool.create_from_data(dict(molecule_designs=set([mol.molecule_design for mol in mols])))
        # Setting attributes outside __init__ pylint: disable=W0201
        concentration = 0
        for sm in self.sample_molecules:
            concentration += sm.concentration
        concentration = round(concentration, 10)  # one decimal place if in nM
        self.molecule_design_pool = mdp
        self.supplier = mols[0].supplier
        self.molecule_type = mols[0].molecule_design.molecule_type
        self.concentration = concentration
        self.sample_type = SAMPLE_TYPES.STOCK
        self.__class__ = StockSample