Skip to content

Commit

Permalink
Added tests for vdj
Browse files Browse the repository at this point in the history
  • Loading branch information
szabogtamas committed Mar 26, 2020
1 parent e820caf commit 7d5bf0e
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
144 changes: 144 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,150 @@ def adata_tra():
adata = AnnData(obs=obs)
return adata

@pytest.fixture
def adata_vdj():
obs =
{
'LT1_ACGGCCATCCGAGCCA-2-24':
{
'TRA_1_j_gene': 'TRAJ42',
'TRA_1_v_gene': 'TRAV26-2',
'TRB_1_v_gene': 'TRBV7-2',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ2-5',
'sample': 'LT1'
},
'LT1_CGCTTCACAAGGTGTG-2-24':
{
'TRA_1_j_gene': 'TRAJ45',
'TRA_1_v_gene': 'None',
'TRB_1_v_gene': 'None',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ2-3',
'sample': 'LT1'
},
'LT1_AGGGAGTTCCCAAGAT-2-24':
{
'TRA_1_j_gene': 'TRAJ29',
'TRA_1_v_gene': 'TRAV12-1',
'TRB_1_v_gene': 'TRBV20-1',
'TRB_1_d_gene': 'TRBD2',
'TRB_1_j_gene': 'TRBJ1-1',
'sample': 'LT1'
},
'LT1_ATTACTCGTTGGACCC-2-24':
{
'TRA_1_j_gene': 'TRAJ4',
'TRA_1_v_gene': 'TRAV12-1',
'TRB_1_v_gene': 'TRBV7-2',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ2-6',
'sample': 'LT1'
},
'LT1_GCAATCACAATGAATG-1-24':
{
'TRA_1_j_gene': 'TRAJ52',
'TRA_1_v_gene': 'TRAV8-6',
'TRB_1_v_gene': 'TRBV30',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ2-2',
'sample': 'LT1'
},
'LT1_TCTCTAATCCACTGGG-2-24':
{
'TRA_1_j_gene': 'TRAJ43',
'TRA_1_v_gene': 'TRAV8-3',
'TRB_1_v_gene': 'TRBV30',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ1-2',
'sample': 'LT1'
},
'LT1_TATTACCTCAACGGCC-2-24':
{
'TRA_1_j_gene': 'TRAJ45',
'TRA_1_v_gene': 'TRAV20',
'TRB_1_v_gene': 'TRBV4-1',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ1-3',
'sample': 'LT1'
},
'LT1_CGTCAGGTCGAACTGT-1-24':
{
'TRA_1_j_gene': 'TRAJ15',
'TRA_1_v_gene': 'TRAV17',
'TRB_1_v_gene': 'TRBV5-1',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ1-1',
'sample': 'LT1'
},
'LT1_GGGAATGGTTGCGTTA-2-24':
{
'TRA_1_j_gene': 'None',
'TRA_1_v_gene': 'None',
'TRB_1_v_gene': 'TRBV30',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ2-2',
'sample': 'LT1'
},
'LT1_AGCTCCTGTAATCGTC-2-24':
{
'TRA_1_j_gene': 'TRAJ13',
'TRA_1_v_gene': 'TRAV13-1',
'TRB_1_v_gene': 'TRBV18',
'TRB_1_d_gene': 'TRBD2',
'TRB_1_j_gene': 'TRBJ2-2',
'sample': 'LT1'
},
'LT1_CAGCTGGTCCGCGGTA-1-24':
{
'TRA_1_j_gene': 'TRAJ30',
'TRA_1_v_gene': 'TRAV21',
'TRB_1_v_gene': 'TRBV30',
'TRB_1_d_gene': 'TRBD2',
'TRB_1_j_gene': 'TRBJ2-1',
'sample': 'LT1'
},
'LT1_CCTTTCTCAGCAGTTT-1-24':
{
'TRA_1_j_gene': 'TRAJ23',
'TRA_1_v_gene': 'TRAV9-2',
'TRB_1_v_gene': 'TRBV3-1',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ1-2',
'sample': 'LT1'
},
'LT1_GTATCTTGTATATGAG-1-24':
{
'TRA_1_j_gene': 'TRAJ40',
'TRA_1_v_gene': 'TRAV36DV7',
'TRB_1_v_gene': 'TRBV6-3',
'TRB_1_d_gene': 'TRBD1',
'TRB_1_j_gene': 'TRBJ2-5',
'sample': 'LT1'
},
'LT1_TGCGCAGAGGGCATGT-1-24':
{
'TRA_1_j_gene': 'TRAJ39',
'TRA_1_v_gene': 'TRAV12-3',
'TRB_1_v_gene': 'TRBV11-2',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ2-7',
'sample': 'LT1'
},
'LT1_CAGCAGCAGCGCTCCA-2-24':
{
'TRA_1_j_gene': 'TRAJ32',
'TRA_1_v_gene': 'TRAV38-2DV8',
'TRB_1_v_gene': 'None',
'TRB_1_d_gene': 'None',
'TRB_1_j_gene': 'TRBJ2-3',
'sample': 'LT1'
}
}
obs = pd.DataFrame.from_dict(obs, orient="index")
adata = AnnData(obs=obs)
return adata


@pytest.fixture
def adata_clonotype():
Expand Down
5 changes: 5 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ def test_group_abundance(adata_clonotype):
def test_spectratype(adata_tra):
p = pl.spectratype(adata_tra, target_col="sample")
assert isinstance(p, plt.Axes)


def test_vdj_usage(adata_tra):
p = pl.vdj_usage(adata_tra, cell_weights="sample")
assert isinstance(p, plt.Axes)
30 changes: 30 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,33 @@ def test_spectratype(adata_tra):
orient="index",
)
npt.assert_equal(res.values, expected_frac.values)


def test_vdj_usage(adata_vdj):
# Check return formats
df = st.tl.vdj_usage(adata_vdj, cell_weights="sample", as_dict=False)
assert isinstance(df, AnnData)
df = st.tl.vdj_usage(adata_vdj, cell_weights="sample", as_dict=True)
assert isinstance(df, dict)

# Check normalization
size_column = "cell_weights"
expected_weights = [
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667,
0.06666666666666667
]
df = st.tl.vdj_usage(adata_vdj, cell_weights="sample", as_dict=False)
npt.assert_equal(df[size_column].tolist(), expected_weights)

0 comments on commit 7d5bf0e

Please sign in to comment.