def __get_single_pools(self): """ Determines the single pool (ID) or each requested molecule design. """ self.add_debug('Get single molecule design pool ...') md_str = create_in_term_for_db_queries(self.__md_map.keys()) query_statement = SINGLE_POOL_QUERY.QUERY_TEMPLATE % (md_str) results = self.__session.query(*SINGLE_POOL_QUERY.QUERY_RESULTS).\ from_statement(query_statement).all() for record in results: md_id = record[SINGLE_POOL_QUERY.MOLECULE_DESIGN_INDEX] pool_id = record[SINGLE_POOL_QUERY.POOL_INDEX] self.__single_pool_map[pool_id] = md_id if not len(self.__single_pool_map) == len(self.__md_map): missing_ids = [] for md_id in self.__md_map.keys(): if not self.__single_pool_map.has_key(md_id): missing_ids.append(md_id) msg = 'Could not find single molecule design pool for the ' \ 'following molecule designs: %s.' % (', '.join( [str(md_id) for md_id in sorted(missing_ids)])) self.add_error(msg)
def __run_optimizer(self): """ Runs the optimizing query and allocates the results to the library candidates. """ self.add_debug('Run optimizer ...') sample_str = create_in_term_for_db_queries(self.__stock_samples) query_statement = LIBRARY_OPTIMIZATION_QUERY.QUERY_TEMPLATE % ( sample_str, sample_str) results = self.__session.query( *LIBRARY_OPTIMIZATION_QUERY.QUERY_RESULT_VALUES).\ from_statement(query_statement).all() for record in results: iso_candidate = IsoCandidate.create_from_query_result(record) if iso_candidate.rack_barcode in self.excluded_racks: continue self.__store_candidate_data(iso_candidate) if len(self.__picked_candidates) < 1: msg = 'Did not find any library candidate!' self.add_error(msg)
def __get_stock_samples(self): """ Determines suitable stock samples for the molecule designs required to create the pools. Suitable tubes must be managed, have a stock concentration and a certain minimum volume. """ self.add_debug('Get stock samples ...') conc = self.stock_concentration / CONCENTRATION_CONVERSION_FACTOR volume = (self.take_out_volume + STOCK_DEAD_VOLUME) \ / VOLUME_CONVERSION_FACTOR pool_str = create_in_term_for_db_queries(self.__single_pool_map.keys()) query_statement = STOCK_SAMPLE_QUERY.QUERY_TEMPLATE % ( pool_str, conc, volume, STOCK_ITEM_STATUS) results = self.__session.query(*STOCK_SAMPLE_QUERY.QUERY_RESULTS).\ from_statement(query_statement).all() found_pools = set() for record in results: stock_sample_id = record[STOCK_SAMPLE_QUERY.STOCK_SAMPLE_INDEX] self.__stock_samples.append(stock_sample_id) pool_id = record[STOCK_SAMPLE_QUERY.POOL_INDEX] found_pools.add(pool_id) if len(found_pools) < 1: msg = 'Did not find any suitable stock sample!' self.add_error(msg) elif not len(found_pools) == len(self.__single_pool_map): missing_pools = [] for pool_id, md_id in self.__single_pool_map.iteritems(): if not pool_id in found_pools: missing_pools.append('%s (md: %s)' % (pool_id, md_id)) msg = 'Could not find suitable source stock tubes for the ' \ 'following molecule design pools: %s.' \ % (', '.join(sorted(missing_pools))) self.add_warning(msg)
def _get_params_for_sql_statement(self): return create_in_term_for_db_queries(self.molecule_design_ids)
def _get_params_for_sql_statement(self): rack_term = create_in_term_for_db_queries(self.rack_map.keys(), as_string=True) return (rack_term)
def _get_params_for_sql_statement(self): sample_str = create_in_term_for_db_queries(self.sample_ids) return (sample_str, sample_str)
def _get_pool_id_term(self): return create_in_term_for_db_queries(self.pool_ids)
def _get_params_for_sql_statement(self): return create_in_term_for_db_queries(self.tube_barcodes, as_string=True)
def _get_params_for_sql_statement(self): pool_str = create_in_term_for_db_queries(self.pool_ids) conc = self.concentration / CONCENTRATION_CONVERSION_FACTOR vol = (self.minimum_volume + STOCK_DEAD_VOLUME) \ / VOLUME_CONVERSION_FACTOR return (pool_str, conc, vol, STOCK_ITEM_STATUS)
def get_stock_tube_specs_db_term(): """ Returns a term that can be inserted into IN-clauses of DB queries (containing all valid specs for stock tubes). """ return create_in_term_for_db_queries(STOCK_TUBE_SPECS, as_string=True)
def _get_params_for_sql_statement(self): return create_in_term_for_db_queries(self.rack_barcodes, as_string=True)