def qualNorm_filter_genes(data, qualitative, pval_threshold=<NUM_LIT>, smoothing=<NUM_LIT>, eps=<NUM_LIT>):
genes, cells = data.shape<EOL>clusters = qualitative.shape[<NUM_LIT:1>]<EOL>output = np.zeros((genes, clusters))<EOL>missing_indices = []<EOL>genes_included = []<EOL>qual_indices = []<EOL>thresholds = qualitative.min(<NUM_LIT:1>) + (qualitative.max(<NUM_LIT:1>) - qualitative.min(<NUM_LIT:1>))/<NUM_LIT><EOL>pvals = np.zeros(genes)<EOL>for i in range(genes):<EOL><INDENT>if qualitative[i,:].max() == -<NUM_LIT:1> and qualitative[i,:].min() == -<NUM_LIT:1>:<EOL><INDENT>missing_indices.append(i)<EOL>continue<EOL><DEDENT>qual_indices.append(i)<EOL>threshold = thresholds[i]<EOL>data_i = data[i,:]<EOL>if sparse.issparse(data):<EOL><INDENT>data_i = data_i.toarray().flatten()<EOL><DEDENT>assignments, means = poisson_cluster(data_i.reshape((<NUM_LIT:1>, cells)), <NUM_LIT:2>)<EOL>means = means.flatten()<EOL>high_i = <NUM_LIT:1><EOL>low_i = <NUM_LIT:0><EOL>if means[<NUM_LIT:0>]>means[<NUM_LIT:1>]:<EOL><INDENT>high_i = <NUM_LIT:0><EOL>low_i = <NUM_LIT:1><EOL><DEDENT>p_val = poisson_test(data_i[assignments==low_i], data_i[assignments==high_i], smoothing=smoothing)<EOL>pvals[i] = p_val<EOL>if p_val <= pval_threshold:<EOL><INDENT>genes_included.append(i)<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>high_mean = np.median(data_i[assignments==high_i])<EOL>low_mean = np.median(data_i[assignments==low_i]) + eps<EOL>for k in range(clusters):<EOL><INDENT>if qualitative[i,k]>threshold:<EOL><INDENT>output[i,k] = high_mean<EOL><DEDENT>else:<EOL><INDENT>output[i,k] = low_mean<EOL><DEDENT><DEDENT><DEDENT>output = output[genes_included,:]<EOL>pvals = pvals[genes_included]<EOL>return output, pvals, genes_included<EOL>
Does qualNorm but returns a filtered gene set, based on a p-value threshold.