def diffexp_topN(self, obsFilterA, obsFilterB, top_n=None): """ Computes the top N differentially expressed variables between two observation sets. If mode is "TOP_N", then stats for the top N dataframes contain a subset of variables, then statistics for all variables will be returned, otherwise only the top N vars will be returned. :param obsFilterA: filter: dictionary with filter params for first set of observations :param obsFilterB: filter: dictionary with filter params for second set of observations :param top_n: Limit results to top N (Top var mode only) :return: top N genes and corresponding stats """ if Axis.VAR in obsFilterA or Axis.VAR in obsFilterB: raise FilterError("Observation filters may not contain variable conditions") try: shape = self.get_shape() obs_mask_A = self._axis_filter_to_mask(Axis.OBS, obsFilterA["obs"], shape[0]) obs_mask_B = self._axis_filter_to_mask(Axis.OBS, obsFilterB["obs"], shape[0]) except (KeyError, IndexError): raise FilterError("Error parsing filter") if top_n is None: top_n = self.dataset_config.diffexp__top_n if self.server_config.exceeds_limit( "diffexp_cellcount_max", np.count_nonzero(obs_mask_A) + np.count_nonzero(obs_mask_B) ): raise ExceedsLimitError("Diffexp request exceeds max cell count limit") result = self.compute_diffexp_ttest(obs_mask_A, obs_mask_B, top_n, self.dataset_config.diffexp__lfc_cutoff) try: return jsonify_numpy(result) except ValueError: raise JSONEncodingValueError("Error encoding differential expression to JSON")
def data_frame_to_fbs_matrix(self, filter, axis): """ Retrieves data 'X' and returns in a flatbuffer Matrix. :param filter: filter: dictionary with filter params :param axis: string obs or var :return: flatbuffer Matrix Caveats: * currently only supports access on VAR axis * currently only supports filtering on VAR axis """ if axis != Axis.VAR: raise ValueError("Only VAR dimension access is supported") try: obs_selector, var_selector = self._filter_to_mask(filter) except (KeyError, IndexError, TypeError, AttributeError): raise FilterError("Error parsing filter") if obs_selector is not None: raise FilterError("filtering on obs unsupported") num_columns = self.get_shape()[1] if var_selector is None else np.count_nonzero(var_selector) if self.server_config.exceeds_limit("column_request_max", num_columns): raise ExceedsLimitError("Requested dataframe columns exceed column request limit") X = self.get_X_array(obs_selector, var_selector) col_idx = np.nonzero([] if var_selector is None else var_selector)[0] return encode_matrix_fbs(X, col_idx=col_idx, row_idx=None)