def __getitem__(self, i): """ Gets alignment pair. Parameters ---------- i : int Index of item Returns ------- gene : torch.Tensor Encoded representation of protein of interest pos : torch.Tensor Encoded representation of protein that aligns with `gene`. states : torch.Tensor Alignment string alignment_matrix : torch.Tensor Ground truth alignment matrix path_matrix : torch.Tensor Pairwise path distances, where the smallest distance to the path is computed for every element in the matrix. """ gene = self.pairs.iloc[i]['chain1'] pos = self.pairs.iloc[i]['chain2'] st = self.pairs.iloc[i]['alignment'] states = list(map(tmstate_f, st)) if self.clip_ends: gene, pos, states, st = clip_boundaries(gene, pos, states, st) if self.pad_ends: states = [m] + states + [m] states = torch.Tensor(states).long() gene = self.tokenizer(str.encode(gene)) pos = self.tokenizer(str.encode(pos)) gene = torch.Tensor(gene).long() pos = torch.Tensor(pos).long() alignment_matrix = torch.from_numpy(states2matrix(states)) path_matrix = torch.empty(*alignment_matrix.shape) g_mask = torch.ones(*alignment_matrix.shape) if self.construct_paths: pi = states2edges(states) path_matrix = torch.from_numpy(path_distance_matrix(pi)) path_matrix = reshape(path_matrix, len(gene), len(pos)) if self.mask_gaps: g_mask = torch.from_numpy(gap_mask(st)).bool() alignment_matrix = reshape(alignment_matrix, len(gene), len(pos)) g_mask = reshape(g_mask, len(gene), len(pos)) if not self.return_names: return gene, pos, states, alignment_matrix, path_matrix, g_mask else: gene_name = self.pairs.iloc[i]['chain1_name'] pos_name = self.pairs.iloc[i]['chain2_name'] return (gene, pos, states, alignment_matrix, path_matrix, g_mask, gene_name, pos_name)
def test_clip_ends_2(self): gen = 'YACNHCGATAIRNPNWKNHQREH' oth = 'FHCKSQRVMSDCGSNGSKPFVTNYYVRHQCRKH' st = np.array([ 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 ]) a = ''.join(list(map(revstate_f, list(st)))) rx, ry, rs, _ = clip_boundaries(gen, oth, st, a) self.assertTrue(1) # just make sure it runs
def test_clip_ends_none(self): from deepblast.constants import m s_ = [m, m, m, m] x_ = 'GSSG' y_ = 'GEIR' a_ = '::::' rx, ry, rs, _ = clip_boundaries(x_, y_, s_, a_) self.assertEqual(x_, rx) self.assertEqual(y_, ry) self.assertEqual(s_, rs)
def test_clip_ends(self): from deepblast.constants import x, m, y s = [x, m, m, m, y] x = 'GSSG' y = 'GEIR' a = '1:::2' rx, ry, rs, _ = clip_boundaries(x, y, s, a) ex, ey, es = 'SSG', 'GEI', [m, m, m] self.assertEqual(ex, rx) self.assertEqual(ey, ry) self.assertEqual(es, rs)