def _get_activations_for_batch(self, list_of_seqs, custom_tensor_to_retrieve=None): """Gets activations for each sequence in list_of_seqs. [ [activation_1, activation_2, ...] # For list_of_seqs[0] [activation_1, activation_2, ...] # For list_of_seqs[1] ... ] In the case that the activations are the normalized probabilities that a sequence belongs to a class, entry `i, j` of `inferrer.get_activations(batch)` contains the probability that sequence `i` is in family `j`. Args: list_of_seqs: list of strings, with characters that are amino acids. custom_tensor_to_retrieve: string name for a tensor to retrieve, if unset uses default for signature. Returns: np.array of floats containing the value from fetch_op. """ one_hots = [utils.residues_to_one_hot(seq) for seq in list_of_seqs] padded_one_hots = utils.make_padded_np_array(one_hots) tensor_name = custom_tensor_to_retrieve or self._fetch_tensor_name with self._graph.as_default(): return self._sess.run( tensor_name, { self._signature.inputs[protein_dataset.SEQUENCE_KEY].name: padded_one_hots, self._signature.inputs[protein_dataset.SEQUENCE_LENGTH_KEY].name: np.array([len(s) for s in list_of_seqs]) })
def testSparseToOneHot(self): seq = 'AY' expected_output = [[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0. ], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1. ]] self.assertListEqual(expected_output, utils.residues_to_one_hot(seq).tolist())