Exemple #1
0
def test_load_like(tmp_path):
    gene_file = str(tmp_path / 'genes.txt')

    # make a permutation
    perm = np.random.choice(NGENES, NGENES - 10, replace=False)

    # load data to make reference and permute
    umis, genes = prep.load_txt(TXT)
    umis = umis.A[:, perm]
    genes = genes.loc[perm]

    # write permuted/subsampled reference file
    genes.to_csv(gene_file, header=None, sep='\t', index=None)

    # load like permuted reference
    ll_umi, ll_genes = prep.load_like(TXT, reference=gene_file)
    assert_equal(len(ll_genes), len(perm))
    assert_array_equal(umis, ll_umi.A)

    # repeat with no_split_on_dot
    ll_umi, ll_genes = prep.load_like(TXT,
                                      reference=gene_file,
                                      no_split_on_dot=True)
    assert_equal(len(ll_genes), len(perm))
    assert_array_equal(umis, ll_umi.A)

    # by gene name
    ll_umi, ll_genes = prep.load_like(TXT,
                                      reference=gene_file,
                                      by_gene_name=True)
    assert_equal(len(ll_genes), len(perm))
    assert_array_equal(umis, ll_umi.A)

    # corrupt the permuted reference
    bad_genes = genes.copy()
    bad_genes.loc[5, 0] = 'random'
    bad_genes.to_csv(gene_file, header=None, sep='\t', index=None)
    with pytest.raises(ValueError):
        ll_umi, ll_genes = prep.load_like(TXT, reference=gene_file)
Exemple #2
0
def test_load_txt(ngene_cols):
    coo, genes = prep.load_txt(TXT, ngene_cols)
    assert genes.shape[1] == ngene_cols
    assert coo.shape[1] == NGENES
    assert genes.shape[0] == NGENES
    assert coo.shape[0] == NCELLS + 2 - ngene_cols