def test_repertoire_full_use_case(self): """ This is not a unit test persay! This is a test of a use_case of an instance of the TCRrep() class used for pairwise sequence comparison """ testrep = TCRrep(cell_df = example_df, chains = ["alpha", "beta"]) # (1) testrep.index_cols.append("epitope") # (2) testrep.index_cols.append("subject") testrep.deduplicate() # (3) testrep.cdr3_a_aa_smat = 'blosum62' # (4) testrep.cdr3_b_aa_smat = 'blosum62' testrep.compute_pairwise(chain = "alpha") # (5) testrep.compute_pairwise(chain = "beta") # (6) tcrdist = testrep.cdr3_a_aa_pw + testrep.cdr3_b_aa_pw # (7) expected_tcrdist = np.array([[ 0., 222., 210., 223., 231., 239., 219., 231., 175.], [ 222., 0., 116., 175., 173., 185., 131., 209., 205.], [ 210., 116., 0., 175., 169., 183., 145., 201., 221.], [ 223., 175., 175., 0., 154., 200., 162., 234., 202.], [ 231., 173., 169., 154., 0., 152., 120., 182., 192.], [ 239., 185., 183., 200., 152., 0., 146., 112., 192.], [ 219., 131., 145., 162., 120., 146., 0., 178., 172.], [ 231., 209., 201., 234., 182., 112., 178., 0., 220.], [ 175., 205., 221., 202., 192., 192., 172., 220., 0.]]) self.assertTrue((tcrdist == expected_tcrdist).all())
def test_repertoire_full_use_case_hamming(self): """ This is not a unit test persay! This is a test of a use_case of an instance of the TCRrep() class used for pairwise sequence comparison """ testrep = TCRrep(cell_df=example_df, chains=["alpha", "beta"]) # (1) testrep.index_cols.append("epitope") # (2) testrep.index_cols.append("subject") testrep.deduplicate() # (3) testrep.cdr3_a_aa_smat = 'blosum62' # (4) testrep.cdr3_b_aa_smat = 'blosum62' testrep.compute_pairwise_all(chain="alpha", metric="hamming") # (5) testrep.compute_pairwise_all(chain="beta", metric="hamming") # (6) tcrdist = testrep.cdr3_a_aa_pw + testrep.cdr3_b_aa_pw # (7) expected_tcrdist = np.array( [[0., 18., 17., 18., 19., 22., 19., 18., 16.], [18., 0., 11., 15., 15., 17., 10., 18., 18.], [17., 11., 0., 18., 15., 17., 13., 18., 20.], [18., 15., 18., 0., 14., 19., 14., 20., 18.], [19., 15., 15., 14., 0., 14., 11., 17., 16.], [22., 17., 17., 19., 14., 0., 14., 13., 18.], [19., 10., 13., 14., 11., 14., 0., 17., 15.], [18., 18., 18., 20., 17., 13., 17., 0., 19.], [16., 18., 20., 18., 16., 18., 15., 19., 0.]]) self.assertTrue((tcrdist == expected_tcrdist).all())
def test_save_as_hdf5(self): testrep = TCRrep(cell_df=example_df, chains=["alpha", "beta"]) # (1) testrep.index_cols.append("epitope") # (2) testrep.index_cols.append("subject") testrep.deduplicate() # (3) testrep.cdr3_a_aa_smat = 'blosum62' # (4) testrep.cdr3_b_aa_smat = 'blosum62' testrep.compute_pairwise(chain="alpha") # (5) testrep.compute_pairwise(chain="beta") # (6) tcrdist = testrep.cdr3_a_aa_pw + testrep.cdr3_b_aa_pw # (7) tmpf = tempfile.NamedTemporaryFile(mode='w+b', suffix='.h5', prefix='tcrrep_test', delete=False) tmpf.close() testrep.save_as_hdf5(tmpf.name) self.assertTrue(os.path.exists(tmpf.name)) incoming = load_hdf5(tmpf.name) os.unlink(tmpf.name) incoming_tcrdist = incoming.cdr3_a_aa_pw + incoming.cdr3_b_aa_pw self.assertTrue((tcrdist == incoming_tcrdist).all()) self.assertTrue(testrep.chains == incoming.chains)