def qualNorm(data, qualitative):
genes, cells = data.shape<EOL>clusters = qualitative.shape[<NUM_LIT:1>]<EOL>output = np.zeros((genes, clusters))<EOL>missing_indices = []<EOL>qual_indices = []<EOL>thresholds = qualitative.min(<NUM_LIT:1>) + (qualitative.max(<NUM_LIT:1>) - qualitative.min(<NUM_LIT:1>))/<NUM_LIT><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>high_mean = np.median(data_i[assignments==high_i])<EOL>low_mean = np.median(data_i[assignments==low_i])<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>if missing_indices:<EOL><INDENT>assignments, means = poisson_cluster(data[qual_indices, :], clusters, output[qual_indices, :], max_iters=<NUM_LIT:1>)<EOL>for ind in missing_indices:<EOL><INDENT>for k in range(clusters):<EOL><INDENT>if len(assignments==k)==<NUM_LIT:0>:<EOL><INDENT>output[ind, k] = data[ind,:].mean()<EOL><DEDENT>else:<EOL><INDENT>output[ind, k] = data[ind, assignments==k].mean()<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return output<EOL>
Generates starting points using binarized data. If qualitative data is missing for a given gene, all of its entries should be -1 in the qualitative matrix.

Args:
    data (array): 2d array of genes x cells
    qualitative (array): 2d array of numerical data - genes x clusters

Returns:
    Array of starting positions for state estimation or
    clustering, with shape genes x clusters